Reputation: 1
I'm trying to perform a get request with servlet but I get Communication Error (1001) - Error while processing a connection.
My code is quite simple:
Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpsClientHelper(null));
ClientResource cr = new ClientResource(URI);
cr.setRequestEntityBuffering(true);
cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC,
SensorUpdaterApp.getInstance().GOOGLE_ACCOUNT_EMAIL,
SensorUpdaterApp.getInstance().GOOGLE_ACCOUNT_TOKEN);
DataTableResource resource = cr.wrap(DataTableResource.class);
Long newId = null;
try{
newId = resource.createDataset();
} catch(Exception e){ e.printStackTrace(); }
Here is the stacktrace I get in my logcat:
08-16 13:21:24.221: I/org.restlet(11223): Starting the internal [HTTPS/1.1] client
08-16 13:21:24.311: D/dalvikvm(11223): GC_FOR_MALLOC freed 9361 objects / 434480 bytes in 59ms
08-16 13:21:24.391: D/dalvikvm(11223): GC_FOR_MALLOC freed 444 objects / 16384 bytes in 54ms
08-16 13:21:24.471: D/dalvikvm(11223): GC_FOR_MALLOC freed 505 objects / 18800 bytes in 53ms
08-16 13:21:24.561: D/dalvikvm(11223): GC_FOR_MALLOC freed 703 objects / 26368 bytes in 41ms
08-16 13:21:24.631: D/dalvikvm(11223): GC_FOR_MALLOC freed 870 objects / 32216 bytes in 41ms
08-16 13:21:24.911: D/dalvikvm(11223): GC_FOR_MALLOC freed 15029 objects / 968672 bytes in 46ms
08-16 13:21:25.241: I/org.restlet(11223): A recoverable error was detected (1001), attempting again in 2000 ms.
08-16 13:21:25.731: D/dalvikvm(11223): GC_FOR_MALLOC freed 24605 objects / 1514848 bytes in 60ms
08-16 13:21:27.531: I/org.restlet(11223): A recoverable error was detected (1001), attempting again in 2000 ms.
08-16 13:21:28.491: D/dalvikvm(11223): GC_FOR_MALLOC freed 33569 objects / 1502352 bytes in 78ms
08-16 13:21:29.821: W/System.err(11223): Communication Error (1001) - Error while processing a connection
08-16 13:21:29.821: W/System.err(11223): at org.restlet.resource.ClientResource.doError(ClientResource.java:611)
08-16 13:21:29.821: W/System.err(11223): at org.restlet.engine.resource.ClientInvocationHandler.invoke(ClientInvocationHandler.java:236)
08-16 13:21:29.821: W/System.err(11223): at $Proxy5.createDataset(Native Method)
08-16 13:21:29.821: W/System.err(11223): at com.sensorupdater2.activities.main.CreateNewDatasetAsyncTask.doInBackground(CreateNewDatasetAsyncTask.java:38)
08-16 13:21:29.821: W/System.err(11223): at com.sensorupdater2.activities.main.CreateNewDatasetAsyncTask.doInBackground(CreateNewDatasetAsyncTask.java:1)
08-16 13:21:29.821: W/System.err(11223): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-16 13:21:29.821: W/System.err(11223): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-16 13:21:29.831: W/System.err(11223): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-16 13:21:29.831: W/System.err(11223): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-16 13:21:29.831: W/System.err(11223): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-16 13:21:29.831: W/System.err(11223): at java.lang.Thread.run(Thread.java:1102)
08-16 13:21:29.831: W/System.err(11223): Caused by: java.lang.NullPointerException
08-16 13:21:29.831: W/System.err(11223): at org.apache.harmony.xnet.provider.jsse.ClientSessionContext$HostAndPort.hashCode(ClientSessionContext.java:214)
08-16 13:21:29.841: W/System.err(11223): at java.util.HashMap.put(HashMap.java:393)
08-16 13:21:29.841: W/System.err(11223): at org.apache.harmony.xnet.provider.jsse.ClientSessionContext.putSession(ClientSessionContext.java:190)
08-16 13:21:29.841: W/System.err(11223): at org.apache.harmony.xnet.provider.jsse.ClientHandshakeImpl.unwrap(ClientHandshakeImpl.java:308)
08-16 13:21:29.841: W/System.err(11223): at org.apache.harmony.xnet.provider.jsse.SSLRecordProtocol.unwrap(SSLRecordProtocol.java:413)
08-16 13:21:29.841: W/System.err(11223): at org.apache.harmony.xnet.provider.jsse.SSLEngineImpl.unwrap(SSLEngineImpl.java:478)
08-16 13:21:29.841: W/System.err(11223): at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:383)
08-16 13:21:29.841: W/System.err(11223): at org.restlet.ext.ssl.internal.ReadableSslChannel.onDrain(ReadableSslChannel.java:114)
08-16 13:21:29.841: W/System.err(11223): at org.restlet.engine.io.Buffer.process(Buffer.java:553)
08-16 13:21:29.841: W/System.err(11223): at org.restlet.engine.io.Buffer.process(Buffer.java:668)
08-16 13:21:29.841: W/System.err(11223): at org.restlet.engine.io.ReadableBufferedChannel.read(ReadableBufferedChannel.java:172)
08-16 13:21:29.841: W/System.err(11223): at org.restlet.engine.io.Buffer.fill(Buffer.java:391)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.connector.InboundWay.onFill(InboundWay.java:278)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.io.Buffer.process(Buffer.java:597)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.io.Buffer.process(Buffer.java:668)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.connector.Way.processIoBuffer(Way.java:477)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.connector.InboundWay.processIoBuffer(InboundWay.java:353)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.connector.Way.onSelected(Way.java:430)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.connector.ConnectionController.controlConnections(ConnectionController.java:105)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.connector.ConnectionController.doRun(ConnectionController.java:156)
08-16 13:21:29.851: W/System.err(11223): at org.restlet.engine.connector.Controller.run(Controller.java:158)
08-16 13:21:29.851: W/System.err(11223): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
08-16 13:21:29.851: W/System.err(11223): ... 5 more
08-16 13:21:31.181: D/dalvikvm(11223): GC_FOR_MALLOC freed 31659 objects / 1496144 bytes in 101ms
08-16 13:21:31.181: I/org.restlet(11223): Stopping the internal[HTTPS/1.1] client
In my libs directory I have:
I tested the server with some other client and it seems to work
Any ideas?
Upvotes: 0
Views: 5194
Reputation: 25673
I found that importing just the org.restlet.ext.net.HttpClientHelper
made both HTTPS and HTTP work, so you might want to try that (but be careful - this behaviour changes depending which exact HttpClientHelper
you import).
If you deliberately want to use org.restlet.ext.ssl.HttpsClientHelper
then you will need to also import the org.jsslutils_1.0 library. If you don't then the connection just times out forever (at least that's what I saw when testing with the Restlet 2.1.0 on Android).
The readme.txt in the Restlet 2.1.0 download shows the dependencies for each of the JARs. org.restlet.ext.ssl depends on jsslutils:
org.restlet.ext.ssl (Restlet Extension - SSL)
- org.jsslutils_1.0
FYI, the Restlet download also includes all of the dependent libraries, so you can get them from there.
Here are some other miscellaneous things I found while testing this:
Make sure you import and use the correct connector (when I imported the `HttpClientHelper Eclipse offered me 4 different ones). The Restlet wiki Connectors page lists the server and client connectors available:
http://wiki.restlet.org/docs_1.1/13-restlet/27-restlet/37-restlet.html
When I tried the org.restlet.ext.httpclient.HttpClientHelper
I don't think I needed to import all its dependencies for my HTTP connector to work (possibly because I am only using the client side parts).
Make sure all your JARs are from the same Restlet release, otherwise you could end up with weird errors.
If you only import the org.restlet.ext.httpclient.HttpClientHelper
connector and not an HTTPS one you will see a java.lang.IllegalStateException: Scheme 'https' not registered
.
Upvotes: 2