我有一个使用相互 SSL 身份验证的 Web 服务。安装客户端证书后,我可以在浏览器中正常访问它。
我需要能够使用 wsimport
访问它以生成 Java 代码来访问该服务。
如何设置我的凭据以便我可以使用 wsimport
访问 URL?
这是我正在尝试的示例,但由于无法进行身份验证而超时。
wsimport ./sample.wsdl -p com.company.ws.sample -Xnocompile -d ./src -extension -keep -XadditionalHeaders
感谢您的帮助
编辑:
这是 wsimport
打印的内容。 WSDL 绝对有效,在给定的位置,问题是弄清楚如何传递我的凭据以进行身份验证:
wsimport https://wsdl.location.com?WSDL -p com.company.ws.sample -Xnocompile
-d ./src -extension -keep -XadditionalHeaders
parsing WSDL...
[ERROR] Received fatal alert: handshake_failure
Failed to read the WSDL document: "https://wsdl.location.com?WSDL", because 1) could
not find the document; /2) the document could not be read; 3) the root element of
the document is not <wsdl:definitions>.
[ERROR] failed.noservice=Could not find wsdl:service in the provided WSDL(s):
At least one WSDL with at least one service definition needs to be provided.
Failed to parse the WSDL.
最佳答案
您可以直接调用 WsImport java 类 (source) 并添加 JVM 必要的参数,让 Java 知道在哪里寻找客户端证书。
有点像
java -classpath C:\jdk160_29\lib\tools.jar -Djavax.net.ssl.trustStore=c:\jdk160_29\.mykeystore com.sun.tools.internal.ws.WsImport https://host:8443/Webservice?wsdl -p com.test -s ./src"
应该可以解决问题。
关于java - 服务器需要客户端证书时如何使用 wsimport?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11848321/