【问题标题】:Security exception while using wsimport使用 wsimport 时出现安全异常
【发布时间】:2011-07-04 21:01:58
【问题描述】:

我想从 wsdl 文件生成存根文件,该文件可通过带有自签名证书的 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>

我仍然收到此错误。我能做什么?

【问题讨论】:

  • Ant 是否以您为keytool -import 执行的用户身份执行?
  • 我担心不会 :-) 导入是以 root (sudo) 身份执行的,ant 是以普通用户身份执行的……但我正在研究另一种解决方案 a.t.m.如果可行,我会在这里发布
  • 您可以下载 WSDL 的本地副本(以及任何引用的 XSD 文件),然后从本地副本生成存根。

标签: java exception ssl ant wsimport


【解决方案1】:

我认为您需要通过指定 -keystore &lt;path_to&gt;/jre/lib/security/cacerts 将服务器证书导入 JRE 的密钥库。如果您坚持使用以前的命令行,我认为您需要为执行 Ant 的同一用户执行该命令。

【讨论】:

  • 这个blog post 概述了使用keytool.exe 将服务器证书导入JRE 密钥库的步骤,供那些像我一样不熟悉该过程的人使用。
【解决方案2】:

我无法将证书导入我的 /jre/lib/security/cacerts。

所以我最终得到了以下解决方法:

<target name="main" >
    <exec executable="java">
        <arg line="-Djavax.net.ssl.trustStore=c:\jdk160_29\.mykeystore  -classpath C:\jdk160_29\lib\tools.jar com.sun.tools.internal.ws.WsImport https://host:8443/Webservice?wsdl -p com.test -s ./src"/>
    </exec>
</target>

【讨论】:

  • 你把这个目标标签放在哪里了?
猜你喜欢
  • 2011-04-01
  • 1970-01-01
  • 2019-12-10
  • 1970-01-01
  • 2012-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-14
相关资源
最近更新 更多