I tried to find the answer to my question on the user list but could not, so
am posting the question.

I am using Axis Beta 3 release (July 9, 2002). I am trying to write a simple
SOAP message to understand the working of SOAP.
In the following code snippet I try to get the envelope, the body and the
header from the SOAP message and modify them. The body element gets
modified, but the header does not appear in the final message output. I have
also included the message output.
Am I doing something wrong?

--- CODE ---

            MessageFactory msgFactory = MessageFactory.newInstance();
            SOAPMessage msg = msgFactory.createMessage();
            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
            envelope.getHeader().detachNode();
            SOAPHeader header = envelope.addHeader();
            SOAPFactory soapFactory = SOAPFactory.newInstance();
            SOAPElement hdrEl = soapFactory.createElement("myHdr", "cc",
"http://mycompany.com";);
            SOAPElement el = soapFactory.createElement("abc");
            el.addTextNode("123");
            hdrEl.addChildElement(el);
            header.addChildElement(hdrEl);
            envelope.getBody().detachNode();
            SOAPBody body = envelope.addBody();
            SOAPBodyElement bodyElement =
body.addBodyElement(envelope.createName("find_business", "",
                "urn:uddi-org:api"));
            msg.saveChanges();
            msg.writeTo(System.out);
-- CODE ENDS---

-- Message output --

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
 <soapenv:Body>
  <find_business xmlns="urn:uddi-org:api"/>
 </soapenv:Body>
</soapenv:Envelope>

-- Message ends --


Cheers,
Chetan

Reply via email to