Differences between revisions 1 and 2
Revision 1 as of 2005-01-12 03:23:56
Size: 1275
Comment: Importing old wiki ...
Revision 2 as of 2009-09-20 22:48:26
Size: 1275
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Q: How do a get/set headers in my web service code?

A: You use the  MessageContext object .

Here is some example code

   // Get current message context
   MessageContext ctx = org.apache.axis.MessageContext.getCurrentContext();

   // Get SOAP envelope of request
   SOAPEnvelope env = ctx.getRequestMessage().getSOAPEnvelope();

   // Get Header
   SOAPHeaderElement soapHeaderElement = env.getHeaderByName(headerNamespace, headerName);

   // Get value of header, could be a complex type!
   Object value = soapHeaderElement.getObjectValue();

Q: How do I set a header in the response to the client?

A: Create a  SOAPHeaderElement  and add it to the  SOAPEnvelope  of the response message.

  // Get current message context
  MessageContext ctx = org.apache.axis.MessageContext.getCurrentContext();

  // Get SOAP envelope of response
  SOAPEnvelope env = ctx.getResponseMessage().getSOAPEnvelope();

  // Create SOAP header object } } } 
  SOAPHeaderElement headerElement =
    new org.apache.axis.message.SOAPHeaderElement(headerNamespace, headerName, headerValue);
  headerElement.setMustUnderstand(mustUnderstand);

  // Set Header
  env.addHeader(headerElement);

FrontPage/Axis/WSDLJavaHeaderServer (last edited 2009-09-20 22:48:26 by localhost)