gpt4 book ai didi

java - 由于 java 中缺少证书(基于 XML SOAP)而导​​致使用 Web 服务时出错

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:23:40 25 4
gpt4 key购买 nike

我需要使用在 java 中的 Https 下构建的 Web 服务。Web 服务客户端是使用 Eclipse 生成的,我使用以下代码调用它:

ServicioTimbradoPruebasLocator ServicioTimbradoLocator = new ServicioTimbradoPruebasLocator();
ServicioTimbradoPruebasSoap ServicioTimbrado = ServicioTimbradoLocator.getServicioTimbradoPruebasSoap();
javax.xml.rpc.Stub s =((javax.xml.rpc.Stub)ServicioTimbrado);
s._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "XXXXXXXX");
s._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "psswd");
String resultado = ServicioTimbrado.generaTimbre(xml.getBytes());
System.out.println("resultado: " +resultado);

在这一行 String resultado = ServicioTimbrado.generaTimbre(xml.getBytes()); 我收到以下错误:

AxisFault
[java] faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
[java] faultSubcode:
[java] faultString: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[java] faultActor:
[java] faultNode:
[java] faultDetail:
[java] {http://xml.apache.org/axis/}stackTrace:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[java] at sun.security.ssl.Alerts.getSSLException(Unknown Source)
[java] at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
[java] at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
[java] at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
[java] at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
[java] at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
[java] at sun.security.ssl.Handshaker.processLoop(Unknown Source)
[java] at sun.security.ssl.Handshaker.process_record(Unknown Source)
[java] at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
[java] at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
[java] at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
[java] at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
[java] at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:186)
[java] at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
[java] at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
[java] at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
[java] at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
[java] at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
[java] at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
[java] at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
[java] at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
[java] at org.apache.axis.client.Call.invoke(Call.java:2767)
[java] at org.apache.axis.client.Call.invoke(Call.java:2443)
[java] at org.apache.axis.client.Call.invoke(Call.java:2366)
[java] at org.apache.axis.client.Call.invoke(Call.java:1812)
[java] at mx.com.timbrado.test.cfdi.ServicioTimbradoPruebasSoapStub.generaTimbre(ServicioTimbradoPruebasSoapStub.java:107)
[java] at natura.facturacion.general.GuardarFacturaElectronicav2.doPost(GuardarFacturaElectronicav2.java:136) ...

我想知道是否可以通过网络服务调用发送证书。可以找到有关 wsdl 契约(Contract)和 java 生成文件的更多信息 here

最佳答案

根据您使用的 Java 版本,1.6 JRE/JDK 的“最近”更新之一包括全局 CACert(签署 SSL 证书的可信机构,例如 Verisign)的重大变化,以包括一些周围的新证书类型。

我建议升级到最新版本的 Java,看看是否可行,如果不行,选项 2 是...

使用 SSLPoke.java您可以找出缺少哪些证书,以及 InstallCert.java按如下方式安装它们;

  1. java InstallCert webserver.domain.com:443
  2. 将生成的“jssecacerts”文件复制到“$JAVA_HOME\jre\lib\security”文件夹。

如果这仍然导致问题,您能否包括 sslpoke 的输出,示例用法;

# java SSLPoke webserver.domain.com 443
Successfully connected

如果所有这些都不起作用,并且您可以获得证书文件 (crt),您可以使用 keytool 命令手动导入该文件(cacerts 是一个将在您的本地工作目录中创建的文件;确保将其移动到JRE/JDK 中的 java 安全文件夹);

keytool -import -trustcacerts -alias AddTrustExternalCARoot -file cetificate.crt -keystore cacerts

关于java - 由于 java 中缺少证书(基于 XML SOAP)而导​​致使用 Web 服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9085970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com