You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Andy Jefferies <aj...@vrisko.com> on 2001/09/20 18:31:03 UTC

Setting NameSpaces in Header

I'm clearly doing something wrong here as my namespaces are not being set.
I'm trying to invoke a SOAP-RPC with a header like:

 <SOAP-ENV:Header xmlns:m="http://myurl">
  <m:authToken SOAP-ENV:mustUnderstand="1">ABCDEF</m:authToken>
 </SOAP-ENV:Header>

but...my code produces a header like:

 <SOAP-ENV:Header xmlns:m="http://myurl">
  <authToken mustUnderstand="1">ABCDEF</authToken>
 </SOAP-ENV:Header>

The authToken element and mustUnderstand attribute both fail to set their
namespaces.

My code looks like:

 // create a non-validating, namespace aware doc-builder
 DocumentBuilder db =
org.apache.soap.util.xml.XMLParserUtils.getXMLDocBuilder();
 Document doc = db.newDocument();

 // create header, declare namespace, add element to entries
 Header header = new Header();
 header.declareNamespace("m", MY_URI);
 Element authToken = doc.createElementNS(MY_URI, "authToken");
 authToken.setAttributeNS(Constants.NS_URI_SOAP_ENV, "mustUnderstand", "1");
 authToken.appendChild(doc.createTextNode("ABCDEF"));
 Vector entries = new Vector();
 entries.addElement(authToken);

 // set the entries and header
 header.setHeaderEntries(entries);
 call.setHeader(header);

I'm using: SOAP-2.2, Xerces 1.4.3, Java 1.3.1

Also, is there a way to set the namespace in the SOAP-ENV:Envelope element
so that it doesn't need to be set in the SOAP-ENV:Header and SOAP-ENV:Body
elements seperately, or is there no advantage to this?

Thanks in advance,
Andy.