java - 使用 wsimport 时出现安全异常

标签 java exception ssl ant wsimport

我想从一个 wsdl 文件生成 stub 文件,该文件可以通过带有自签名证书的 ssl 连接访问。

<exec executable="wsimport">
<arg value="-d" />
<arg value="${absolute.path.to.project}/gen" />
<arg value="-s" />
<arg value="${absolute.path.to.project}/src" />
<arg value="https://host:8443/wsrf/services/WS?wsdl" />
</exec>

当我在 ant 中执行此操作时,出现此错误:

generate-from-wsdl:
     [exec] parsing WSDL...
     [exec] [ERROR] sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
     [exec] Failed to read the WSDL document: https://192.168.56.101:8443/wsrf/services/KnowledgebaseWebservice?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>.
     [exec] [ERROR] failed.noservice=Could not find wsdl:service in the provided WSDL(s): 
     [exec]  At least one WSDL with at least one service definition needs to be provided.
     [exec]     Failed to parse the WSDL.
     [exec] Result: 1

为了避免这种情况,我尝试了

  • 使用 keytool -importcert -file ~/path/server.crt 导入 server.crt 文件
  • 将 server.crt 复制到 $JAVA_HOME/lib/security

更新

我还尝试了以下方法:

<wsimport wsdl="https://host:8443/Webservice?wsdl" destdir="gen"
              sourcedestdir="src"
              verbose="true">
    <jvmarg value="-Djavax.net.ssl.trustStore=/path/host.cer" />
    <jvmarg value="-Djavax.net.ssl.trustStorePassword=changeit" />
</wsimport>

我仍然遇到这个错误。我能做什么?

最佳答案

我认为您需要通过指定 -keystore <path_to>/jre/lib/security/cacerts 将服务器证书导入到 JRE 的 keystore 中.如果您坚持使用以前的命令行,我认为您需要为执行 Ant 的同一用户执行该命令。

关于java - 使用 wsimport 时出现安全异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6576030/

相关文章:

java - 需要在一个复杂度为 O(n) 的循环中打印一个图案。我尝试了以下但不确定复杂性

java - 在java中处理对象的可空性检查

eDirectory 和 OpenLDAP 之间的 SSL 连接

java - 未处理的异常的输出与程序的输出混淆

java - 在 Java 8 流中捕获 UncheckedIOException

ssl - TLS 版本与蜂窝通信技术有关系吗?

ssl - 带 SNI 的本地 HTTPS 服务器

java - 排序坐标系

java - 使用 Java 和 selenium 的 css 选择器中的多个值

java - 根据当前时区与东部时区的时差更改 LocalDateTime