View Javadoc

1   /*
2    * $Id: MuleHeadersInHandler.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.soap.xfire;
12  
13  import org.mule.config.MuleProperties;
14  import org.mule.providers.soap.MuleSoapHeaders;
15  
16  import org.codehaus.xfire.MessageContext;
17  import org.codehaus.xfire.handler.AbstractHandler;
18  import org.jdom.Element;
19  import org.jdom.Namespace;
20  
21  /**
22   * Reads the Mule Soap Header and sets the various header properties on the context.
23   */
24  public class MuleHeadersInHandler extends AbstractHandler
25  {
26      protected final Namespace ns = Namespace.getNamespace(MuleSoapHeaders.MULE_NAMESPACE,
27          MuleSoapHeaders.MULE_10_ACTOR);
28  
29      /**
30       * Invoke a handler. If a fault occurs it will be handled via the
31       * <code>handleFault</code> method.
32       * 
33       * @param context The message context.
34       */
35      public void invoke(MessageContext context) throws Exception
36      {
37          if (context.getInMessage() != null)
38          {
39              Element header = context.getInMessage().getHeader();
40              if (header == null)
41              {
42                  return;
43              }
44  
45              Element muleHeaders = header.getChild(MuleSoapHeaders.MULE_HEADER, ns);
46              if (muleHeaders != null)
47              {
48                  Element child = muleHeaders.getChild(MuleProperties.MULE_CORRELATION_ID_PROPERTY, ns);
49                  if (child != null)
50                  {
51                      context.setProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY, child.getText());
52                  }
53                  child = muleHeaders.getChild(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, ns);
54                  if (child != null)
55                  {
56                      context.setProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, child.getText());
57                  }
58                  child = muleHeaders.getChild(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, ns);
59                  if (child != null)
60                  {
61                      context.setProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, child.getText());
62                  }
63                  child = muleHeaders.getChild(MuleProperties.MULE_REPLY_TO_PROPERTY, ns);
64                  if (child != null)
65                  {
66                      context.setProperty(MuleProperties.MULE_REPLY_TO_PROPERTY, child.getText());
67                  }
68              }
69          }
70      }
71  
72  }