You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by in...@apache.org on 2007/03/07 06:06:59 UTC

svn commit: r515458 - in /webservices/synapse/trunk/java/modules/core/src: main/java/org/apache/synapse/config/xml/ main/java/org/apache/synapse/config/xml/endpoints/ main/java/org/apache/synapse/core/axis2/ main/java/org/apache/synapse/mediators/ main...

Author: indika
Date: Tue Mar  6 21:06:57 2007
New Revision: 515458

URL: http://svn.apache.org/viewvc?view=rev&rev=515458
Log:
fixed some minor issues 
Change property mediator so that It can remove or set properties 

Added:
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/PropertyMediatorSerializationTest.java
Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EndpointDefinitionFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointAbstractFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/IndirectEndpointFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/PropertyMediatorTest.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EndpointDefinitionFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EndpointDefinitionFactory.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EndpointDefinitionFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EndpointDefinitionFactory.java Tue Mar  6 21:06:57 2007
@@ -90,7 +90,7 @@
             }
         } else {
 			OMAttribute reference = elem.getAttribute(new QName(
-					Constants.NULL_NAMESPACE, "ref"));
+					Constants.NULL_NAMESPACE, "key"));
 			if (reference != null) {
 				endpoint.setRef(reference.getAttributeValue());
 			} else if (address != null) {

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java Tue Mar  6 21:06:57 2007
@@ -32,17 +32,17 @@
 import org.jaxen.JaxenException;
 
 /**
- * Creates a set-property mediator through the supplied XML configuration
- *
+ * Creates a property mediator through the supplied XML configuration
+ * <p/>
  * <pre>
- * &lt;set-property name="string" (value="literal" | expression="xpath")/&gt;
+ * &lt;property name="string" [action=set] (value="literal" | expression="xpath")/&gt;
  * </pre>
  */
-public class PropertyMediatorFactory extends AbstractMediatorFactory  {
+public class PropertyMediatorFactory extends AbstractMediatorFactory {
 
     private static final Log log = LogFactory.getLog(LogMediatorFactory.class);
 
-    private static final QName PROP_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "set-property");
+    private static final QName PROP_Q = new QName(Constants.SYNAPSE_NAMESPACE, "property");
 
     public Mediator createMediator(OMElement elem) {
 
@@ -51,21 +51,20 @@
         OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
         OMAttribute expression = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "expression"));
         OMAttribute scope = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "scope"));
-
+        OMAttribute action = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "action"));
         if (name == null) {
             String msg = "The 'name' attribute is required for the configuration of a property mediator";
             log.error(msg);
             throw new SynapseException(msg);
-        } else if (value == null && expression == null) {
-            String msg = "Either an 'value' or 'expression' attribute is required for a property mediator";
+        } else if ((value == null && expression == null) && !(action != null && "remove".equals(action.getAttributeValue()))) {
+            String msg = "Either an 'value' or 'expression' attribute is required for a property mediator when action is SET";
             log.error(msg);
             throw new SynapseException(msg);
         }
-
         propMediator.setName(name.getAttributeValue());
         if (value != null) {
             propMediator.setValue(value.getAttributeValue());
-        } else {
+        } else if (expression != null) {
             try {
                 AXIOMXPath xp = new AXIOMXPath(expression.getAttributeValue());
                 OMElementUtils.addNameSpaces(xp, elem, log);
@@ -77,22 +76,26 @@
                 throw new SynapseException(msg);
             }
         }
-
         if (scope != null) {
             String valueStr = scope.getAttributeValue();
-            if (!Constants.SCOPE_AXIS2.equals(valueStr) && !Constants.SCOPE_TRANSPORT.equals(valueStr)) {
-        		String msg = "Only '" + Constants.SCOPE_AXIS2 + "' or '" + Constants.SCOPE_TRANSPORT
+            if (!Constants.SCOPE_AXIS2.equals(valueStr) && !Constants.SCOPE_TRANSPORT.equals(valueStr))
+            {
+                String msg = "Only '" + Constants.SCOPE_AXIS2 + "' or '" + Constants.SCOPE_TRANSPORT
                         + "' values are allowed for attribute scope for a property mediator"
                         + ", Unsupported scope " + scope.getAttributeValue();
                 log.error(msg);
                 throw new SynapseException(msg);
-        	}
+            }
             propMediator.setScope(valueStr);
         }
         // after successfully creating the mediator
         // set its common attributes such as tracing etc
