2

(this is running jboss eap7.0 on a Windows machine )I Generated a jax-ws client to connect to external web service.

It is using https with an url of https://smartpayform.com/api/transaction/transaction.asmx I have exported the site certificate and inserted into a keystore I created. I could not find enough detail on how to configure jboss directly (in standalone.xml or cli), so I found some java code to add the certificate to the jax-ws client:

    SSLContext sc = SSLContext.getInstance("TLS");
    KeyManagerFactory kmf =    KeyManagerFactory.getInstance( KeyManagerFactory.getDefaultAlgorithm() );
    KeyStore ks = KeyStore.getInstance( KeyStore.getDefaultType() );
    ks.load(new FileInputStream( "C:\\Users\\amikaml\\.keystore" ), certPassword.toCharArray() );
    kmf.init( ks, certPassword.toCharArray() );
    sc.init( kmf.getKeyManagers(), null, null );
     binding.getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory",sc.getSocketFactory() );

That code runs without any exceptions. When I execute the SOAP call, I am getting the error below. If I try to access the web service outside EAP with a plain old, standalone java app, it works fine. What am I doing wrong?

 Caused by: java.net.SocketException: Unrecognized Windows Sockets error: 0: recv failed
 at java.net.SocketInputStream.socketRead0(Native Method) ~[?:1.8.0_111]
 at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[?:1.8.0_111]
 at java.net.SocketInputStream.read(SocketInputStream.java:170) ~[?:1.8.0_111]
 at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_111]
 at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) ~[?:?]
 at sun.security.ssl.InputRecord.read(InputRecord.java:503) ~[?:?]
 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) ~[?:?]


Caused by: java.net.SocketException: Unrecognized Windows Sockets error: 0: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:170)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    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.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
    at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.setupWrappedStream(URLConnectionHTTPConduit.java:236)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1319)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.onFirstWrite(HTTPConduit.java:1279)
    at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.onFirstWrite(URLConnectionHTTPConduit.java:267)
    at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
    at org.apache.cxf.io.AbstractThresholdOutputStream.write(AbstractThresholdOutputStream.java:69)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1332)

UPDATE I turned on full ssl debug logging in jboss. I see that the certificate for the endpoint is loaded:

 Subject: CN=*.smartpayform.com, OU=Domain Control Validated
 Issuer:  CN=AlphaSSL CA - SHA256 - G2, O=GlobalSign nv-sa, C=BE
 Algorithm: RSA; Serial number: 0xc2d0a153e5915039e88cbf7
 Valid from Mon Sep 05 12:33:58 EDT 2016 until Wed Sep 06 12:33:58 EDT 2017

and here is a more complete trace of the socket error:

 handling exception: java.net.SocketException: Unrecognized Windows Sockets error: 0: recv failed
 SEND TLSv1.2 ALERT:  fatal, description = unexpected_message
 WRITE: TLSv1.2 Alert, length = 2
 Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error
 called closeSocket()
 called close()
 called closeInternal(true)

UPDATE #2

The 1st three rows below from wireshark, shows the connection that does not work. You will notice it is using SSL. The second set of lines is from running the same soap call in soapui. You will see that it has "TLSv1" for the Client Hello. So I am guessing that is the problem, but not sure why.

OldProgrammer
  • 12,050
  • 4
  • 24
  • 45

1 Answers1

1

From java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind (JBOSS)

This problem occurs on some Windows systems that have the IPv6 TCP Stack installed. If both IPv4 and IPv6 are installed on the computer, the Java Virtual Machine (JVM) may have problems closing or opening sockets at the operating system level.

Add the following JVM option:

-Djava.net.preferIPv4Stack=true 
Community
  • 1
  • 1
mikep
  • 3,841
  • 8
  • 21