0

I tried to call a web service that changed recently from HTTP to HTTPS and I get this error :

    java.net.SocketException: Unexpected end of file from server

Note that i had issues with certificates but i added them in the truststore via keytool, then i set System properties with:

    System.setProperty("javax.net.ssl.trustStore", "C://Progra~1//Java//jdk1.8.0_201//jre//lib//security//cacerts");
    System.setProperty("javax.net.ssl.trustStorePassword","changeit");

The error that appears:

main, handling exception: java.net.SocketException: Connection reset main, SEND TLSv1.2 ALERT:  fatal, description = unexpected_message main, WRITE: TLSv1.2 Alert, length = 2 main, 
Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error main, called closeSocket()

thank you in advance for your intervention!

Jenea Vranceanu
  • 4,530
  • 2
  • 18
  • 34
  • What errors do you encounter? – Jenea Vranceanu Jun 22 '20 at 14:50
  • `main, handling exception: java.net.SocketException: Connection reset main, SEND TLSv1.2 ALERT: fatal, description = unexpected_message main, WRITE: TLSv1.2 Alert, length = 2 main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error main, called closeSocket()` – adnane Lebouiha Jun 22 '20 at 14:57

2 Answers2

1

Adnane, while trying to run the client you can set extra parameter which will print debug logs on ssl connection negotiation with server.

This way you can check if certificate chain is correct and rule out if it is related to certificates.

-Djavax.net.debug=all
ihimanshu19
  • 136
  • 1
  • 8
  • thank you for your answer. can you explain this response : 'main, handling exception: java.net.SocketException: Connection reset main, SEND TLSv1.2 ALERT: fatal, description = unexpected_message main, WRITE: TLSv1.2 Alert, length = 2 main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error main, called closeSocket()' – adnane Lebouiha Jun 22 '20 at 14:53
  • here is the log : [link](https://pastebin.com/LtwgTSwN) – adnane Lebouiha Jun 22 '20 at 15:16
  • There is definitely no issue with certificate chain as I can see 0000: 47 45 54 20 2F 57 73 44 65 63 65 2E 61 73 6D 78 GET /WsDece.asmx 0010: 3F 57 53 44 4C 20 48 54 54 50 2F 31 2E 31 0D 0A ?WSDL HTTP/1.1.. and server response 0000: 48 54 54 50 2F 31 2E 31 20 32 30 30 20 4F 4B 0D HTTP/1.1 200 OK. But I am not able to understand INFOS: Creating Service {http://interieur.gov.ma/ec/dece}WsDece from WSDL: https://ec-ws-part.cloud.interieur.gov.ma/WsDece.asmx?WSDL Invoking getDeces... – ihimanshu19 Jun 22 '20 at 15:32
  • The interesting thing is that's work fine in Soapui. – adnane Lebouiha Jun 22 '20 at 15:38
0

I solved the problème by setting the header as :

Map<String, Object> req_ctx = ((BindingProvider) port).getRequestContext();
    req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,wsdlURL.toString());          
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    headers.put("Content-Type", Collections.singletonList("text/xml"));        
    req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);

the content type was "application/xml".