As discussed in my earlier post Consuming web services with Spring, web service client initialization might fail due to non-availability of the running web service. We can overcome this limiting factor by packaging the WSDL with client and using that for creating the instance of client stub and during service method invocation use the live URL of the service. Have a look at Packaging dynamic resources with Maven to know more about packaging. The following code snippet shows how to use locally packaged WSDL and live service URL-
// during instantiation use the locally packaged WSDL WebServiceClient ann = AddressService.class.getAnnotation(WebServiceClient.class); URL wsdlURL = this.getClass().getResource("/wsdl/AddressService.wsdl"); AddressService serviceObj = new AddressService(wsdlURL, new QName(ann.targetNamespace(), ann.name())); Address service = serviceObj.getAddressPort(); BindingProvider bp = ((BindingProvider) service); Map<String, Object> context = bp.getRequestContext(); // set the live URL of the service, which will be used during service method invocations context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "LIVE URL OF THE WEB SERVICE");
5 Comments:
I am trying this, but It keeps returning null wsdlURL. My webservice client is a part of a web application. I am calling the client from a servlet.
I have a question:
this.getClass().getResource("/wsdl/AddressService.wsdl");
The location I am passing to getResource is the location of the wsdl file in .war file. But It keeps returning null URL. Am I doing it wrong?
getResource("") method returns null as it can't find the resource at the given location. You need to find the correct path of the resource.
I got it working. I was not packaging it under classes which is why it couldn't find.
Hi vinod,
I tried this way to access the local wsdl. i get different error, details are as follows:
javax.xml.ws.WebServiceException: org.apache.axis2.AxisFault: Address information does not exist in the Endpoint Reference (EPR).The system cannot infer the transport mechanism. >>>
Can you give some idea why i m getting this error
Thank you foor sharing this
Post a Comment