Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 787
The Dark Knight Avatar asked Sep 06 '13 09:09

The Dark Knight


People also ask

Is JAX-WS part of JDK?

When using Eclipse, I'm able to use JAX-WS annotations (e.g. @WebService ) without including any external dependencies, but I can't do the same for JAX-RS annotations (e.g. @Path ). I took a look at this answer and I understand that javax.ws.rs is not a part of the JDK.


3 Answers

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!

like image 157
The Dark Knight Avatar answered Oct 04 '22 07:10

The Dark Knight


Put the below line as the very first line in your program. That will solve the issue. System.setProperty("com.ibm.SSL.ConfigURL", "file:C:\IBM\WebSphere\AppServer\profiles\AppSrv01\properties\ssl.client.props");

like image 23
Prasanna Bandaru Avatar answered Oct 04 '22 08:10

Prasanna Bandaru


Have you tried setting end point address to your webservice address. In my case, I had the jar generated from WSDL file with the client code.

One example in my test case is

public static void main(String[] args){
          SecurityRefServiceLocator securityRefServiceLocator = new SecurityRefServiceLocator();
            securityRefServiceLocator.setSecurityrefPortEndpointAddress("http://xxxxx:13600/my_ss/webservice/refreshSecurity?wsdl");
            WebserviceClient webserviceClient = new WebserviceClient();
            webserviceClient.setSecurityRefServiceLocator(securityRefServiceLocator);
            System.out.println(webserviceClient.refreshSecurity(8798789l,"1114"));

}

}

WeberviceClient code

public WebServiceReturnCode refreshSecurity(Long securityId, String productId) {

    try{
        SecurityRef securityRef = securityRefServiceLocator.getSecurityrefPort();

        SecurityServiceBindingStub  securityServiceBindingStub=
            (SecurityServiceBindingStub) securityRef;

        securityServiceBindingStub.setUsername("user");
        securityServiceBindingStub.setPassword("password");

        securityServiceBindingStub.setTimeout(timeout);

        SecurityServiceRequest parameter = new SecurityServiceRequest();

        parameter.setMessageId("MSG-" + securityId);
        parameter.setSecurityId(securityId.toString());
        SecurityServiceResponse refreshSecurity = securityRef.refreshSecurity(parameter);
        ResponseType msgResponse = refreshSecurity.getMsgResponse();
        //evaluate msg response and send E200; if fail
        if(msgResponse.equals(ResponseType.SUCCESS)){
            return WebServiceReturnCode.SUCCESS;
        }
        // Response was not favorable
        return "WSE200";

    }catch(Exception e){
        // Exception occurred. Mark this as technical failure to webservice call.
        return "WSE100";
    }finally{
}
}

public SecurityRefServiceLocator getSecurityRefServiceLocator() {
    return securityRefServiceLocator;
}

public void setSecurityRefServiceLocator(
        SecurityRefServiceLocator securityRefServiceLocator) {
    this.securityRefServiceLocator = securityRefServiceLocator;
}
like image 40
Gyanendra Dwivedi Avatar answered Oct 04 '22 08:10

Gyanendra Dwivedi