0

I've been trying how to solve my problem for days but I didn't succeded.

I'm just tyring to perform RESTlet HTTPS request. The code is quiet simple as I've only one acrivity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    System.setProperty("java.net.preferIPv6Addresses", "false");

    Engine.getInstance().getRegisteredClients().clear();
    Engine.getInstance().getRegisteredClients().add(new HttpsClientHelper(null));

    System.out.println("VERIFICO IL TOKEN: ");
    ClientResource clientResource = new ClientResource(
            "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=lalala");

    Representation rep = clientResource.get();
}

The reason given by restlet is:

Caused by: Communication Error (1001) - Error while processing a connection

Caused By:

Caused by: java.lang.NullPointerException
at org.apache.harmony.xnet.provider.jsse.ClientSessionContext$HostAndPort.hashCode(ClientSessionContext.java:214)
at java.util.HashMap.put(HashMap.java:393)

I read somewere in the web it's an android bug but I couldn't find any workaround for that

Any idea? I'm using Restlet 2.1 RC5

The complete stacktrace is:

08-19 13:43:23.911: E/AndroidRuntime(30053): FATAL EXCEPTION: main
08-19 13:43:23.911: E/AndroidRuntime(30053): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.MainActivity}: Communication Error (1001) - Error while processing a connection
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.app.ActivityThread.access$2300(ActivityThread.java:135)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.os.Looper.loop(Looper.java:144)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.app.ActivityThread.main(ActivityThread.java:4937)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.lang.reflect.Method.invokeNative(Native Method)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.lang.reflect.Method.invoke(Method.java:521)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at dalvik.system.NativeStart.main(Native Method)
08-19 13:43:23.911: E/AndroidRuntime(30053): Caused by: Communication Error (1001) - Error while processing a connection
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.resource.ClientResource.doError(ClientResource.java:611)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.resource.ClientResource.handleInbound(ClientResource.java:1201)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.resource.ClientResource.handle(ClientResource.java:1068)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.resource.ClientResource.handle(ClientResource.java:1043)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.resource.ClientResource.handle(ClientResource.java:949)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.resource.ClientResource.get(ClientResource.java:657)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at com.example.helloandroid.MainActivity.onCreate(MainActivity.java:30)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
08-19 13:43:23.911: E/AndroidRuntime(30053):    ... 11 more
08-19 13:43:23.911: E/AndroidRuntime(30053): Caused by: java.lang.NullPointerException
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.apache.harmony.xnet.provider.jsse.ClientSessionContext$HostAndPort.hashCode(ClientSessionContext.java:214)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.util.HashMap.put(HashMap.java:393)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.apache.harmony.xnet.provider.jsse.ClientSessionContext.putSession(ClientSessionContext.java:190)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.apache.harmony.xnet.provider.jsse.ClientHandshakeImpl.unwrap(ClientHandshakeImpl.java:308)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.apache.harmony.xnet.provider.jsse.SSLRecordProtocol.unwrap(SSLRecordProtocol.java:413)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.apache.harmony.xnet.provider.jsse.SSLEngineImpl.unwrap(SSLEngineImpl.java:478)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:383)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.ext.ssl.internal.ReadableSslChannel.onDrain(ReadableSslChannel.java:114)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.io.Buffer.process(Buffer.java:553)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.io.Buffer.process(Buffer.java:668)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.io.ReadableBufferedChannel.read(ReadableBufferedChannel.java:172)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.io.Buffer.fill(Buffer.java:391)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.connector.InboundWay.onFill(InboundWay.java:278)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.io.Buffer.process(Buffer.java:597)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.io.Buffer.process(Buffer.java:668)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.connector.Way.processIoBuffer(Way.java:477)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.connector.InboundWay.processIoBuffer(InboundWay.java:353)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.connector.Way.onSelected(Way.java:430)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.connector.ConnectionController.controlConnections(ConnectionController.java:105)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.connector.ConnectionController.doRun(ConnectionController.java:156)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at org.restlet.engine.connector.Controller.run(Controller.java:158)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-19 13:43:23.911: E/AndroidRuntime(30053):    at java.lang.Thread.run(Thread.java:1102)
neb
  • 1
  • 1
  • 4
  • are you using android < 2.2? http://code.google.com/p/android/issues/detail?id=4914 seems to be your bug and says it's fixed in 2.2. Workaround for older androids here: http://code.google.com/p/android/issues/attachmentText?id=4914&aid=3990080216532268321&name=SslPeerUpdater.java&token=tSBsRZTT7llRFWRQSAF-skh8upg%3A1345391602829 – zapl Aug 19 '12 at 15:53
  • I read about it but I'm using Android 2.2. I get the same error in both emulator and my htc device – neb Aug 20 '12 at 10:29

1 Answers1

1

It seems that you are using the internal Restlet connector despite your call to:

Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpsClientHelper(null));

You should ensure try this instead:

Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new org.restlet.ext.net.HttpClientHelper(null));
Jerome Louvel
  • 2,882
  • 18
  • 19
  • Note that the internal HTTP connector of Restlet isn't fully stable in 2.1 RC5. We fixed several bugs for the upcoming 2.1 RC6 but only 2.1.0 should fix the remaining bugs, especially for HTTPS communication. – Jerome Louvel Aug 20 '12 at 21:33