AnsweredAssumed Answered

CodeSV with https service error

Question asked by gaboguzman on Jan 24, 2018
Latest reply on Jan 25, 2018 by sursu06

Hi all, I'm trying to use CodeSV to mock a HTTPS service that DOES NOT need a keystore and password. Using the example from the documentation for a POST call, I'm getting this error: 

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://beta-sandbox.sensibill.io/api/v1/accessToken": Unrecognized SSL message, plaintext connection?; nested exception is javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
     at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666)
     at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
     at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
     at com.fismobile.mb.digitalreceipts.adapter.impl.SensibillAdapterMockedTest.testBasicExample(SensibillAdapterMockedTest.java:182)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:498)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
     at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
     at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
     at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
     at org.junit.rules.RunRules.evaluate(RunRules.java:20)
     at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
     at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
     at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
     at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:710)
     at sun.security.ssl.InputRecord.read(InputRecord.java:527)
     at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
     at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
     at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
     at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
     at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
     at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
     at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
     at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:78)
     at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
     at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
     at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:99)
     at com.fismobile.mb.digitalreceipts.adapter.impl.LoggingRequestInterceptor.intercept(LoggingRequestInterceptor.java:20)
     at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:86)
     at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:70)
     at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
     at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
     at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:652)
     ... 35 more

Then, when I add this to my code:

.usingHttps(
    withSecureProtocol("TLS")
)

I get this error:

java.lang.RuntimeException: SSL server cannot be initialized.
     at com.ca.codesv.protocols.http.agent.AgentEndpoint.<init>(AgentEndpoint.java:73)
     at com.ca.codesv.protocols.http.agent.SocketRouter.connect(SocketRouter.java:133)
     at com.ca.codesv.protocols.http.agent.WrapSocketImpl.connect(WrapSocketImpl.java:224)
     at java.net.Socket.connect(Socket.java:589)
     at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
     at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
     at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
     at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
     at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
     at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
     at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
     at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
     at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
     at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
     at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
     at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
     at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:78)
     at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
     at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
     at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:99)
     at com.fismobile.mb.digitalreceipts.adapter.impl.LoggingRequestInterceptor.intercept(LoggingRequestInterceptor.java:20)
     at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:86)
     at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:70)
     at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
     at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
     at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:652)
     at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
     at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
     at com.fismobile.mb.digitalreceipts.adapter.impl.SensibillAdapterMockedTest.testBasicExample(SensibillAdapterMockedTest.java:182)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:498)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
     at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
     at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
     at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
     at org.junit.rules.RunRules.evaluate(RunRules.java:20)
     at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
     at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
     at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.NullPointerException
     at java.io.FileInputStream.<init>(FileInputStream.java:130)
     at java.io.FileInputStream.<init>(FileInputStream.java:93)
     at com.ca.codesv.protocols.ssl.SslServer.createKeyManagerFactory(SslServer.java:229)
     at com.ca.codesv.protocols.ssl.SslServer.<init>(SslServer.java:85)
     at com.ca.codesv.protocols.http.agent.AgentEndpoint.<init>(AgentEndpoint.java:58)
     ... 60 more

But I don't need to initialize any SSL server, I just need to call the service. 

FYI: the service API has public access and the same tests without CodeSV work fine.

Outcomes