ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gene...@ws.apache.org
Subject [Apache Web Services Wiki] New: FrontPage/Axis/WSDLJavaHeaderServer
Date Wed, 12 Jan 2005 03:23:57 GMT
   Date: 2005-01-11T19:23:57
   Editor: ToshiyukiKimura
   Wiki: Apache Web Services Wiki
   Page: FrontPage/Axis/WSDLJavaHeaderServer
   URL: http://wiki.apache.org/ws/FrontPage/Axis/WSDLJavaHeaderServer

   Importing old wiki ...

New Page:

##language:en
'''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);
}}}

Mime
View raw message