Search code examples
javasoaphttpssoap-client

SOAP java client HTTPS/SSL


Im trying to call a web service over https , the administrator send me the WSDL file and certificates for my server :

myserver.der
myserver.p7b 
myserver.pem
myserver-bundle.pem

I installed the certificate myserver.der :

keytool -import -trustcacerts -alias myserver -file myserver.der

Then, using wsimport, I generated the stubs.

Before calling the web service, my client is doing this :

String javaHomePath = System.getProperty("java.home");
String keystore = javaHomePath + "\\lib\\security\\cacerts";
String storepass= "changeit";
String storetype= "JKS";

String[][] props = {
      { "javax.net.ssl.trustStore", keystore, },
      { "javax.net.ssl.keyStore", keystore, },
      { "javax.net.ssl.keyStorePassword", storepass, },
      { "javax.net.ssl.keyStoreType", storetype, },
    };
    for (int i = 0; i < props.length; i++)
      System.getProperties().setProperty(props[i][0], props[i][1]);

Questions :

1) I don't know what to do with the other files (.p7b ; .pem) ?

2) It seems that the handshake works , but im getting this error :

 com.sun.xml.internal.ws.client.ClientTransportException: The server sent    HTTP status code 407: Proxy Authentication Required

Thanks for Help


Solution

  • Go through this link to understand the difference between different certificate formats - Different Certificate Formats

    You can go through this link here - Java SOAP client with certificate authentication

    create keystore like this:

    keytool -import -trustcacerts -file myserver.p7b -keystore keystore -storepass <mypasswd> -alias "myalias"
    

    Note that myalias MUST be the same as the one used when the key was generated.

    You can also verify if keystore has certificates

    keytool -list -v -keystore keystore.jks
    

    To debug the ssl handshake process and view the certificates, set the VM parameter -Djavax.net.debug=all

    PS: Also, go through this link which might help you resolve Proxy Authentication Required error - Proxy authentication in Java