Remote host closed connection during handshake Exception

637 views
Skip to first unread message

Qaddaffi Sulaiman

unread,
May 21, 2018, 6:11:26 AM5/21/18
to REST assured
Hey Guys,

I am trying to test a Get API service which initially looked rather simple, but I am stuck with this exception 'javax.net.ssl.SSLHandshakeException:' for the last few hours. I tried changing protocol like 'System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");' and also tried using 'relaxedHTTPSValidation', but nothing seem to fix this issue. The only other solution that I have not tried so far is adding the certificates to trust store, but I am unable to grab that concept. My exception looks like below,

 javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1002)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
      at org.apache.http.conn.ssl.SSLSocketFactory.createLayeredSocket(SSLSocketFactory.java:573)
      at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:557)
      at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
      at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
      at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)
      at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
      at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
      at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
      at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)
      at io.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:2128)
      at io.restassured.internal.http.HTTPBuilder.doRequest(HTTPBuilder.java:494)
      at io.restassured.internal.http.HTTPBuilder.request(HTTPBuilder.java:451)
      at io.restassured.internal.http.HTTPBuilder$request$3.call(Unknown Source)
      at io.restassured.internal.RequestSpecificationImpl.sendHttpRequest(RequestSpecificationImpl.groovy:1531)
      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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)
      at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
      at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)
      at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)
      at io.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1290)
      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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)
      at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
      at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)
      at io.restassured.internal.filter.SendRequestFilter.filter(SendRequestFilter.groovy:30)
      at io.restassured.filter.Filter$filter$0.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at io.restassured.filter.Filter$filter.call(Unknown Source)
      at io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)
      at io.restassured.filter.time.TimingFilter.filter(TimingFilter.java:56)
      at io.restassured.filter.Filter$filter.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      at io.restassured.filter.Filter$filter$0.call(Unknown Source)
      at io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)
      at io.restassured.filter.FilterContext$next.call(Unknown Source)
      at io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1731)
      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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)
      at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
      at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)
      at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
      at io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1737)
      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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)
      at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
      at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)
      at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
      at io.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy:170)
      at io.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy)
      at com.sss.tests.WebRestApi.TC015_RestApi_Verify_DeliveryConfirmationEmail_CODOrder_RegisteredCustomer_Test.verifyDeliveryConfirmationEmailIsSent(TC015_RestApi_Verify_DeliveryConfirmationEmail_CODOrder_RegisteredCustomer_Test.java:347)
      at ?.Then The order delivery confirmation email should be sent to customer email - Email Scenario1(SSS08_CustomerOrder_DeliveryConfirmation_Email.feature:13)
      Caused by: java.io.EOFException: SSL peer shut down incorrectly

So if anyone could let me know any fix for this, that would be much appreciated.

Qaddaffi Sulaiman

unread,
May 21, 2018, 6:24:25 AM5/21/18
to REST assured
Additional info - I am able to hit this service successfully in PostMan API client.

Qaddaffi Sulaiman

unread,
May 22, 2018, 3:44:00 AM5/22/18
to REST assured
I solved it by using the java code that was generated by Postman client. When we are able to successfully process a api call through postman, it also generates code in pretty much all popular languages to programmatically mimic the same.  For my request, the code that was generated looks like the below,

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
  .url("your endpoint url")
  .get()
  .addHeader("Cache-Control", "no-cache")
  .build();


On Monday, May 21, 2018 at 2:11:26 PM UTC+4, Qaddaffi Sulaiman wrote:
Reply all
Reply to author
Forward
0 new messages