Open jhulst opened 10 years ago
Can you enable verbose logging in ion? That will give me more info
Verbose logging below. I substituted https://google.com for our internal host in the logfiles but the original calls were done on our internal host. It looks like Ion is trying to do the actual network access rather than use the mock from Robolectric. Also, I realized that our API URL has an auto-redirect to an https:// url so it actually was hitting an SSL endpoint (which does have a properly signed key).
Thanks for your help
D/Ion: (0 ms) https://google.com/2/resources/publications: preparing request
I/Ion: (0 ms) https://google.com/2/resources/publications: Using loader: com.koushikdutta.ion.loader.HttpLoader@2c92fcb9
D/Ion: (0 ms) https://google.com/2/resources/publications: Executing request.
V/Ion: (14 ms) https://google.com/2/resources/publications: Resolving domain and connecting to all available addresses
V/Ion: (459 ms) https://google.com/2/resources/publications: socket connected
V/Ion: (466 ms) https://google.com/2/resources/publications:
GET /2/resources/publications HTTP/1.1
Host: google.com
User-Agent: Java1.7.0_51
Accept-Encoding: gzip, deflate
Connection: keep-alive
Accept: */*
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397)
at com.koushikdutta.async.AsyncSSLSocketWrapper.handleResult(AsyncSSLSocketWrapper.java:226)
at com.koushikdutta.async.AsyncSSLSocketWrapper.write(AsyncSSLSocketWrapper.java:356)
at com.koushikdutta.async.Util$7.onWriteable(Util.java:192)
at com.koushikdutta.async.Util.writeAll(Util.java:199)
at com.koushikdutta.async.Util.writeAll(Util.java:207)
at com.koushikdutta.async.http.AsyncHttpResponseImpl.setSocket(AsyncHttpResponseImpl.java:66)
at com.koushikdutta.async.http.AsyncHttpClient$3.onConnectCompleted(AsyncHttpClient.java:358)
at com.koushikdutta.async.http.AsyncSocketMiddleware$2$2$1.onConnectCompleted(AsyncSocketMiddleware.java:246)
at com.koushikdutta.async.http.AsyncSSLSocketMiddleware$1.onConnectCompleted(AsyncSSLSocketMiddleware.java:41)
at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:743)
at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:583)
at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:36)
at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:531)
E/Ion: (480 ms) https://google.com/2/resources/publications: exception during response
E/Ion: connection closed before response completed.
com.koushikdutta.async.http.ConnectionClosedException: connection closed before response completed.
at com.koushikdutta.async.http.AsyncHttpResponseImpl$3.onCompleted(AsyncHttpResponseImpl.java:95)
at com.koushikdutta.async.AsyncSSLSocketWrapper.report(AsyncSSLSocketWrapper.java:382)
at com.koushikdutta.async.AsyncSSLSocketWrapper.handleResult(AsyncSSLSocketWrapper.java:247)
at com.koushikdutta.async.AsyncSSLSocketWrapper.write(AsyncSSLSocketWrapper.java:356)
at com.koushikdutta.async.Util$7.onWriteable(Util.java:192)
at com.koushikdutta.async.Util.writeAll(Util.java:199)
at com.koushikdutta.async.Util.writeAll(Util.java:207)
at com.koushikdutta.async.http.AsyncHttpResponseImpl.setSocket(AsyncHttpResponseImpl.java:66)
at com.koushikdutta.async.http.AsyncHttpClient$3.onConnectCompleted(AsyncHttpClient.java:358)
at com.koushikdutta.async.http.AsyncSocketMiddleware$2$2$1.onConnectCompleted(AsyncSocketMiddleware.java:246)
at com.koushikdutta.async.http.AsyncSSLSocketMiddleware$1.onConnectCompleted(AsyncSSLSocketMiddleware.java:41)
at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:743)
at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:583)
at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:36)
at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:531)
Caused by: com.koushikdutta.async.AsyncSSLException: Peer not trusted by any of the system trust managers.
at com.koushikdutta.async.AsyncSSLSocketWrapper.handleResult(AsyncSSLSocketWrapper.java:246)
... 12 more
E/Ion: (487 ms) https://google.com/2/resources/publications: Connection error
E/Ion: connection closed before response completed.
com.koushikdutta.async.http.ConnectionClosedException: connection closed before response completed.
at com.koushikdutta.async.http.AsyncHttpResponseImpl$3.onCompleted(AsyncHttpResponseImpl.java:95)
at com.koushikdutta.async.AsyncSSLSocketWrapper.report(AsyncSSLSocketWrapper.java:382)
at com.koushikdutta.async.AsyncSSLSocketWrapper.handleResult(AsyncSSLSocketWrapper.java:247)
at com.koushikdutta.async.AsyncSSLSocketWrapper.write(AsyncSSLSocketWrapper.java:356)
at com.koushikdutta.async.Util$7.onWriteable(Util.java:192)
at com.koushikdutta.async.Util.writeAll(Util.java:199)
at com.koushikdutta.async.Util.writeAll(Util.java:207)
at com.koushikdutta.async.http.AsyncHttpResponseImpl.setSocket(AsyncHttpResponseImpl.java:66)
at com.koushikdutta.async.http.AsyncHttpClient$3.onConnectCompleted(AsyncHttpClient.java:358)
at com.koushikdutta.async.http.AsyncSocketMiddleware$2$2$1.onConnectCompleted(AsyncSocketMiddleware.java:246)
at com.koushikdutta.async.http.AsyncSSLSocketMiddleware$1.onConnectCompleted(AsyncSSLSocketMiddleware.java:41)
at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:743)
at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:583)
at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:36)
at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:531)
Caused by: com.koushikdutta.async.AsyncSSLException: Peer not trusted by any of the system trust managers.
at com.koushikdutta.async.AsyncSSLSocketWrapper.handleResult(AsyncSSLSocketWrapper.java:246)
... 12 more
V/Ion: (499 ms) https://google.com/2/resources/publications: closing out socket (exception)
E/ResourceService: Error getting resources
java.util.concurrent.ExecutionException: com.koushikdutta.async.http.ConnectionClosedException: connection closed before response completed.
at com.koushikdutta.async.future.SimpleFuture.getResult(SimpleFuture.java:46)
at com.koushikdutta.async.future.SimpleFuture.get(SimpleFuture.java:41)
at com.myapp.data.services.ResourceService.getAllResources(ResourceService.java:89)
at com.myapp.data.services.ResourceServiceTest.shouldGetAllResourcesForUser(ResourceServiceTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: com.koushikdutta.async.http.ConnectionClosedException: connection closed before response completed.
at com.koushikdutta.async.http.AsyncHttpResponseImpl$3.onCompleted(AsyncHttpResponseImpl.java:95)
at com.koushikdutta.async.AsyncSSLSocketWrapper.report(AsyncSSLSocketWrapper.java:382)
at com.koushikdutta.async.AsyncSSLSocketWrapper.handleResult(AsyncSSLSocketWrapper.java:247)
at com.koushikdutta.async.AsyncSSLSocketWrapper.write(AsyncSSLSocketWrapper.java:356)
at com.koushikdutta.async.Util$7.onWriteable(Util.java:192)
at com.koushikdutta.async.Util.writeAll(Util.java:199)
at com.koushikdutta.async.Util.writeAll(Util.java:207)
at com.koushikdutta.async.http.AsyncHttpResponseImpl.setSocket(AsyncHttpResponseImpl.java:66)
at com.koushikdutta.async.http.AsyncHttpClient$3.onConnectCompleted(AsyncHttpClient.java:358)
at com.koushikdutta.async.http.AsyncSocketMiddleware$2$2$1.onConnectCompleted(AsyncSocketMiddleware.java:246)
at com.koushikdutta.async.http.AsyncSSLSocketMiddleware$1.onConnectCompleted(AsyncSSLSocketMiddleware.java:41)
at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:743)
at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:583)
at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:36)
at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:531)
Caused by: com.koushikdutta.async.AsyncSSLException: Peer not trusted by any of the system trust managers.
at com.koushikdutta.async.AsyncSSLSocketWrapper.handleResult(AsyncSSLSocketWrapper.java:246)
... 12 more
java.lang.NullPointerException
at com.myapp.data.services.ResourceServiceTest.shouldGetAllResourcesForUser(ResourceServiceTest.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
E/NIO: Unhandled exception
java.nio.channels.ClosedChannelException
at sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:265)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:474)
at com.koushikdutta.async.SocketChannelWrapper.write(SocketChannelWrapper.java:32)
at com.koushikdutta.async.AsyncNetworkSocket.write(AsyncNetworkSocket.java:122)
at com.koushikdutta.async.BufferedDataSink.write(BufferedDataSink.java:57)
at com.koushikdutta.async.AsyncSSLSocketWrapper.writeTmp(AsyncSSLSocketWrapper.java:265)
at com.koushikdutta.async.AsyncSSLSocketWrapper.write(AsyncSSLSocketWrapper.java:345)
at com.koushikdutta.async.Util$7.onWriteable(Util.java:192)
at com.koushikdutta.async.Util.writeAll(Util.java:199)
at com.koushikdutta.async.Util.writeAll(Util.java:207)
at com.koushikdutta.async.http.AsyncHttpResponseImpl.setSocket(AsyncHttpResponseImpl.java:66)
at com.koushikdutta.async.http.AsyncHttpClient$3.onConnectCompleted(AsyncHttpClient.java:358)
at com.koushikdutta.async.http.AsyncSocketMiddleware$2$2$1.onConnectCompleted(AsyncSocket
Process finished with exit code 255
"Peer not trusted by any of the system trust managers." and "peer not authenticated" are your concern.
I am not familiar with Roboelectric. Are you using a wildcard cert by chance?
I saw something similar the other day in my own usage. I'm guessing you are using a wildcard cert on your server, and the default strict name verifier is failing. You may need to use browser compat name verification. That's configurable by modifying the AsyncSSLSocketMiddleWare in AsyncHttpClient, accessible in Ion.getDefault().configure().
Ie, *.foo.com cert will fail matching hello.world.foo.com. It will work on world.foo.com though.
Anyways, let me know on the SSL issue. I am fairly certain that the aforementioned wildcard cert is the cause (and is addressable by using the lax browser compat verifier).
I'll take a look at RoboElectric and see what that's about.
The server is using a wildcard certificate but it's only one level deep so it looks like StrictHostnameVerifier should handle it correctly (the cert is for *.google.com and the domain I'm hitting is api.google.com).
I tried removing Robolectric from the equation and if I run the Ion call as normal it works as expected (even without modifying the hostname verifier). It's only when running in Robolectric's environment that it fails (and changing the Hostname verifier to AllowAllHostnameVerifier didn't change anything). I'm guessing there is some incompatibility between Robolectric and Ion due to the way Robolectric mocks out the HTTP calls.
We use Robolectric for some of our testing and really like the way we can insert mock HTTP responses. When trying it out with an Ion request, I get the following SSL related error (which is interesting because the URL we're mocking isn't https).