【问题标题】:Debugging error org.apache.axis2.AxisFault: Connection or outbound has closed, the trustAnchors parameter must be non-empty调试错误 org.apache.axis2.AxisFault: Connection or outbound has closed, trustAnchors 参数必须非空
【发布时间】:2021-04-30 13:42:49
【问题描述】:

我们在尝试使用带有 Java OpenJDK 14 和 Apache Tomcat 9 的 Netbeans 连接到 Web 服务时遇到了麻烦。这是一个特定的环境,需要 Axis2 1.6.2 库通过受 keytool 信任的 SSL 证书连接到 WSDL。我们将 Axis2 更改为 1.7.9,但没有成功。

我们得到以下错误:

org.apache.axis2.AxisFault: Connection or outbound has closed
org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:78)
org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)

com.ctc.wstx.exc.WstxIOException: Connection or outbound has closed
    com.ctc.wstx.sw.BaseStreamWriter.finishDocument(BaseStreamWriter.java:1687)
    com.ctc.wstx.sw.BaseStreamWriter.close(BaseStreamWriter.java:288)
    org.apache.axiom.om.impl.MTOMXMLStreamWriter.close(MTOMXMLStreamWriter.java:222)
    org.apache.axiom.om.impl.llom.OMSerializableImpl.serializeAndConsume(OMSerializableImpl.java:192)
    org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:74)
    org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)

java.net.SocketException: Connection or outbound has closed
    java.base/sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:1246)
    java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
    java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)
    java.base/java.io.FilterOutputStream.flush(FilterOutputStream.java:153)

我们尝试使用以下代码测试一个 java 主类:

System.setProperty("javax.net.ssl.trustStore", "pathToKeystore");
System.setProperty("javax.net.ssl.keyStorePassword", "myKeystorePassword");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");

RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();

EndpointReference targetEPR = new EndpointReference(wsdlDatos);
options.setTo(targetEPR);
options.setTimeOutInMilliSeconds(600000);

clientDatosConsultaDetalles datos = new clientDatosConsultaDetalles();

datos.setUser(usuario);
datos.setPassword(password);
datos.setIpAddress(ip);


System.out.println("Getting service: " + wsdlDatos);
System.out.println(targetEPR.getAddress()); 

// Generate curp
QName service = new QName("http://services.wserv.ecurp.dgti.segob.gob.mx", "consultarCurpDetalle");

Object[] serviceArgs = new Object[]{datos};

Class[] returnTypes = new Class[]{String.class};

Object[] response = serviceClient.invokeBlocking(service, serviceArgs, returnTypes);

但是,抛出错误的行是最后一行:

Object[] response = serviceClient.invokeBlocking(service, serviceArgs, returnTypes);

防火墙规则已打开,网络服务允许连接到 IP 地址列表。我们的 IP 被允许连接,所以关于我们如何调试此错误的任何想法?我们认为与 Web 服务的连接被拒绝,但我们不确定。

编辑:根据评论的建议,结果证明这可能是 SSL 证书的问题,因为使用了 jvm 参数

-Djavax.net.debug=all

发现以下错误:

java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

我们在 OpenJDK 14 中使用 keytool,如下所示:

keytool -import -alias inea -keystore c:\WSCURP\2021\ineacurp.keystore -trustcacerts -file theCer.cer

密钥库是使用上面的行自动生成的。一个查找人员信息的组织为我们提供了 .cer 文件。可能我们在导入 .cer 文件时遗漏了一些关键步骤。

keystore 文件内容正在调试器中显示,这意味着正在检测 keystore 并且对该文件有读/写权限。

奇怪的是,根据调试器,responder_id 是空的

"status_request_v2 (17)": {
      "cert status request": {
        "certificate status type": ocsp_multi
        "OCSP status request": {
          "responder_id": <empty>

还有什么建议吗?

【问题讨论】:

  • 如果我不得不猜测 SSL 握手失败。使用-Djavax.net.debug=ssl-Djavax.net.debug=all 运行测试代码以查看连接失败的位置。
  • @PiotrP.Karwasz 使用 -Djavax.net.debug=all 作为 jvm 参数,检测到潜在错误。 Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty我在帖子中提供了更多详细信息,还有其他建议吗?
  • 从您编辑的消息中不清楚:SSL 握手是否成功?你收到从Produced ClientHello handshake messageConsuming server Finished handshake message 的所有消息了吗?您可以使用-Djavax.net.debug=ssl,handshake 细化记录的数据并将其添加到问题中?
  • 嗯,实际上这是一个愚蠢的错误。由于它是一个导入的项目,Netbeans 没有识别 lib 文件夹中的所有库,我不知道为什么。但是,缺少以下库:javaee-endorsed-api-6.0。项目没有抱怨编译也没有运行时。由于缺少库,我预计构建会失败。添加后,它就像魅力一样。无论如何感谢您的帮助。

标签: java web-services tomcat netbeans axis2


【解决方案1】:

在这种情况下,这是一个愚蠢的错误。我期待 Netbeans 能够识别 lib 文件夹中的所有内容,因为它是一个导入的 Web 项目。然而,这并没有发生。 Netbeans 要求解决缺失的依赖项,但并非所有依赖项都被检测到。缺少的库是 javaee-endorsed-api-6.0。

该项目在编译和运行时都没有抱怨,但握手无法通信。这可以作为axis2错误的替代方法,我在谷歌搜索时发现它并不常见。

【讨论】:

    猜你喜欢
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 2018-06-03
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    相关资源
    最近更新 更多