HTTPS issue for Jersey Server and Jersey Clinet

872 views
Skip to first unread message

Ashok K S

unread,
Dec 13, 2015, 3:03:25 AM12/13/15
to wiremock-user
com.sun.jersey.api.client.ClientHandlerException: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:671)
at sun.security.ssl.InputRecord.read(InputRecord.java:504)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
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.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1092)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler$1$1.getOutputStream(URLConnectionClientHandler.java:225)
at com.sun.jersey.api.client.CommittingOutputStream.commitWrite(CommittingOutputStream.java:117)
at com.sun.jersey.api.client.CommittingOutputStream.write(CommittingOutputStream.java:89)
at com.sun.jersey.api.client.filter.LoggingFilter$LoggingOutputStream.write(LoggingFilter.java:110)
at org.codehaus.jackson.impl.Utf8Generator._flushBuffer(Utf8Generator.java:1746)
at org.codehaus.jackson.impl.Utf8Generator.flush(Utf8Generator.java:1082)
at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1347)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:527)
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
at com.sun.jersey.api.client.filter.LoggingFilter.handle(LoggingFilter.java:183)
at com.sun.jersey.api.client.filter.HTTPBasicAuthFilter.handle(HTTPBasicAuthFilter.java:81)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:670)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.method(WebResource.java:613)


Ashok K S

unread,
Dec 13, 2015, 3:04:47 AM12/13/15
to wiremock-user
It is https Wiremock server.

Tom Akehurst

unread,
Dec 13, 2015, 6:12:27 AM12/13/15
to wiremock-user
This is almost certainly because you're trying to connect to the HTTP using HTTPS.

Suggest checking that your client port number matches WireMock's https port.

Marvel

unread,
Dec 13, 2015, 12:51:34 PM12/13/15
to wiremock-user
WireMockServer server = new WireMockServer(443);
server.start();
WireMock.configureFor("localhost", 443);

server.stubFor(post(urlEqualTo("a/b/c"))
 .withHeader(...)
 .willReturn(withResponseFile(aResponse(), "Response", server.port()))
 .withStatus(Status,CREATED.getStatusCode())
  .withHeader("Content-Type", "")
);

Is it correct to start wiremock https server on port 443 ?

Tom Akehurst

unread,
Dec 13, 2015, 12:59:47 PM12/13/15
to wiremock-user
You're starting the HTTP connector on port 443 there, which I'm guessing isn't what you want.

Pass wireMockConfig().httpsPort(443) into the constructor instead.

Marvel

unread,
Dec 13, 2015, 2:54:25 PM12/13/15
to wiremock-user
Passed WireMockConfiguration.wireMockConfig().httpsPort(443) into the constructor and getting same issue.   Also tried without WireMock.configureFor("localhost", 443); and getting same issue.

WireMockServer server = new WireMockServer(WireMockConfiguration.wireMockConfig.httpsPort(443));
server.start();
WireMock.configureFor("localhost", 443);

On Sunday, December 13, 2015 at 12:03:25 AM UTC-8, Marvel wrote:

Tom Akehurst

unread,
Dec 13, 2015, 3:12:16 PM12/13/15
to wiremock-user
WireMock.configureFor(host, port) sets the HTTP port, not HTTPS so ensure the port you pass to that is the http port (8080 by default)

Marvel

unread,
Dec 13, 2015, 3:25:58 PM12/13/15
to wiremock-user
WireMock.configureFor("localhost", 8080); also gives same issue


On Sunday, December 13, 2015 at 12:03:25 AM UTC-8, Marvel wrote:

Tom Akehurst

unread,
Dec 13, 2015, 3:41:07 PM12/13/15
to wiremock-user
Then your client code is most likely pointed at the wrong port.

Marvel

unread,
Dec 13, 2015, 4:05:32 PM12/13/15
to wiremock-user
I passed wireMockServer.port() to client and it gives http port 8080. I changed to hardcoded 443 port for Client and getting  Error SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost found

Couple of questions: Is it mandatory to set SSL certs on Client and Server side ?
                              Can i disable the host name verification ?

com.sun.jersey.api.client.ClientHandlerException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost found
at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:221)
at sun.security.util.HostnameChecker.match(HostnameChecker.java:95)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:347)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:203)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1428)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:913)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:849)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1023)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
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.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1092)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler$1$1.getOutputStream(URLConnectionClientHandler.java:225)
at com.sun.jersey.api.client.CommittingOutputStream.commitWrite(CommittingOutputStream.java:117)
at com.sun.jersey.api.client.CommittingOutputStream.write(CommittingOutputStream.java:89)
at com.sun.jersey.api.client.filter.LoggingFilter$LoggingOutputStream.write(LoggingFilter.java:110)
at org.codehaus.jackson.impl.Utf8Generator._flushBuffer(Utf8Generator.java:1746)
at org.codehaus.jackson.impl.Utf8Generator.flush(Utf8Generator.java:1082)
at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1347)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:527)
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
at com.sun.jersey.api.client.filter.LoggingFilter.handle(LoggingFilter.java:183)
at com.sun.jersey.api.client.filter.HTTPBasicAuthFilter.handle(HTTPBasicAuthFilter.java:81)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:670)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.method(WebResource.java:613)


On Sunday, December 13, 2015 at 12:03:25 AM UTC-8, Marvel wrote:

Tom Akehurst

unread,
Dec 13, 2015, 4:13:27 PM12/13/15
to wiremock-user
You have three options:
1) configure your client to trust WireMock's embedded keystore
2) generate your own keystore containing a cert, set your client to trust it and set it as WM's keystore
3) configure your client to trust all certs (usually via SSLContext)

WireMock's HttpsAcceptanceTest configures the apache client as per 1.

Stackoverflow has examples of 2 and 3.

Reply all
Reply to author
Forward
0 new messages