View Javadoc

1   /*
2    * $Id: AxisCleanAndAddProperties.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.soap.axis.extras;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.config.MuleProperties;
16  import org.mule.api.transport.PropertyScope;
17  import org.mule.module.cxf.SoapConstants;
18  import org.mule.transport.http.HttpConnector;
19  import org.mule.transport.http.HttpConstants;
20  import org.mule.transport.soap.axis.AxisConnector;
21  import org.mule.util.StringUtils;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  public class AxisCleanAndAddProperties
27  {
28      
29      // add all custom headers, filter out all mule headers (such as
30      // MULE_SESSION) except
31      // for MULE_USER header. Filter out other headers like "soapMethods" and
32      // MuleProperties.MULE_METHOD_PROPERTY and "soapAction"
33      // and also filter out any http related header
34      
35      public static Map<String, Object> cleanAndAdd(MuleEventContext muleEventContext){
36          
37          Map<String, Object> props = new HashMap<String, Object>();
38          MuleMessage currentMessage = muleEventContext.getMessage();
39  
40          populateProps(props, currentMessage, PropertyScope.INVOCATION);
41          populateProps(props, currentMessage, PropertyScope.OUTBOUND);
42          return props;
43      }
44  
45      protected static void populateProps(Map<String, Object> props, MuleMessage currentMessage, PropertyScope scope)
46      {
47          for (String name : currentMessage.getPropertyNames(scope))
48          {
49              if (!StringUtils.equals(name, AxisConnector.SOAP_METHODS)
50                  && !StringUtils.equals(name, SoapConstants.SOAP_ACTION_PROPERTY)
51                  && !StringUtils.equals(name, MuleProperties.MULE_METHOD_PROPERTY)
52                  && (!name.startsWith(MuleProperties.PROPERTY_PREFIX) || StringUtils.equals(name,
53                      MuleProperties.MULE_USER_PROPERTY))
54                  && !HttpConstants.ALL_HEADER_NAMES.containsValue(name)
55                  && !StringUtils.equals(name, HttpConnector.HTTP_STATUS_PROPERTY))
56              {
57                  props.put(name, currentMessage.getProperty(name, scope));
58              }
59          }
60      }
61  }