Search code examples
javaweb-servicesjax-ws

How to call JAX WS from a stand alone java file?


I am trying to call a jax ws web service from a stand alone java class(containing the main method). I have tried this in SOAP UI and there it returns the response.

My Java Code : Inside the main() method :

GInformation getGMInfo = new GInformation();
GInformationResult getGMResult = new GInformationResult();

GKService GKProxy = getProxy();

//Set the Request
XMLGregorianCalendar xmlGreg = null;
getGMInfo.setRequestId("");
getGMInfo.setMessageDateTime(xmlGreg);

try {
    //Get the response
    getGMResult = GKProxy.getGInformation(getGMInfo);
    System.out.println("Address: "+getGMResult.getInfo());
} catch (OperationFaultException e) {
    e.printStackTrace();
} catch (SystemFaultException e) {
    e.printStackTrace();
} 

But it is failing with an error like this :

org.apache.axis2.AxisFault: WSWS7130E: No Secure Sockets Layer (SSL) configuration is available for the https://mklip.verd.Gin/WS/v2.8 endpoint.

I have been trying to rectify this for a very long time and am on the verge of becoming mad. Can somebody tell me what i am doing wrong here ? Is it at all possible to invoke jax-ws from a a stand alone java class or do we need web server for that ? But this application does not have a web server.


Solution

  • I had to delve deeper and deeper to resolve this issue. The problem that i had is a trusted certificate issue. So first, i got my hands on the certificates required for invoking the service(cert1.cer, cert2.cer).

    Then i integrated the certificates locally using these steps :

    1. Place the below cry certificates in the path "C:\Program Files\IBM\SDP\jdk\jre\lib\security"
    
       cert1.cer, cert2.cer 
    
    2. cacerts is the trusStore file. It's present in :
       C:/Program Files/IBM/SDP/jdk/jre/lib/security/cacerts
    
    3. In command prompt perform the below execution
    C:\Program Files\IBM\SDP\jdk\jre\lib\security>"C:\Program Files\IBM\SDP\jdk\jre\bin\keytool" -import -alias cert1 -file cert1.cer -keystore cacerts
    
    4. If it asks keystore password, mention changeit, which is the default keystore password
    
    Enter keystore password: changeit
    
    Trust this certificate? [no]:  yes
    Certificate was added to keystore
    
    5. Peform the steps 3 and 4 for the second certificate(cert2.cer).
    

    But that was not enough. I had to set javax.net.ssl programatically like this :

    System.setProperty("javax.net.ssl.trustStore", "C:\\Program Files\\IBM\\SDP\\jdk\\jre\\lib\\security\\cacerts");
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    System.setProperty("javax.net.ssl.keyStore", "C:\\Program Files\\IBM\\SDP\\jdk\\jre\\lib\\security\\cacerts");
    System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
    

    The above few lines of code ensure that trustStore and keyStore are set up for the SSL invocation during WS call.

    This was not easy to come by and as such i have provided the explanation and answer here, so that in case some one does have the same problem, then he/she can take it as a reference to mitigate their problem. Cheers!