Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Security exception while using wsimport

I want to generate stub files from a wsdl file which is reachable over a ssl connection with a self-signed certificate.

<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>

When I execute this in ant, I get this error:

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

To avoid this, I tried to

  • Import the server.crt file with keytool -importcert -file ~/path/server.crt
  • Copying the server.crt to $JAVA_HOME/lib/security

UPDATE

I've also tried the following:

<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>

I still get this error. What could I do?

like image 329
strauberry Avatar asked Jul 04 '11 21:07

strauberry


2 Answers

I think you will need to import the server cert into the JRE's keystore by specifying -keystore <path_to>/jre/lib/security/cacerts. If you stick with your previous command line, I think you'll need to execute that command for the same user who executes Ant.

like image 121
sudocode Avatar answered Nov 13 '22 17:11

sudocode


I cannot import cert to my /jre/lib/security/cacerts.

So I ended up with the following workaround:

<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>
like image 2
lovelywib Avatar answered Nov 13 '22 18:11

lovelywib