synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject svn commit: r601613 - in /webservices/synapse/trunk/java/modules/core/src: main/java/org/apache/synapse/config/xml/ main/java/org/apache/synapse/mediators/ext/ test/java/org/apache/synapse/config/xml/ test/java/org/apache/synapse/mediators/ext/
Date Thu, 06 Dec 2007 05:03:10 GMT
Author: ruwan
Date: Wed Dec  5 21:03:06 2007
New Revision: 601613

URL: http://svn.apache.org/viewvc?rev=601613&view=rev
Log:
Improved the POJOCommand mediator with the property getting back to the message after the
execution, this fixes the issue SYNAPSE-182 as well. Now the configuration for the pojo command
properties has an optional attribute to specify the action as [action="get|set"] defaults
to [action="set"]

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java?rev=601613&r1=601612&r2=601613&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnnotatedCommandMediatorFactory.java
Wed Dec  5 21:03:06 2007
@@ -89,14 +89,14 @@
                             xpath = new AXIOMXPath(
                                 child.getAttribute(ATT_EXPRN).getAttributeValue());
                             OMElementUtils.addNameSpaces(xpath, child, log);
-                            pojoMediator.addDynamicProperty(propName, xpath);
+                            pojoMediator.addDynamicSetterProperty(propName, xpath);
                         } catch (JaxenException e) {
                             handleException("Error instantiating XPath expression : " +
                                 child.getAttribute(ATT_EXPRN), e);
                         }
                     } else {
                         if (child.getAttribute(ATT_VALUE) != null) {
-                            pojoMediator.addStaticProperty(propName,
+                            pojoMediator.addStaticSetterProperty(propName,
                                 child.getAttribute(ATT_VALUE).getAttributeValue());
                         } else {
                             handleException("A POJO mediator property must specify either
" +

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java?rev=601613&r1=601612&r2=601613&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java
Wed Dec  5 21:03:06 2007
@@ -37,17 +37,19 @@
  * <p/>
  * <pre>
  * &lt;pojoCommand name=&quot;class-name&quot;&gt;
- *   &lt;property name=&quot;string&quot; value=&quot;literal&quot;&gt;
+ *   &lt;property name=&quot;string&quot; value=&quot;literal&quot;
+ *                action=(&quot;get&quot; | &quot;set&quot;)&gt;
  *      either literal or XML child
  *   &lt;/property&gt;
- *   &lt;property name=&quot;string&quot; expression=&quot;XPATH expression&quot;/&gt;
+ *   &lt;property name=&quot;string&quot; expression=&quot;XPATH expression&quot;
+ *                action=(&quot;get&quot; | &quot;set&quot;)/&gt;
  * &lt;/pojoCommand&gt;
  * </pre>
  */
 public class POJOCommandMediatorFactory extends AbstractMediatorFactory {
 
-    private static final QName POJO_COMMAND_Q =
-        new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "pojoCommand");
+    private static final QName POJO_COMMAND_Q = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE,
"pojoCommand");
+    protected static final QName ATT_ACTION   = new QName("action");    
 
     public Mediator createMediator(OMElement elem) {
 
@@ -84,22 +86,55 @@
                 } else {
                     if (child.getAttribute(ATT_EXPRN) != null) {
                         AXIOMXPath xpath = null;
+
                         try {
-                            xpath = new AXIOMXPath(
-                                child.getAttribute(ATT_EXPRN).getAttributeValue());
+                            xpath = new AXIOMXPath(child.getAttribute(ATT_EXPRN).getAttributeValue());
                             OMElementUtils.addNameSpaces(xpath, child, log);
-                            pojoMediator.addDynamicProperty(propName, xpath);
+
+                            if (child.getAttribute(ATT_ACTION) != null) {
+                                
+                                String action = child.getAttribute(ATT_ACTION).getAttributeValue();
+                                if ("get".equals(action)) {
+                                    pojoMediator.addMessageGetterProperty(propName, xpath);
+                                } else if ("set".equals(action)) {
+                                    pojoMediator.addDynamicSetterProperty(propName, xpath);
+                                } else {
+                                    // if there is an action attribute and the value is not
neigther get nor set
+                                    handleException("Property action for the " +
+                                            "POJOCommand mediator should be eigther 'get'
or 'set'");
+                                }
+                            } else {
+                                // if no action is provided take it as a setter propperty
+                                pojoMediator.addDynamicSetterProperty(propName, xpath);
+                            }
+                            
                         } catch (JaxenException e) {
                             handleException("Error instantiating XPath expression : " +
                                 child.getAttribute(ATT_EXPRN), e);
                         }
                     } else {
                         if (child.getAttribute(ATT_VALUE) != null) {
-                            pojoMediator.addStaticProperty(propName,
-                                child.getAttribute(ATT_VALUE).getAttributeValue());
+
+                            String value = child.getAttribute(ATT_VALUE).getAttributeValue();
+                            if (child.getAttribute(ATT_ACTION) != null) {
+
+                                String action = child.getAttribute(ATT_ACTION).getAttributeValue();
+                                if ("get".equals(action)) {
+                                    pojoMediator.addContextGetterProperty(propName, value);
+                                } else if ("set".equals(action)) {
+                                    pojoMediator.addStaticSetterProperty(propName, value);
+                                } else {
+                                    // if there is an action attribute and the value is not
neigther get nor set
+                                    handleException("Property action for the " +
+                                            "POJOCommand mediator should be eigther 'get'
or 'set'");
+                                }
+                            } else {
+                                // if no action is provided take it as a setter propperty
+                                pojoMediator.addStaticSetterProperty(propName, value);
+                            }
                         } else {
                             handleException("A POJO mediator property must specify either
" +
-                                "name and expression attributes, or name and value attributes");
+                                    "name and expression attributes, or name and value attributes");
                         }
                     }
                 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java?rev=601613&r1=601612&r2=601613&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java
Wed Dec  5 21:03:06 2007
@@ -21,12 +21,9 @@
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.mediators.ext.POJOCommandMediator;
 
-import javax.xml.namespace.QName;
 import java.util.Iterator;
 
 /**
@@ -61,23 +58,47 @@
             handleException("Invalid POJO Command mediator. The command class name is required");
         }
 
-        for (Iterator itr = mediator.getStaticProps().keySet().iterator(); itr.hasNext();
) {
+        for (Iterator itr = mediator.getStaticSetterProperties().keySet().iterator(); itr.hasNext();
) {
             String propName = (String) itr.next();
-            String value = (String) mediator.getStaticProps().get(propName);
+            String value = (String) mediator.getStaticSetterProperties().get(propName);
             OMElement prop = fac.createOMElement(PROP_Q);
             prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
             prop.addAttribute(fac.createOMAttribute("value", nullNS, value));
+            prop.addAttribute(fac.createOMAttribute("action", nullNS, "set"));
             pojoCommand.addChild(prop);
         }
 
-        for (Iterator itr = mediator.getDynamicProps().keySet().iterator(); itr.hasNext();
) {
+        for (Iterator itr = mediator.getDynamicSetterProperties().keySet().iterator(); itr.hasNext();
) {
             String propName = (String) itr.next();
-            AXIOMXPath exprn = (AXIOMXPath) mediator.getDynamicProps().get(propName);
+            AXIOMXPath exprn = (AXIOMXPath) mediator.getDynamicSetterProperties().get(propName);
             OMElement prop = fac.createOMElement(PROP_Q);
             prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
             prop.addAttribute(fac.createOMAttribute("expression", nullNS,
                 exprn.toString()));
             serializeNamespaces(prop, exprn);
+            prop.addAttribute(fac.createOMAttribute("action", nullNS, "set"));
+            pojoCommand.addChild(prop);
+        }
+
+        for (Iterator itr = mediator.getContextGetterProperties().keySet().iterator(); itr.hasNext();
) {
+            String propName = (String) itr.next();
+            String value = (String) mediator.getContextGetterProperties().get(propName);
+            OMElement prop = fac.createOMElement(PROP_Q);
+            prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
+            prop.addAttribute(fac.createOMAttribute("value", nullNS, value));
+            prop.addAttribute(fac.createOMAttribute("action", nullNS, "get"));
+            pojoCommand.addChild(prop);
+        }
+
+        for (Iterator itr = mediator.getMessageGetterProperties().keySet().iterator(); itr.hasNext();
) {
+            String propName = (String) itr.next();
+            AXIOMXPath exprn = (AXIOMXPath) mediator.getMessageGetterProperties().get(propName);
+            OMElement prop = fac.createOMElement(PROP_Q);
+            prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
+            prop.addAttribute(fac.createOMAttribute("expression", nullNS,
+                exprn.toString()));
+            serializeNamespaces(prop, exprn);
+            prop.addAttribute(fac.createOMAttribute("action", nullNS, "get"));
             pojoCommand.addChild(prop);
         }
 

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java?rev=601613&r1=601612&r2=601613&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java
Wed Dec  5 21:03:06 2007
@@ -75,9 +75,9 @@
         }
 
         // then set the static/constant properties first
-        for (Iterator iter = getStaticProps().keySet().iterator(); iter.hasNext(); ) {
+        for (Iterator iter = getStaticSetterProperties().keySet().iterator(); iter.hasNext();
) {
             String name = (String) iter.next();
-            setInstanceProperty(name, (String) getStaticProps().get(name), commandObject,
synCtx);
+            setInstanceProperty(name, (String) getStaticSetterProperties().get(name), commandObject,
synCtx);
         }
         
         

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java?rev=601613&r1=601612&r2=601613&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
Wed Dec  5 21:03:06 2007
@@ -19,16 +19,22 @@
 
 package org.apache.synapse.mediators.ext;
 
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.xpath.AXIOMXPath;
 import org.apache.synapse.Command;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.eip.EIPUtils;
+import org.jaxen.JaxenException;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 /**
  * This mediator will use the specified command object and execute the command after setting
@@ -49,12 +55,25 @@
      * 'static' properties whose values are constant and does not depend
      * on the current message (i.e. and XPath over it)
      */
-    private Map staticProps = new HashMap();
+    private Map staticSetterProperties = new HashMap();
+
     /**
      * 'dynamic' properties whose values are dynamically evaluated before each
      * invocation of the command, by evaluating an XPath against the current message
      */
-    private Map dynamicProps = new HashMap();
+    private Map dynamicSetterProperties = new HashMap();
+
+    /**
+     * 'context' properties whose values are set back to the message context as message
+     * context properties
+     */
+    private Map contextGetterProperties = new HashMap();
+
+    /**
+     * 'messsage' properties whose values are set back to the current message, from the command
+     * and as specified by the XPATH
+     */
+    private Map messageGetterProperties = new HashMap();
 
     /**
      * Implements the mediate method of the Mediator interface. This method will instantiate
@@ -95,16 +114,17 @@
         }
 
         // then set the static/constant properties first
-        for (Iterator iter = staticProps.keySet().iterator(); iter.hasNext(); ) {
+        for (Iterator iter = staticSetterProperties.keySet().iterator(); iter.hasNext();
) {
             String name = (String) iter.next();
-            setInstanceProperty(name, (String) staticProps.get(name), commandObject, synCtx);
+            setInstanceProperty(name,
+                (String) staticSetterProperties.get(name), commandObject, synCtx);
         }
 
         // now set the any dynamic properties evaluating XPath's on the current message
-        for (Iterator iter = dynamicProps.keySet().iterator(); iter.hasNext(); ) {
+        for (Iterator iter = dynamicSetterProperties.keySet().iterator(); iter.hasNext();
) {
 
             String name = (String) iter.next();
-            AXIOMXPath xpath = (AXIOMXPath) dynamicProps.get(name);
+            AXIOMXPath xpath = (AXIOMXPath) dynamicSetterProperties.get(name);
             String value = Axis2MessageContext.getStringValue(xpath, synCtx);
 
             setInstanceProperty(name, value, commandObject, synCtx);
@@ -138,6 +158,47 @@
             }
         }
 
+        // then set the context properties back to the messageContext from the command
+        for (Iterator iter = contextGetterProperties.keySet().iterator(); iter.hasNext();
) {
+            String name = (String) iter.next();
+            synCtx.setProperty((String) contextGetterProperties.get(name),
+                getInstanceProperty(name, commandObject, synCtx));
+        }
+
+        // now set the any message properties evaluating XPath's on the current message back
+        // to the message from the command
+        for (Iterator iter = messageGetterProperties.keySet().iterator(); iter.hasNext();
) {
+
+            String name = (String) iter.next();
+            AXIOMXPath xpath = (AXIOMXPath) messageGetterProperties.get(name);
+
+            Object resultValue = getInstanceProperty(name, commandObject, synCtx);
+
+            try {
+                List list = EIPUtils.getMatchingElements(synCtx.getEnvelope(), xpath);
+                if (list.size() > 0) {
+                    Object o = list.get(0);
+                    if (resultValue instanceof String) {
+                        OMAbstractFactory.getOMFactory().createOMText(
+                            ((OMNode) o).getParent(), (String) resultValue);
+                        ((OMNode) o).detach();
+                    } else if (resultValue instanceof OMNode) {
+                        ((OMNode) o).insertSiblingAfter((OMNode) resultValue);
+                        ((OMNode) o).detach();
+                    }
+
+                } else {
+                    if (traceOrDebugOn) {
+                        traceOrDebug(traceOn, "Unable to set the message property " + resultValue
+                            + "back to the message : Specified element by the xpath " + xpath
+ " can not be found");
+                    }
+                }
+            } catch (JaxenException e) {
+                handleException("Unable to set the command property "
+                    + name + " back to the message", e, synCtx);
+            }
+        }
+
         if (traceOrDebugOn) {
             traceOrDebug(traceOn, "End : POJOCommand mediator");
         }
@@ -145,8 +206,40 @@
     }
 
     /**
+     * Find and invoke the getter method with the name of form getXXX and returns the value
given
+     * on the POJO object
+     *
+     * @param name name of the getter field
+     * @param obj POJO instance
+     * @param synCtx current message
+     * @return object representing the value of the getter method
+     */
+    private Object getInstanceProperty(String name, Object obj, MessageContext synCtx) {
+
+        String mName = "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
+        try {
+            Method[] methods = obj.getClass().getMethods();
+
+            for (Method method : methods) {
+                if (mName.equals(method.getName())) {
+                    return method.invoke(obj);
+                }
+            }
+        } catch(InvocationTargetException e) {
+            handleException("Unable to get the command property '"
+                + name + "' back to the message", e, synCtx);
+        } catch(IllegalAccessException e){
+            handleException("Unable to get the command property '"
+                + name + "' back to the message", e, synCtx);
+        }
+
+        return null;
+    }
+
+    /**
      * Find and invoke the setter method with the name of form setXXX passing in the value
given
      * on the POJO object
+     *
      * @param name name of the setter field
      * @param value value to be set
      * @param obj POJO instance
@@ -218,19 +311,35 @@
         this.command = command;
     }
 
-    public void addStaticProperty(String name, String value) {
-        this.staticProps.put(name, value);
+    public void addStaticSetterProperty(String name, String value) {
+        this.staticSetterProperties.put(name, value);
+    }
+
+    public void addDynamicSetterProperty(String name, Object value) {
+        this.dynamicSetterProperties.put(name, value);
+    }
+
+    public void addContextGetterProperty(String name, String value) {
+        this.contextGetterProperties.put(name, value);
+    }
+
+    public void addMessageGetterProperty(String name, Object value) {
+        this.messageGetterProperties.put(name, value);
+    }
+
+    public Map getStaticSetterProperties() {
+        return this.staticSetterProperties;
     }
 
-    public void addDynamicProperty(String name, Object value) {
-        this.dynamicProps.put(name, value);
+    public Map getDynamicSetterProperties() {
+        return this.dynamicSetterProperties;
     }
 
-    public Map getStaticProps() {
-        return this.staticProps;
+    public Map getContextGetterProperties() {
+        return this.contextGetterProperties;
     }
 
-    public Map getDynamicProps() {
-        return this.dynamicProps;
+    public Map getMessageGetterProperties() {
+        return this.messageGetterProperties;
     }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java?rev=601613&r1=601612&r2=601613&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java
Wed Dec  5 21:03:06 2007
@@ -50,7 +50,7 @@
     public void testPOJOCommandNotImplementedMediatorWithPropertySerialization() throws Exception
{
         String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
                 "name=\"org.apache.synapse.mediators.ext.POJOCommandTestMediator\">" +
-                "<property name=\"testProp\" expression=\"fn:concat('XPATH ', 'FUNC')\"/></pojoCommand>";
+                "<property name=\"testProp\" expression=\"fn:concat('XPATH ', 'FUNC')\"
action=\"set\"/></pojoCommand>";
         assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
         assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
     }
@@ -58,7 +58,7 @@
     public void testPOJOCommandMediatorImplementedWithPropertySerialization() throws Exception
{
         String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
                 "name=\"org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator\">"
+
-                "<property name=\"testProp\" expression=\"fn:concat('XPATH ', 'FUNC')\"/></pojoCommand>";
+                "<property name=\"testProp\" expression=\"fn:concat('XPATH ', 'FUNC')\"
action=\"set\"/></pojoCommand>";
         assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
         assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
     }
@@ -66,7 +66,23 @@
     public void testPOJOCommandMediatorWithStaticPropertySerialization() throws Exception
{
         String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
                 "name=\"org.apache.synapse.mediators.ext.POJOCommandTestMediator\">" +
-                "<property name=\"testProp\" value=\"Test Property\"/></pojoCommand>";
+                "<property name=\"testProp\" value=\"Test Property\" action=\"set\"/></pojoCommand>";
+        assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
+        assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
+    }
+
+    public void testPOJOCommandMediatorWithMessagePropertySerialization() throws Exception
{
+        String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
+                "name=\"org.apache.synapse.mediators.ext.POJOCommandTestMediator\">" +
+                "<property name=\"testProp\" expression=\"fn:concat('XPATH ', 'FUNC')\"
action=\"get\"/></pojoCommand>";
+        assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
+        assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
+    }
+
+    public void testPOJOCommandMediatorWithContextPropertySerialization() throws Exception
{
+        String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
+                "name=\"org.apache.synapse.mediators.ext.POJOCommandTestMediator\">" +
+                "<property name=\"testProp\" value=\"Test Property\" action=\"get\"/></pojoCommand>";
         assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
         assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
     }

Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java?rev=601613&r1=601612&r2=601613&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java
Wed Dec  5 21:03:06 2007
@@ -19,10 +19,13 @@
 
 package org.apache.synapse.mediators.ext;
 
-import org.apache.synapse.config.xml.MediatorFactoryFinder;
 import org.apache.synapse.Mediator;
+import org.apache.synapse.MessageContext;
 import org.apache.synapse.TestMessageContext;
+import org.apache.synapse.config.xml.MediatorFactoryFinder;
 import org.apache.synapse.mediators.AbstractMediatorTestCase;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.om.OMAbstractFactory;
 
 /**
  * Tests the pojo command mediator instantiation and setting of literal and
@@ -78,6 +81,35 @@
         POJOCommandTestHelper.reset();
         pcm.mediate(new TestMessageContext());
         assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty());
+        assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
+    }
+
+    public void testPojoWithContextPropertiesCommandImpl() throws Exception {
+        Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
+                "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator'
" +
+                        "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\"
" +
+                        "value=\"Test Property\"/><property name=\"testProp\" value=\"testPropInMC\"
action=\"get\"/></pojoCommand>"));
+        POJOCommandTestHelper.reset();
+        MessageContext ctx = new TestMessageContext();
+        pcm.mediate(ctx);
+        assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty());
+        assertEquals("Test Property", ctx.getProperty("testPropInMC"));
+        assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
+    }
+
+    public void testPojoWithMessagePropertiesCommandImpl() throws Exception {
+        Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
+                "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator'
" +
+                        "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\"
" +
+                        "value=\"TestProperty\"/><property name=\"testProp\" expression=\"//testNode\"
action=\"get\"/></pojoCommand>"));
+        POJOCommandTestHelper.reset();
+        MessageContext ctx = new TestMessageContext();
+        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+        envelope.getBody().addChild(createOMElement("<original><testNode/></original>"));
+        ctx.setEnvelope(envelope);
+        pcm.mediate(ctx);
+        assertEquals("TestProperty", POJOCommandTestHelper.getInstance().getChangedProperty());
+        assertEquals("<original>TestProperty</original>", ctx.getEnvelope().getBody().getFirstOMChild().toString());
         assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
     }
 }



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


Mime
View raw message