Hello.  I am new to Restlet client programming.  I am attempting to use Restlet 
client 2.1.6 on Android.

I have read the documentation on SSL config by way of DefaultSslContextFactory, 
as well as having read StackOverflow articles on configuring an 
HttpsClientHelper.  I chose the latter route, as I could convince myself that 
the client helper approach installed the helper for all subsequent use of 
ClientResource.  However, I cannot get this approach to work.  I receive this 
error message in an exception from the Restlet client when I attempt to connect 
to the remote server:

Internal connector error 1002

No available client connector supports the required protocol: 2131034127. 
Please add the JAR of a matching connector to your classpath.

Here is my approach in detail:

1) Perform this once before any network calls are made:

        List<ConnectorHelper<Client>> registeredClients = 
Engine.getInstance().getRegisteredClients();
        registeredClients.add(0, new SslHelper(this));

where SslHelper is a subclass of HttpsClientHelper and is defined by 

package com.homosuperiorus.clips.clients;

import android.content.Context;
import android.util.Log;

import com.homosuperiorus.clips.R;

import org.restlet.ext.ssl.HttpsClientHelper;

import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;

public class SslHelper extends HttpsClientHelper {
    private final String TAG = "SslHelper";
    private KeyStore trustStore;

    public SslHelper(Context appContext) {
        super(null);
        InputStream inputStream = 
appContext.getResources().openRawResource(R.raw.keystore);
        try {
            trustStore = KeyStore.getInstance("BKS");
            trustStore.load(inputStream, "changeit".toCharArray());
        } catch (Exception e) {
            Log.d(TAG, "Keystore error", e);
            throw new RuntimeException(e);
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                Log.d(TAG, "error closing keystore inputStream", e);
            }
        }
    }

    @Override
    protected SSLContext getSslContext() {
        try {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
            tmf.init(trustStore);
            sslContext.init(new KeyManager[0], tmf.getTrustManagers(), null);
            setSslContext(sslContext);
            return sslContext;
        } catch (NoSuchAlgorithmException shouldNeverHappen) {
            throw new RuntimeException(shouldNeverHappen);
        } catch (KeyStoreException shouldNeverHappen) {
            throw new RuntimeException(shouldNeverHappen);
        } catch (KeyManagementException shouldNeverHappen) {
            throw new RuntimeException(shouldNeverHappen);
        }
    }
}

The BKS keystore loads successfully.

Next, I setup and make the client call:

    public MyStuff getMyStuff() {
        ClientResource resource = new ClientResource(BASEURL);
        resource.setChallengeResponse(ChallengeScheme.HTTP_BASIC, 
credentials.userName, credentials.password);
        resource.accept(MediaType.APPLICATION_JSON);
        MyStuff myStuff;
        try {
            myStuff = resource.getChild(PATH).get(MyStuff.class);
            Log.d(TAG, myStuff.toString());
            return myStuff;
        } catch (ResourceException e) {
            String reasonPhrase = e.getStatus().getReasonPhrase();
            Log.d(TAG, String.format("Login with GET /mystuff failed:  
status=%d, reason phrase=%s", e.getStatus().getCode(), reasonPhrase));
            return null;
        }
    }

The client throws a ResourceException, with the detail I provided above.

My dependencies on restlet are as follows:

dependencies {
    compile 'com.google.android:support-v4:r7'
    compile 'com.google.code.gson:gson:2.2.4'
    compile group: "org.restlet.android", name: "org.restlet", version: 
versions.restlet
    compile group: "org.restlet.android", name: "org.restlet.ext.json", 
version: versions.restlet
    compile group: "org.restlet.android", name: "org.restlet.ext.ssl", version: 
versions.restlet
}

I feel like this code is one line from working, but I cannot tell which line.  
It sounds like I need another restlet jar on the classpath, but I cannot take a 
good guess at which one I'm missing.

Your help is much appreciated.

Thank you.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3071486

Reply via email to