使用https的jboss eap jax-ws客户端失败

时间:2017-07-17 14:44:43

标签: java https jboss jax-ws

(这是在Windows机器上运行jboss eap7.0)我生成了一个jax-ws客户端来连接外部Web服务。

使用https,网址为https://smartpayform.com/api/transaction/transaction.asmx  我已导出站点证书并插入到我创建的密钥库中。我找不到关于如何直接配置jboss的详细信息(在standalone.xml或cli中),所以我 找到一些java代码将证书添加到jax-ws客户端:

    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() );

该代码运行没有任何例外。当我执行SOAP调用时,我收到以下错误。如果我尝试使用一个简单的旧的独立Java应用程序访问EAP之外的Web服务,它可以正常工作。我做错了什么?

 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)

更新 我在jboss中启用了完整的ssl调试日志记录。我看到端点的证书已加载:

 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

以下是套接字错误的更完整描述:

 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

wireshark下面的前三行显示了无效的连接。您会注意到它正在使用SSL。第二组线是在soapui中运行相同的soap调用。你会发现它有" TLSv1"为客户你好。所以我猜这是问题所在,但不确定原因。

1 个答案:

答案 0 :(得分:1)

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

  

在某些安装了IPv6 TCP堆栈的Windows系统上会出现此问题。如果计算机上同时安装了IPv4和IPv6,则Java虚拟机(JVM)可能无法在操作系统级别关闭或打开套接字。

     

添加以下JVM选项:

-Djava.net.preferIPv4Stack=true