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

3

5

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.

Christiano answered 6/9, 2013 at 9:20 Comment(3)
possible duplicate of How to make 'simple SSL' thru Web Services?Prehensile
@PaulVargas : Don't think it is a duplicate. I understand it's a certificate problem. But the real question is how to get around it? Is a workaround possible here ? If so, how can i do it ? Or do i need the certificate from the wsdl service hoster to make it work ?Christiano
You need to configure SSL only if you want to call server over HTTPS. If you don't want the secure connection you can change the address to HTTP one.Decarbonize
C
4

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!

Christiano answered 11/9, 2013 at 8:42 Comment(1)
Why do the trustStore and keyStore need to be explicitly set if you are using the same JRE which has the certificates trusted in cacerts?Woolcott
E
4

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");

Enzymology answered 6/4, 2016 at 18:37 Comment(0)
C
1

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;
}
Conjunctive answered 10/9, 2013 at 11:48 Comment(3)
Yes I have already tried doing that using this piece of code : bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://mklip.verd.Gin/WS/v2.8?wsdl"); . That does not work and gives the same exception .Christiano
Could you please try doing my way....generate a client code from wsdl. Please take the WSDL file generated from URL. And then try to test it. The only difference I see here is that your URL is having SSL, while in my case its is not a secure URL. May be that requires a different approach, I would do a parallel research on this.Conjunctive
Taking the WSDL file from the endpoint url is not a great idea. Some times the wsdl that you get from such a url gives you an underdeveloped wsdl without proper xsd references(like in my case, i was not even able to generate clients using that wsdl, as it gave me several wsdl parsing errors , since it did not have proper xsd references) . So i used the old wsdl and used the answer that i posted above to solve the SSL config issue.Christiano

© 2022 - 2024 — McMap. All rights reserved.