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).
Definitely it was from lots of Googling and trial-&-error. So common references could be found on web.
Steps:
1.
Generate an authfile by executing command
echo http://myUsername:myPassword@localhost:9001/wservice3/services/AdminWebService?wsdl > wsxauthfile
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.