-        initMediator(propMediator,elem);
-
+        initMediator(propMediator, elem);
+        // The action attribute is optional, if provided and equals to 'remove' the
+        // property mediator will act as a property remove mediator
+        if (action != null && "remove".equals(action.getAttributeValue())) {
+            propMediator.setAction(PropertyMediator.ACTION_REMOVE);
+        }
         return propMediator;
     }
 

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorSerializer.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorSerializer.java Tue Mar  6 21:06:57 2007
@@ -28,11 +28,10 @@
 
 /**
  * <pre>
- * &lt;set-property name="string" (value="literal" | expression="xpath")/&gt;
+ * &lt;property name="string" [action=set] (value="literal" | expression="xpath")/&gt;
  * </pre>
  */
-public class PropertyMediatorSerializer extends AbstractMediatorSerializer
-     {
+public class PropertyMediatorSerializer extends AbstractMediatorSerializer {
 
     private static final Log log = LogFactory.getLog(PropertyMediatorSerializer.class);
 
@@ -43,34 +42,36 @@
         }
 
         PropertyMediator mediator = (PropertyMediator) m;
-        OMElement property = fac.createOMElement("set-property", synNS);
-        finalizeSerialization(property,mediator);
+        OMElement property = fac.createOMElement("property", synNS);
+        finalizeSerialization(property, mediator);
 
         if (mediator.getName() != null) {
             property.addAttribute(fac.createOMAttribute(
-                "name", nullNS, mediator.getName()));
+                    "name", nullNS, mediator.getName()));
         } else {
             handleException("Invalid property mediator. Name is required");
         }
 
         if (mediator.getValue() != null) {
             property.addAttribute(fac.createOMAttribute(
-                "value", nullNS, mediator.getValue()));
+                    "value", nullNS, mediator.getValue()));
 
         } else if (mediator.getExpression() != null) {
             property.addAttribute(fac.createOMAttribute(
-                "expression", nullNS, mediator.getExpression().toString()));
+                    "expression", nullNS, mediator.getExpression().toString()));
             super.serializeNamespaces(property, mediator.getExpression());
 
-        } else {
-            handleException("Invalid property mediator. Value or expression is required");
+        } else if (mediator.getAction() == PropertyMediator.ACTION_SET) {
+            handleException("Invalid property mediator. Value or expression is required if action is SET");
         }
-        
         if (mediator.getScope() != null) {
             // if we have already built a mediator with scope, scope should be valid, now save it
             property.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
         }
-
+        if (mediator.getAction() == PropertyMediator.ACTION_REMOVE) {
+            property.addAttribute(fac.createOMAttribute(
+                    "action", nullNS, "remove"));
+        }
         if (parent != null) {
             parent.addChild(property);
         }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java Tue Mar  6 21:06:57 2007
@@ -21,6 +21,7 @@
 import org.apache.commons.logging.LogFactory;
 
 import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 
 /**
  * A SwitchCase define a case element of Switch Mediator and It has a list mediator and
@@ -96,7 +97,11 @@
      * @return boolean value
      */
     public boolean matches(String value) {
-        boolean retVal = regex.matcher(value).matches();
+        Matcher matcher = regex.matcher(value);
+        if(matcher == null){
+            return false;
+        }
+        boolean retVal = matcher.matches();
         log.debug("Case : " + regex.pattern() + " evaluated to : " + retVal);
         return retVal;
     }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java Tue Mar  6 21:06:57 2007
