View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.soap.axis.extras;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.config.MuleProperties;
12  import org.mule.api.transport.PropertyScope;
13  import org.mule.module.cxf.SoapConstants;
14  import org.mule.transport.http.HttpConnector;
15  import org.mule.transport.http.HttpConstants;
16  import org.mule.transport.soap.axis.AxisConnector;
17  import org.mule.util.StringUtils;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  public class AxisCleanAndAddProperties
23  {
24      
25      // add all custom headers, filter out all mule headers (such as
26      // MULE_SESSION) except
27      // for MULE_USER header. Filter out other headers like "soapMethods" and
28      // MuleProperties.MULE_METHOD_PROPERTY and "soapAction"
29      // and also filter out any http related header
30      
31      public static Map<String, Object> cleanAndAdd(MuleEventContext muleEventContext){
32          
33          Map<String, Object> props = new HashMap<String, Object>();
34          MuleMessage currentMessage = muleEventContext.getMessage();
35  
36          populateProps(props, currentMessage, PropertyScope.INVOCATION);
37          populateProps(props, currentMessage, PropertyScope.OUTBOUND);
38          return props;
39      }
40  
41      protected static void populateProps(Map<String, Object> props, MuleMessage currentMessage, PropertyScope scope)
42      {
43          for (String name : currentMessage.getPropertyNames(scope))
44          {
45              if (!StringUtils.equals(name, AxisConnector.SOAP_METHODS)
46                  && !StringUtils.equals(name, SoapConstants.SOAP_ACTION_PROPERTY)
47                  && !StringUtils.equals(name, MuleProperties.MULE_METHOD_PROPERTY)
48                  && (!name.startsWith(MuleProperties.PROPERTY_PREFIX) || StringUtils.equals(name,
49                      MuleProperties.MULE_USER_PROPERTY))
50                  && !HttpConstants.ALL_HEADER_NAMES.containsValue(name)
51                  && !StringUtils.equals(name, HttpConnector.HTTP_STATUS_PROPERTY))
52              {
53                  props.put(name, currentMessage.getProperty(name, scope));
54              }
55          }
56      }
57  }