java - 带 https 的 jboss eap jax-ws 客户端失败

标签 java https jboss jax-ws

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

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

    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 调用。您将看到它具有用于 Client Hello 的“TLSv1”。所以我猜这就是问题所在,但不确定原因。

最佳答案

来自 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 

关于java - 带 https 的 jboss eap jax-ws 客户端失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45147224/

相关文章:

performance - 为什么我们将结果发送给用户时需要 HTTPS

tomcat https 端口上的 JSP 显示不正确

java - 在 Java WAR 文件中部署 Angular 6

java - 没有注册类 'com.appspot.<projectname>.model.News'

java - 为什么 JVM 需要这么长时间来 GC 我无法访问的对象?

java - 使用 while 循环删除字符,直到达到计数,Java 不工作

java - LibGDX And​​roid : Lag with 25+ sprites despite use of TimeKeeping

ssl - Coldfusion:使用 SSL 加密页面 (https://) 的 CFHTTP - 出现错误

java - JBoss 编码 utf 8

maven - 在 VM 上查找 java ee 文件