Accessing WS-Addressing Headers inside a Mediation Flow

In many respects, WebSphere ESB mediation modules act as an ‘ultimate endpoint’, which means WS-Addressing (WS-A) headers are normally stripped off on entry to the mediation flow, and so you cannot access them directly in the SOAPHeader section of the SMO. This technote describes the problem and the potential solution: writing a JAX-RPC handler to access the headers. However, it doesn’t go into detail on how this could be implemented. So here’s how you’d implement a simple JAX-RPC handler to extract the WS-A ‘To’ address on an incoming message so you can use it in your mediation flow:

  1. Define a business object that can be used as a pseudo-WS-A SOAP header to contain whatever WS-A content you care about on the incoming message. In our case, we are just interested in the ‘To’ header:

    You must make sure that this BO is available to the mediation module in question at runtime, by placing it in the module itself or a library that it depends on. If you don’t do this, the header will silently fail to appear.
  2. Write a JAX-RPC handler (which is a Java class) to pull out the content of the incoming SOAP header and place it in a new SOAP header of that Business Object’s type. You need to place it somewhere accessible to mediation module in question. It might look something like this:
    import javax.xml.namespace.*;
    import javax.xml.rpc.handler.*;
    import javax.xml.rpc.handler.soap.*;
    import javax.xml.soap.*;
    public class WSAHandler extends GenericHandler {
      public boolean handleRequest(MessageContext context) {
        Object object = context
        String to = (object == null ? "" : object.toString());
        SOAPMessageContext soapMessageContext = (SOAPMessageContext) context;
        try {
          SOAPEnvelope soapEnvelope = soapMessageContext
          SOAPHeader soapHeader = soapEnvelope.getHeader();
          SOAPHeaderElement myBO = (SOAPHeaderElement) soapHeader
              .addChildElement("PseudoWSAHeader", "pwsahn",
          SOAPElement seTo = (SOAPElement) myBO
        } catch (SOAPException e) {
        return true;
      public QName[] getHeaders() {
        return null;

    The name and namespace of the business object used when creating the new SOAPHeaderElement need to match the name and namespace of the business object you created. Also, be aware that the class in the* hierarchy is part of the WebSphere SPI (System Programming Interface); it is not a fully public API and may not be subject to the same terms (please check your license agreement).

  3. Configure the JAX-RPC handler you just wrote on the Web Services export in question:
  4. Now, when you invoke the Web Services export with a message containing a WS-A ‘To’ header, the pseudo-header will appear in the relevant location in the SMO, and you can access it and use it in whatever way you need, perhaps using an XSLT primitive or a custom mediation, for example. Here’s an example of what the SMO looks like when dumped out in the middle of the mediation flow. The value of the WS-A To header is highlighted:
    <p:ServiceMessageObject xsi:type="p:ServiceMessageObject" xmlns:xsi="" xmlns:in="wsdl.http://WSADemo/MyInterface" xmlns:in_1="http://WSADemo/MyInterface" xmlns:ps="http://pseudoWSAHeaderNamespace" xmlns:p="">
          <value xsi:type="ps:PseudoWSAHeader">
      <body xsi:type="in:operation1RequestMsg">
          <input1>Some regular message data</input1>

Thanks to Chris Markes, Rob Phippen, and David Illsley for the help with this tip.


6 Responses to Accessing WS-Addressing Headers inside a Mediation Flow

  1. Pingback: WS-Addressing Headers in WebSphere ESB v6.2 « SOA Tips ‘n’ Tricks

  2. rohit reddy says:

    Hi Andrew.

    I have a use case in which the endpoints (i.e, imports to ESB app) are secured using saml token.

    I wrote a JAX RPC handler for the ESB (export has web service bindings) to intercept the soap message and add the SAML token to it.
    Now to get the saml token from the STS, i need the end point to which ESB will direct the soap message. Is it possible to get the Endpoint URL in the handler?

    I have tried using Object object = context.getProperty(;
    but i’m getting NULL value for this.

    Can you help me in this regard.


  3. @Rohit, you might find this posting relevant:

    It talks about JAX-WS handlers rather than JAX-RPC, but maybe it would be applicable?

  4. rohit reddy says:

    Thanks Andrew, Will go through it

  5. Sadhana says:

    Hi Andrew –

    Do we need to write a handler to receive these WS-A headers on a SOAP/JMS Inbound Export as well ? or can we do it with just configuration ? I am on version 7.0

  6. I believe what you said was actually very logical. However, what about this?
    suppose you typed a catchier post title? I ain’t suggesting
    your content is not good., however suppose you added a headline
    to possibly grab people’s attention? I mean Accessing WS-Addressing Headers inside a Mediation Flow | SOA Tips ‘n’ Tricks is a little boring.
    You could glance at Yahoo’s home page and note how they
    create post titles to grab viewers interested. You might add a related video or a
    pic or two to get people interested about what you’ve got to say.
    Just my opinion, it could bring your posts a little livelier.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: