axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Reinhold" <>
Subject RE: Axis2 deployment: obtain the full SOAP message
Date Thu, 25 Oct 2012 11:15:56 GMT
Thanks Krishantha,

What I need to get is the MessageContext. I have just gotten informed it is available to me
by calling getCurrentMessageContext() in my service. Had no idea!!


-----Original Message-----
From: Krishantha Rathnayake [] 
Sent: Thursday, October 25, 2012 4:29 AM
Subject: RE: Axis2 deployment: obtain the full SOAP message

Hi Brian,

Let's see how to access this SOAP message inside Axis2.

 MessageContext messageContext; // if you are within a handler, reference to the message context
object will be passed to you through Handler.invoke(MessageContext) method.
      SOAPEnvelope soapEnvelope = messageContext.getEnvelope(); Now we have access to the
AXIOM model of the SOAP message. The AXIOM SOAP API provides convenient methods to navigate
inside the SOAP message. The SOAPEnvelope.getBody() and SOAPEnvelope.getHeader() methods give
you access to the SOAP body and the SOAP header of the message respectively. (For more information
on SOAP API of AXIOM, refer to the Axiom article.) Sometimes you might also need to add a
new header or new XML element to the message, especially if you are writing a handler. How
do we do this? You use the AXIOM API to create these XML elements.

      1. OMFactory omFactory = soapEnvelope.getOMFactory();
      2. OMElement newElement = factory.createOMElement("FooElement", null);
      3. soapEnvelope.getBody().addChild(newElement);       
All the OMElements should be created using a factory (as shown in the first line). The reason
is that AXIOM has a couple of different implementations. The basic implementation is based
on a linked list object model. The other model that is used when WS-Security is enabled is
called DOOM. DOOM implements DOM API on top of AXIOM API, providing DOM capabilities on AXIOM.
Since these implementations can be switched within the Axis2 engine, transparent to the user,
we store the factory in which the OMElements are created, within them.

Since we have the choice of two factories to use, we need to know which one to use when we
are trying to add a new element to the existing SOAP message. The easiest way is to ask for
the factory from the SOAP envelope, by which it was created. All the OMElements have a pointer
to the factory they are created, within them. If you do not do this, you may encounter exceptions
when your modified message is traversing through the Axis2 engine.

Then you need to create an OMElement as usual using OM API (line 2). Then add that as a child
to the SOAP body (line 3). If you want to add an element to the SOAP header, the easiest method
is to use the following method inside the SOAP header element. This helper method will take
care of getting the proper factory, creating the OMElement and adding that to the SOAP envelope.

SOAPHeader.addHeaderBlock(String localName, OMNamespace ns)

Regards Krishantha.

-----Original Message-----
From: Brian Reinhold []
Sent: Thursday, October 25, 2012 1:51 PM
Subject: Axis2 deployment: obtain the full SOAP message

To all Axis2 fans,

What is the easiest way to obtain the full SOAP message or the messageContext object in an
Axis2 deployment. Typically all that one gets in one's service is the body of the SOAP message
as an OMElement. I need to get the full message, in particular the SAML token.


To unsubscribe, e-mail:
For additional commands, e-mail:



This e-mail, including any attachments, is confidential and for use only by the intended recipient.
If you are not the intended recipient, please notify us immediately and delete this e-mail
from your system. Any use or disclosure of the information contained herein is strictly prohibited.
As internet communications are not secure, we do not accept legal responsibility for the contents
of this message nor responsibility for any change made to this message after it was sent by
the original sender. We advise you to carry out your own virus check as we cannot accept liability
for damage resulting from software viruses.

 ssi,-i vd-ssi@iac.gF diacmd mljaehpx.aer

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message