Axis2 username/password Authentication
I was calling the username/password authentication enabled web service from axis2 client. To pass the username and password to request header I was looking for solution and found many ways to pass username and password to header like rampart, OMElement using java code:
Below is some code snippet that shows how to pass username and password to service call:
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.impl.dom.SOAPHeaderBlockImpl;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11HeaderBlockImpl;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.types.NonNegativeInteger;
import org.apache.axis2.databinding.types.PositiveInteger;
ServiceClient client = stub._getServiceClient();
SOAP11Factory factory = new SOAP11Factory();
OMNamespace SecurityElementNamespace = factory.createOMNamespace(”http://schemas.xmlsoap.org/ws/2002/04/secext”, “wwlm”);
OMElement usernameTokenEl = factory.createOMElement(”UsernameToken”, SecurityElementNamespace);
OMElement usernameEl = factory.createOMElement(”Username”, SecurityElementNamespace);
OMElement passwordEl = factory.createOMElement(”Password”, SecurityElementNamespace);
usernameEl.setText(”username”);
passwordEl.setText(”password”);
usernameTokenEl.addChild(usernameEl);
usernameTokenEl.addChild(passwordEl);
SOAPHeaderBlockImpl block = new SOAP11HeaderBlockImpl(”Security”, SecurityElementNamespace, factory);
block.addChild(usernameTokenEl);
client.addHeader(block);
I will try to post other way to pass username/password to web service.
Thanks,
~Kumar
Can you send me the code so that i can look.
Thanks,
~Kumar