Pages

Wednesday, December 17, 2014

Generating SOAP Client using JAX-WS

This post describes, how to generate SOAP Client using JAX-WS and perform basic authentication of username and password. It uses JDK(Java Development Kit)'s wsimport command to generate SOAP client, using the WSDL(Web Service Definition Language).



Steps:

1.       Generate an authfile by executing command







2.       \bin>wsimport –keep –verbose –Xauthfile -d

3.       Code ->

a.       Create the instance of _Service (serviceImpl) class.

b.      Get the service instance :

tempService = serviceImpl.get_xxxxPort();

c.       Add the credentials if the service requires authentication:
BindingProvider prov = (BindingProvider) tempService;
Map requestContext = prov.getRequestContext();

requestContext .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ); 

requestContext.put(BindingProvider.USERNAME_PROPERTY, );
requestContext.put(BindingProvider.PASSWORD_PROPERTY, );

d.      Hit the operation using tempService:
                  Response tempResponse = tempService.operation1(param1,param2);


Definitely it was from lots of Googling and trial-&-error. So common references could be found on web.