gpt4 book ai didi

java - SOAP 客户端 SSL,身份验证失败

转载 作者:行者123 更新时间:2023-11-30 10:12:56 27 4
gpt4 key购买 nike

我正在组装一个 soap 客户端来调用第三方 soap 服务。我在连接 Java 时遇到问题。它适用于 SoapUI。这是我第一次在应用程序中设置 keystore 。我找到的所有代码都是一样的,而且非常简单,但我无法弄清楚为什么 java 版本无法正常工作。我使用的是公司提供的 TLS pfx 文件,我也尝试连接其服务.我从服务器返回 403。这是代码

        URL wsdlLocation = new URL(SECURE_INTEGRATION_WSDL);
ObjectFactory ofactory = new ObjectFactory();
HttpsURLConnection httpsConnection = (HttpsURLConnection)wsdlLocation.openConnection();
char[] password = CLIENT_KEYSTORE_PASSWORD.toCharArray();

//load keystore
FileInputStream is = new FileInputStream(new File(CLIENT_KEYSTORE_PATH));
final KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(is, password);
is.close();

KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");

kmf.init(keystore, password);

//set the ssl context
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), null,
new java.security.SecureRandom());


httpsConnection.setSSLSocketFactory(sc.getSocketFactory());



SecureIntegrationServicesImap client = new SecureIntegrationServicesImap(wsdlLocation);


SesMessage message = ofactory.createSesMessage();

ReceiveRequest r = ofactory.createReceiveRequest();

r.setEmail(ofactory.createReceiveRequestEmail("<email ommitted>"));
ArrayOfMessageSummary messages = client.getWSHttpBindingSecureIntegrationServiceImap().getMessageList(r);
log.info(messages.getMessageSummary().size());

非常感谢任何对我错误的帮助..

不确定这是否重要,但服务器是 .NET 平台

这是我得到的堆栈跟踪

javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://<host omitted>/TS?wsdl. It failed with: 
Server returned HTTP response code: 403 for URL: https://<host omitted>/TS?wsdl.
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:265)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:246)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:209)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:178)
at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:363)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:321)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:230)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:211)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:207)
at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:114)
at javax.xml.ws.Service.<init>(Service.java:77)
at org.tempuri.SecureIntegrationServicesImap.<init>(SecureIntegrationServicesImap.java:50)
at com.wiredinformatics.utils.SecureExchange.main(SecureExchange.java:127) Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: https://host omitted/TS?wsdl
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at java.net.URL.openStream(URL.java:1045)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:999)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:400)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:231)
... 11 more

最佳答案

听起来您正在使用基于 TLS 的客户端身份验证。根据您发布的代码,我怀疑问题是您在初始化后没有在任何地方使用 httpsConnection 。因此,它不会像您期望的那样尝试使用您的客户端证书,而是使用默认的请求上下文设置。

假设您使用的是 JAX-WS,您应该能够使用 this answer 中概述的解决方案将您的证书绑定(bind)到您的请求上下文(而不是初始化您自己的 HttpsURLConnection):

HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

关于java - SOAP 客户端 SSL,身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51620712/

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