How to create a SOAP API request with UsernameToken in JAVA?

1.3k Views Asked by At

My program is running in a server and needs to make a client side call to a SOAP API using Java.

I used SOUPUI to generate a client stub code for the API service WSDL by JAX-WS Artifacts. The API server side requires a UsernameToken. I used the jaxws-ri document example "How do I do basic authentication in JAX-WS ?" as something like below to call the API.

HelloService service = new HelloService();
Hello proxy = (service.getHelloPort());

((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "userfoo");
((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "passbar"); 

Output output = proxy.doAction();
return output.getResult();

But I get below exception in the step of proxy.doAction().

Exception: com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: security.wssecurity.WSSContextImpl.s02: com.ibm.websphere.security.WSSecurityException: Exception org.apache.axis2.AxisFault: CWWSS6500E: There is no caller identity candidate that can be used to login. ocurred while running action: com.ibm.ws.wssecurity.handler.WSSecurityConsumerHandler$1@30ed30ed Please see the server log to find more detail regarding exact cause of the failure.

at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)
at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:125)
at com.sun.xml.ws.client.sei.StubHandler.readResponse(StubHandler.java:253)
at com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:181)
at com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:258)
Truncated. see log file for complete stacktrace

Could you please give me some advice on how to call the API with the UsernameToken? Or is there any server side configuration needed?

1

There are 1 best solutions below

0
On BEST ANSWER

Thanks to the answer from the post JAX-WS Password Type PasswordText. I solved my problem. Also, with reference from the post JAX-WS : SOAP handler in client side.