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 Ricky Ho <ri...@cisco.com> on 2003/01/18 02:55:29 UTC

How to add a SOAP header into a SOAP envelope ??

I try to add a SOAP header into a SOAP envelope.

1) SOAPEnvelope soapEnv = .... ;
2) System.out.println("SoapEnv is ..\n" + soapEnv);
3) SOAPHeaderElement hdrElement = new SOAPHeaderElement(new 
PrefixedQName("myNamespace","someHeader", "prefix"));
4) soapEnv.addHeader(hdrElement);
5) System.out.println("SoapEnv is ..\n" + soapEnv);

At line 2, I get ...

SoapEnv is ..
<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>
   <ns1:getTemp 
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:ns1="urn:xmethods-Temperature">
    <zipcode xsi:type="xsd:string">95135</zipcode>
   </ns1:getTemp>
  </soapenv:Body>
</soapenv:Envelope>

But I get an Exception after line 4

Exception:
java.lang.NullPointerException
         at org.apache.axis.message.SOAPHeader.outputImpl(SOAPHeader.java:330)
         at 
org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:395)
         at 
org.apache.axis.message.MessageElement.output(MessageElement.java:754)
         at 
org.apache.axis.message.MessageElement.getAsString(MessageElement.java:677)
         at 
org.apache.axis.message.MessageElement.toString(MessageElement.java:805)
         at java.lang.String.valueOf(String.java:2146)
         at java.lang.StringBuffer.append(StringBuffer.java:372)
         at myMethod

At line 5, I get the following

SoapEnv is ..
null

What have I done wrong ??

Rgds, Ricky