You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Pani, Gourav" <go...@brightpoint.com> on 2003/12/23 21:55:54 UTC
Assigning values to SOAP Header
hi,
i have generated stub classes using WSDL2Java to create a Client object to
post to a Web Service. however, i need to manipulate the SOAP Header in
order to send Authorization Information before i execute the transaction.
to accomplish that i just created a org.w3c.dom.Element object and tried to
create a SOAPHeaderElement using the MessageElement(org.w3c.dom.Element)
constructor.
however, this gives me a null pointer exception, which is puzzling since the
org.w3c.dom.Element object called securityInformation is not null.
any ideas as to what i might be doing wrong.
tia.
TransactionService serviceLocator = new TransactionServiceLocator();
Transaction transaction = serviceLocator.getFastWebService();
TransactionServiceSoapBindingStub stub =
(TransactionServiceSoapBindingStub) transaction;
DocumentBuilder documentBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element securityInformation = document.createElement("SecurityInfo");
Element authenticationElement =
document.createElement("AuthenticationInfo");
Element authorizationElement =
document.createElement("AuthorizationInfo");
Element fromElement = document.createElement("From");
Element toElement = document.createElement("To");
authenticationElement.setAttribute("userid", "foo");
authenticationElement.setAttribute("password", "bar");
fromElement.setAttribute("domain", "brightpoint.com");
fromElement.setAttribute("system", "BEST");
toElement.setAttribute("domain", "nextel.com");
toElement.setAttribute("system",
"FAST.FASTWebService.InventoryHandler");
authorizationElement.appendChild(fromElement);
authorizationElement.appendChild(toElement);
securityInformation.appendChild(authenticationElement);
securityInformation.appendChild(authorizationElement);
SOAPHeaderElement securityInfo = new
SOAPHeaderElement(securityInformation);
stub.setHeader(securityInfo);
SenderObject senderObject = new SenderObject();
stub.updateInventory("Bad Santa", senderObject);