@@ -147,7 +147,7 @@
 
     public static void defineEndpoint(SynapseConfiguration config, OMElement ele) {
 
-        String name = ele.getAttributeValue(new QName(Constants.NULL_NAMESPACE, "nane"));
+        String name = ele.getAttributeValue(new QName(Constants.NULL_NAMESPACE, "name"));
         if (name != null) {
             if (config.getLocalRegistry().get(name) != null) {
                 handleException("Duplicate endpoint definition : " + name);

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java Tue Mar  6 21:06:57 2007
@@ -88,7 +88,7 @@
         OMAttribute optimize = elem.getAttribute(new QName(
                 org.apache.synapse.config.xml.Constants.NULL_NAMESPACE, "optimize"));
         OMAttribute reference = elem.getAttribute(new QName(
-                org.apache.synapse.config.xml.Constants.NULL_NAMESPACE, "ref"));
+                org.apache.synapse.config.xml.Constants.NULL_NAMESPACE, "key"));
 
         EndpointDefinition endpoint = new EndpointDefinition();
 

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointAbstractFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointAbstractFactory.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointAbstractFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointAbstractFactory.java Tue Mar  6 21:06:57 2007
@@ -28,7 +28,7 @@
 
     public static EndpointFactory getEndpointFactroy(OMElement configElement) {
 
-        if (configElement.getAttribute(new QName("ref")) != null) {
+        if (configElement.getAttribute(new QName("key")) != null) {
             IndirectEndpointFactory endpointFactory = IndirectEndpointFactory.getInstance();
             return endpointFactory;
         }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/IndirectEndpointFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/IndirectEndpointFactory.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/IndirectEndpointFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/IndirectEndpointFactory.java Tue Mar  6 21:06:57 2007
@@ -44,7 +44,7 @@
     public Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint) {
 
         IndirectEndpoint indirectEndpoint = new IndirectEndpoint();
-        String ref = epConfig.getAttributeValue(new QName("ref"));
+        String ref = epConfig.getAttributeValue(new QName("key"));
         indirectEndpoint.setRef(ref);
         return indirectEndpoint;
     }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java Tue Mar  6 21:06:57 2007
@@ -349,11 +349,17 @@
             }
             try {
                 Object result = xpath.evaluate(synCtx.getEnvelope());
+                if (result == null) {
+                    return null;
+                }
                 StringBuffer textValue = new StringBuffer();
                 if (result instanceof List) {
                     Iterator iter = ((List) result).iterator();
                     while (iter.hasNext()) {
                         Object o = iter.next();
+                        if (o == null) {
+                            return null;
+                        }
                         if (o instanceof OMTextImpl) {
                             textValue.append(((OMTextImpl) o).getText());
                         } else if (o instanceof OMElementImpl) {

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java Tue Mar  6 21:06:57 2007
@@ -41,6 +41,7 @@
 
     private static final Log log = LogFactory.getLog(GetPropertyFunction.class);
 
+    /** Synapse Message context*/
     private MessageContext synCtx = null;
 
     public MessageContext getSynCtx() {
@@ -51,6 +52,15 @@
         this.synCtx = synCtx;
     }
 
+    /**
+     * Returns the string value of the property which is get from the corresponding context to the provided scope .
+     * The default scope is used to get property from the synapse message context
+     *
+     * @param context
+     * @param args
+     * @return The string value of a property
+     * @throws FunctionCallException
+     */
     public Object call(Context context, List args) throws FunctionCallException {
 
         int size = args.size();
@@ -69,6 +79,14 @@
         }
     }
 
+    /**
+     * Returns the string value of the property using arg. one as key and arg. two as scope
+     *
+     * @param scopeObject
+     * @param keyObject
+     * @param navigator
+     * @return The String value of property using arg. one as key and arg. two as scope
+     */
     public Object evaluate(Object scopeObject, Object keyObject, Navigator navigator) {
         if (synCtx == null) {
             log.warn("Synapse context has not been set for the XPath extension function" +
@@ -80,7 +98,8 @@
         String key = StringFunction.evaluate(keyObject, navigator);
 
         if (key == null || "".equals(key)) {
-            log.warn("property-name should be provided when executing synapse:get-property(scope,prop-name)" +
+            log.warn("property-name should be provided when executing " +
+                    "synapse:get-property(scope,prop-name)" +
                     " or synapse:get-property(prop-name) Xpath function");
             return null;
         }
@@ -111,13 +130,15 @@
         if (Constants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) {
             org.apache.axis2.context.MessageContext axis2MessageContext
                     = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
-            Object headers = axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
+            Object headers = axis2MessageContext.getProperty(
+                    org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
             if (headers != null && headers instanceof Map) {
                 Map headersMap = (HashMap) headers;
                 return headersMap.get(key);
             }
         } else {
-            log.warn("Invalid scope : '" + scope + "' has been set for the synapse:get-property(scope,prop-name) XPath function");
+            log.warn("Invalid scope : '" + scope + "' has been set for the " +
+                    "synapse:get-property(scope,prop-name) XPath function");
         }
         return null;
     }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java Tue Mar  6 21:06:57 2007
@@ -27,27 +27,38 @@
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.synapse.mediators.AbstractMediator;
-
 import java.util.Map;
 import java.util.HashMap;
+import java.util.Set;
 
 /**
- * The property mediator would save a named property as a local property
- * of the Synapse Message Context. Properties set this way could be
- * extracted through the XPath extension function "synapse:get-property(prop-name)"
+ * The property mediator would save(or remove) a named property as a local property of the Synapse Message Context
+ * or as a property of the Axis2 Configuration Context or as a Transport Header.
+ * Properties set this way could be extracted through the XPath extension function "synapse:get-property(scope,prop-name)"
  */
+
 public class PropertyMediator extends AbstractMediator {
 
+    /** The Name of the property  */
     private String name = null;
+    /** The Value to be set*/
     private String value = null;
+    /** The XPath expr. to get value  */
     private AXIOMXPath expression = null;
+    /** The scope for which decide properties where to go*/
     private String scope = null;
-
+    /** The Action - set or remove */
+    public static final int ACTION_SET = 0;
+    public static final int ACTION_REMOVE = 1;
+    /** Set the property (ACTION_SET) or remove it (ACTION_REMOVE). Defaults to ACTION_SET */
+    private int action = ACTION_SET;
     private static final Log log = LogFactory.getLog(PropertyMediator.class);
     private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
 
     /**
-     * Sets a property into the current (local) Synapse Context
+     * Sets or  a property into the current (local) Synapse Context or into the Axis Configuration Context
+     * or into Transports Header
+     * And Removes above properties from the corresspounding locations
      *
      * @param smc the message context
      * @return true always
@@ -58,54 +69,103 @@
         if (shouldTrace) {
             trace.trace("Start : Entry mediator");
         }
-        String value = (this.value != null ? this.value : Axis2MessageContext.getStringValue(
-                getExpression(), smc));
-        log.debug("Setting property : " + name +
-                " (scope:" + (scope == null ? "default" : scope) + ") = " + value);
-        if (shouldTrace) {
-            trace.trace("Entry Name : " + getName() +
-                " (scope:" + (scope == null ? "default" : scope) + ") set to " +
-                (getValue() != null ? " value = " + getValue() :
-                    " result of expression " + getExpression() + " = " + value));
-        }
-        if (scope == null) {
-            smc.setProperty(name, value);
-
-        } else if (Constants.SCOPE_DEFAULT.equals(scope)) {
-            smc.setProperty(name, value);
-
-        } else if (Constants.SCOPE_AXIS2.equals(scope)
-                && smc instanceof Axis2MessageContext) {
-            Axis2MessageContext axis2smc = (Axis2MessageContext) smc;
-            org.apache.axis2.context.MessageContext axis2MessageCtx =
-                    axis2smc.getAxis2MessageContext();
-            axis2MessageCtx.getConfigurationContext().setProperty(name, value);
-
-        } else if (Constants.SCOPE_TRANSPORT.equals(scope)
-                && smc instanceof Axis2MessageContext) {
-            Axis2MessageContext axis2smc = (Axis2MessageContext) smc;
-            org.apache.axis2.context.MessageContext axis2MessageCtx =
-                    axis2smc.getAxis2MessageContext();
-            Object headers = axis2MessageCtx.getProperty(
-                    org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
-
-            if (headers != null && headers instanceof Map) {
-                Map headersMap = (HashMap) headers;
-                headersMap.put(name, value);
+        if (action == ACTION_SET) {
+            String resultValue = (this.value != null ? this.value : Axis2MessageContext.getStringValue(
+                    expression, smc));
+            log.debug("Setting : " + name +
+                    " property (scope:" + (scope == null ? "default" : scope) + ") = " + resultValue);
+            if (shouldTrace) {
+                trace.trace("Entry Name : " + name +                                                                    
+                        " (scope:" + (scope == null ? "default" : scope) + ") set to " +
+                        (value != null ? " resultValue = " + value :
+                                " result of expression " + expression + " = " + resultValue));
             }
-            if (headers == null) {
-                Map headersMap = new HashMap();
-                headersMap.put(name, value);
-                axis2MessageCtx.setProperty(
-                        org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
-                        headersMap);
+            if (scope == null) {
+                //Setting property into the  Synapse Context
+                smc.setProperty(name, resultValue);
+            } else if (Constants.SCOPE_DEFAULT.equals(scope)) {
+                //Setting property into the  Synapse Context
+                smc.setProperty(name, resultValue);
+            } else if (Constants.SCOPE_AXIS2.equals(scope)
+                    && smc instanceof Axis2MessageContext) {
+                //Setting property into the  Axis2 Configuaration Context Context
+                Axis2MessageContext axis2smc = (Axis2MessageContext) smc;
+                org.apache.axis2.context.MessageContext axis2MessageCtx =
+                        axis2smc.getAxis2MessageContext();
+                axis2MessageCtx.getConfigurationContext().setProperty(name, resultValue);
+
+            } else if (Constants.SCOPE_TRANSPORT.equals(scope)
+                    && smc instanceof Axis2MessageContext) {
+                //Setting Transport Headers
+                Axis2MessageContext axis2smc = (Axis2MessageContext) smc;
+                org.apache.axis2.context.MessageContext axis2MessageCtx =
+                        axis2smc.getAxis2MessageContext();
+                Object headers = axis2MessageCtx.getProperty(
+                        org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
+
+                if (headers != null && headers instanceof Map) {
+                    Map headersMap = (HashMap) headers;
+                    headersMap.put(name, resultValue);
+                }
+                if (headers == null) {
+                    Map headersMap = new HashMap();
+                    headersMap.put(name, resultValue);
+                    axis2MessageCtx.setProperty(
+                            org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
+                            headersMap);
+                }
+            } else {
+                String msg = "Unsupported scope : " + scope + " for property mediator";
+                handleException(msg);
             }
-
         } else {
-            String msg = "Unsupported scope : " + scope + " for set-property mediator";
-            handleException(msg);
+            log.debug("Removing : " + name +
+                    " property (scope:" + (scope == null ? "default" : scope) + ") ");
+            trace.trace("Remove - Entry Name : " + name +
+                    " (scope:" + (scope == null ? "default" : scope) + ")");
+            if (scope == null) {
+                //Removing property from the  Synapse Context
+                Set pros = smc.getLocalPropertyKeySet();
+                if (pros != null) {
+                    pros.remove(name);
+                }
+            } else if (Constants.SCOPE_DEFAULT.equals(scope)) {
+                //Removing property from the  Synapse Context
+                Set pros = smc.getLocalPropertyKeySet();
+                if (pros != null) {
+                    pros.remove(name);
+                }
+            } else if (Constants.SCOPE_AXIS2.equals(scope)
+                    && smc instanceof Axis2MessageContext) {
+                //Removing property from the  Axis2 Configuration Context
+                Axis2MessageContext axis2smc = (Axis2MessageContext) smc;
+                org.apache.axis2.context.MessageContext axis2MessageCtx =
+                        axis2smc.getAxis2MessageContext();
+                Map pros = axis2MessageCtx.getConfigurationContext().getProperties();
+                if (pros != null) {
+                    pros.remove(name);
+                }
+            } else if (Constants.SCOPE_TRANSPORT.equals(scope)
+                    && smc instanceof Axis2MessageContext) {
+                // Removing transport headers
+                Axis2MessageContext axis2smc = (Axis2MessageContext) smc;
+                org.apache.axis2.context.MessageContext axis2MessageCtx =
+                        axis2smc.getAxis2MessageContext();
+                Object headers = axis2MessageCtx.getProperty(
+                        org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
+                if (headers != null && headers instanceof Map) {
+                    Map headersMap = (HashMap) headers;
+                    headersMap.remove(name);
+                }
+                if (headers == null) {
+                    log.info("No Headers found ");
+                }
+
+            } else {
+                String msg = "Unsupported scope : " + scope + " for property mediator";
+                handleException(msg);
+            }
         }
-
         if (shouldTrace) {
             trace.trace("End : Entry mediator");
         }
@@ -147,5 +207,13 @@
 
     public void setScope(String scope) {
         this.scope = scope;
+    }
+
+    public int getAction() {
+        return action;
+    }
+
+    public void setAction(int action) {
+        this.action = action;
     }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java Tue Mar  6 21:06:57 2007
@@ -40,8 +40,8 @@
     public static final String DISPATCHERS_ELEMENT      = "dispatchers";
     public static final String DISPATCHER_ELEMENT       = "dispatcher";
 
-    public static final QName ATT_REF_Q =
-            new QName(org.apache.synapse.config.xml.Constants.NULL_NAMESPACE, "ref");
+    public static final QName ATT_KEY_Q =
+            new QName(org.apache.synapse.config.xml.Constants.NULL_NAMESPACE, "key");
     public static final QName ATT_ADDRESS_Q =
             new QName(org.apache.synapse.config.xml.Constants.NULL_NAMESPACE, "address");
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java Tue Mar  6 21:06:57 2007
@@ -103,13 +103,14 @@
                 Axis2MessageContext.getStringValue(mProp.getExpression(), synCtx));
 
             try {
-                Method method = m.getClass().getMethod(mName, new Class[] {String.class});
-                log.debug("Setting property :: invoking method " + mName + "(" + value + ")");
-                if (shouldTrace) {
-                    trace.trace("Setting property :: invoking method " + mName + "(" + value + ")");
+                if (value != null) {
+                    Method method = m.getClass().getMethod(mName, new Class[]{String.class});
+                    log.debug("Setting property :: invoking method " + mName + "(" + value + ")");
+                    if (shouldTrace) {
+                        trace.trace("Setting property :: invoking method " + mName + "(" + value + ")");
+                    }
+                    method.invoke(m, new Object[]{value});
                 }
-                method.invoke(m, new Object[] { value });
-
             } catch (Exception e) {
                 String msg = "Error setting property : " + mProp.getName() + " as a String property into class" +
                     " mediator : " + m.getClass() + " : " + e.getMessage();

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java Tue Mar  6 21:06:57 2007
@@ -29,6 +29,7 @@
 import org.jaxen.JaxenException;
 
 import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 
 /**
  * The filter mediator combines the regex and xpath filtering functionality. If an xpath
@@ -92,11 +93,20 @@
             } else if (source != null && regex != null) {
                 log.debug("Evaluating regular expression : " + regex.pattern() + " against source : " + source);
                 String sourceString = Axis2MessageContext.getStringValue(source, synCtx);
+                if (sourceString == null) {
+                    log.warn("Source String has been evaluated to Null");
+                    return false;
+                }
                 if (shouldTrace(synCtx.getTracingState())) {
                     trace.trace("Regular expression : " + regex.pattern() + " and Source " +
-                        sourceString + " matches : " + regex.matcher(sourceString).matches());
+                            sourceString + " matches : " + regex.matcher(sourceString).matches());
+                }
+                Matcher matcher = regex.matcher(sourceString);
+                if (matcher == null) {
+                    log.warn("Can not find a Regex Pattren Matcher");
+                    return false;
                 }
-                return regex.matcher(sourceString).matches();
+                return matcher.matches();
 
             } else {
                 log.error("Invalid configuration specified");

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java Tue Mar  6 21:06:57 2007
@@ -72,20 +72,24 @@
                 trace.trace("Source Value : " + sourceText);
                 trace.trace("Start Case mediator list");
             }
-            Iterator iter = cases.iterator();
-            while (iter.hasNext()) {
-                SwitchCase swCase = (SwitchCase) iter.next();
-                if (swCase != null) {
-                    if (swCase.matches(sourceText)) {
-                        if (shouldTrace) {
-                            trace.trace("Executing case for : " + swCase.getRegex());
+            if (sourceText != null) {
+                Iterator iter = cases.iterator();
+                while (iter.hasNext()) {
+                    SwitchCase swCase = (SwitchCase) iter.next();
+                    if (swCase != null) {
+                        if (swCase.matches(sourceText)) {
+                            if (shouldTrace) {
+                                trace.trace("Executing case for : " + swCase.getRegex());
+                            }
+                            return swCase.mediate(synCtx);
                         }
-                        return swCase.mediate(synCtx);
                     }
                 }
-            }
-            if (shouldTrace) {
-                trace.trace("End Case mediator list");
+                if (shouldTrace) {
+                    trace.trace("End Case mediator list");
+                }
+            } else {
+                log.warn("Source has been evaluated to Null...Default Case will be run");
             }
             if (defaultCase != null) {
                 log.debug("Executing default case");

Added: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/PropertyMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/PropertyMediatorSerializationTest.java?view=auto&rev=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/PropertyMediatorSerializationTest.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/PropertyMediatorSerializationTest.java Tue Mar  6 21:06:57 2007
@@ -0,0 +1,56 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse.config.xml;
+
+/**
+ *
+ *
+ */
+
+public class PropertyMediatorSerializationTest extends AbstractTestCase {
+    PropertyMediatorFactory propertyMediatorFactory;
+    PropertyMediatorSerializer propertyMediatorSerializer;
+
+    public PropertyMediatorSerializationTest() {
+        super(AbstractTestCase.class.getName());
+        propertyMediatorFactory = new PropertyMediatorFactory();
+        propertyMediatorSerializer = new PropertyMediatorSerializer();
+    }
+
+    public void testPropertyMediatorSerializationSenarioOne() throws Exception {
+        String inputXml = "<property xmlns=\"http://ws.apache.org/ns/synapse\" name=\"To\" value=\"http://127.0.0.1:10001/axis2/services/Services\" action=\"remove\" />";
+        assertTrue(serialization(inputXml, propertyMediatorFactory, propertyMediatorSerializer));
+        assertTrue(serialization(inputXml, propertyMediatorSerializer));
+    }
+
+    public void testPropertyMediatorSerializationSenarioTwo() throws Exception {
+        String inputXml = "<property xmlns=\"http://ws.apache.org/ns/synapse\" expression=\"child::*\" name=\"To\" />";
+        assertTrue(serialization(inputXml, propertyMediatorFactory, propertyMediatorSerializer));
+        assertTrue(serialization(inputXml, propertyMediatorSerializer));
+    }
+
+    public void testPropertyMediatorSerializationSenarioThree() throws Exception {
+        String inputXml = "<property xmlns=\"http://ws.apache.org/ns/synapse\" expression=\"child::*\" name=\"To\" action=\"remove\"/>";
+        assertTrue(serialization(inputXml, propertyMediatorFactory, propertyMediatorSerializer));
+        assertTrue(serialization(inputXml, propertyMediatorSerializer));
+    }
+
+    public void testPropertyMediatorSerializationSenarioFour() throws Exception {
+        String inputXml = "<property xmlns=\"http://ws.apache.org/ns/synapse\"  name=\"To\" action=\"remove\"/>";
+        assertTrue(serialization(inputXml, propertyMediatorFactory, propertyMediatorSerializer));
+        assertTrue(serialization(inputXml, propertyMediatorSerializer));
+    }
+}

Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/PropertyMediatorTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/PropertyMediatorTest.java?view=diff&rev=515458&r1=515457&r2=515458
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/PropertyMediatorTest.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/PropertyMediatorTest.java Tue Mar  6 21:06:57 2007
@@ -34,12 +34,32 @@
         propMediator.setName("name");
         propMediator.setValue("value");
 
+         // set a local property to the synapse context
+        PropertyMediator propMediatorTwo = new PropertyMediator();
+        propMediatorTwo.setName("nameTwo");
+        propMediatorTwo.setValue("valueTwo");
+
         MessageContext synCtx = TestUtils.getTestContext("<empty/>");
         propMediator.mediate(synCtx);
-
+        propMediatorTwo.mediate(synCtx);
         assertTrue(
             "value".equals(Axis2MessageContext.getStringValue(
                 new AXIOMXPath("synapse:get-property('name')"), synCtx)));
+        assertTrue(
+            "valueTwo".equals(Axis2MessageContext.getStringValue(
+                new AXIOMXPath("synapse:get-property('nameTwo')"), synCtx)));
+
+        PropertyMediator propMediatorThree = new PropertyMediator();
+        propMediatorThree.setName("name");
+        propMediatorThree.setValue("value");
+        propMediatorThree.setAction(PropertyMediator.ACTION_REMOVE);
+        propMediatorThree.mediate(synCtx) ;
+        assertNull(Axis2MessageContext.getStringValue(
+                new AXIOMXPath("synapse:get-property('name')"), synCtx));
+        assertTrue(
+                   "valueTwo".equals(Axis2MessageContext.getStringValue(
+                       new AXIOMXPath("synapse:get-property('nameTwo')"), synCtx)));
+                
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org