synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject svn commit: r576407 - in /webservices/synapse/trunk/java/modules/core/src: main/java/org/apache/synapse/config/xml/ main/java/org/apache/synapse/mediators/eip/ main/java/org/apache/synapse/mediators/eip/splitter/ test/java/org/apache/synapse/mediators/...
Date Mon, 17 Sep 2007 13:04:15 GMT
Author: ruwan
Date: Mon Sep 17 06:04:13 2007
New Revision: 576407

URL: http://svn.apache.org/viewvc?rev=576407&view=rev
Log:
Adding a new Clone Mediator which will basically clone the message and in to specified number
of targets and mediated using different targets (target can be either sequence or endpoint
or both) 

// more to be followed

Added:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/eip/

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorFactory.java?rev=576407&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorFactory.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorFactory.java
Mon Sep 17 06:04:13 2007
@@ -0,0 +1,54 @@
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.Mediator;
+import org.apache.synapse.config.xml.endpoints.EndpointAbstractFactory;
+import org.apache.synapse.mediators.eip.splitter.CloneMediator;
+import org.apache.synapse.mediators.eip.splitter.IterateMediator;
+import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * The <clone> element is used to copy messages in Synapse to simillar messages
but with
+ * different message contexts and mediated using the specified targets
+ *
+ * <pre>
+ *  &lt;clone continueParent=(true | false)&gt;
+ *   &lt;target to="TO address" [soapAction="urn:Action"] sequence="sequence ref"
+ *                                                         endpoint="endpoint ref"&gt;
+ *    &lt;sequence&gt; (mediator +) &lt;/sequence&gt;
+ *    &lt;endpoint&gt; endpoint &lt;/endpoint&gt;
+ *   &lt;/target&gt;
+ *  &lt;/iterate&gt;
+ * </pre>
+ */
+public class CloneMediatorFactory extends AbstractMediatorFactory {
+
+    private static final QName CLONE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "clone");
+    
+    public Mediator createMediator(OMElement elem) {
+
+        CloneMediator mediator = new CloneMediator();
+        initMediator(mediator, elem);
+        OMAttribute continueParent = elem.getAttribute(new QName(
+                Constants.NULL_NAMESPACE, "continueParent"));
+        if (continueParent != null) {
+            mediator.setContinueParent(Boolean.valueOf(continueParent.getAttributeValue()).booleanValue());
+        }
+
+        Iterator targetElements = elem.getChildrenWithName(
+                new QName(Constants.SYNAPSE_NAMESPACE, "target"));
+        while (targetElements.hasNext()) {
+            mediator.addTarget(TargetFactory.createTarget((OMElement) targetElements.next()));
+        }
+
+        return mediator;
+    }
+
+    public QName getTagQName() {
+        return CLONE_Q;
+    }
+}

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java?rev=576407&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java
Mon Sep 17 06:04:13 2007
@@ -0,0 +1,42 @@
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.eip.splitter.CloneMediator;
+import org.apache.synapse.mediators.eip.Target;
+
+import java.util.Iterator;
+
+/**
+ * 
+ */
+public class CloneMediatorSerializer extends AbstractMediatorSerializer {
+
+    public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+        OMElement cloneElem = fac.createOMElement("clone", synNS);
+        finalizeSerialization(cloneElem, m);
+
+        CloneMediator clone = (CloneMediator) m;
+        if (clone.isContinueParent()) {
+            cloneElem.addAttribute("continueParent", Boolean.toString(true), nullNS);
+        }
+
+        for (Iterator itr = clone.getTargets().iterator(); itr.hasNext();) {
+            Object o = itr.next();
+            if (o instanceof Target) {
+                cloneElem.addChild(TargetSerializer.serializeTarget((Target) o));
+            }
+        }
+
+        if (parent != null) {
+            parent.addChild(cloneElem);
+        }
+
+        return cloneElem;
+    }
+
+    public String getMediatorClassName() {
+        return CloneMediator.class.getName();
+    }
+}

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetFactory.java?rev=576407&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetFactory.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetFactory.java
Mon Sep 17 06:04:13 2007
@@ -0,0 +1,74 @@
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.mediators.eip.Target;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.xml.endpoints.EndpointAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+
+/**
+ * 
+ */
+public class TargetFactory {
+
+    private static final Log log = LogFactory.getLog(TargetFactory.class);
+    private static final QName TARGET_Q = new QName(Constants.SYNAPSE_NAMESPACE, "target");
+
+    public static Target createTarget(OMElement elem) {
+
+        if (!TARGET_Q.equals(elem.getQName())) {
+            handleException("Element does not match with the target QName");
+        }
+
+        Target target = new Target();
+        OMAttribute toAttr = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "to"));
+        if (toAttr != null && toAttr.getAttributeValue() != null) {
+            target.setTo(toAttr.getAttributeValue());
+        }
+
+        OMAttribute soapAction = elem.getAttribute(
+                new QName(Constants.NULL_NAMESPACE, "soapAction"));
+        if (soapAction != null && soapAction.getAttributeValue() != null) {
+            target.setSoapAction(soapAction.getAttributeValue());
+        }
+
+        OMAttribute sequenceAttr = elem.getAttribute(
+                new QName(Constants.NULL_NAMESPACE, "sequence"));
+        if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
+            target.setSequenceRef(sequenceAttr.getAttributeValue());
+        }
+
+        OMAttribute endpointAttr = elem.getAttribute(
+                new QName(Constants.NULL_NAMESPACE, "endpoint"));
+        if (endpointAttr != null && endpointAttr.getAttributeValue() != null) {
+            target.setEndpointRef(endpointAttr.getAttributeValue());
+        }
+
+        OMElement sequence = elem.getFirstChildWithName(
+                new QName(Constants.SYNAPSE_NAMESPACE, "sequence"));
+        if (sequence != null) {
+            SequenceMediatorFactory fac = new SequenceMediatorFactory();
+            target.setSequence(fac.createAnonymousSequence(sequence));
+        }
+
+        OMElement endpoint = elem.getFirstChildWithName(
+                new QName(Constants.SYNAPSE_NAMESPACE, "endpoint"));
+        if (endpoint != null) {
+            target.setEndpoint(EndpointAbstractFactory.
+                    getEndpointFactroy(endpoint).createEndpoint(endpoint, true));
+        }
+
+        return target;
+    }
+
+    private static void handleException (String message) {
+        if (log.isDebugEnabled()) {
+            log.debug(message);
+        }
+        throw new SynapseException(message);
+    }
+}

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetSerializer.java?rev=576407&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetSerializer.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TargetSerializer.java
Mon Sep 17 06:04:13 2007
@@ -0,0 +1,53 @@
+package org.apache.synapse.config.xml;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.synapse.mediators.eip.Target;
+import org.apache.synapse.config.xml.endpoints.EndpointAbstractSerializer;
+
+/**
+ * 
+ */
+public class TargetSerializer {
+
+    private static final Log log = LogFactory.getLog(TargetSerializer.class);
+    private static final OMFactory fac = OMAbstractFactory.getOMFactory();
+    private static final OMNamespace synNS = fac.createOMNamespace(Constants.SYNAPSE_NAMESPACE,
"syn");
+    private static final OMNamespace nullNS = fac.createOMNamespace(Constants.NULL_NAMESPACE,
"");
+
+    public static OMElement serializeTarget(Target target) {
+
+        OMElement targetElem = fac.createOMElement("target", synNS);
+        if (target.getTo() != null) {
+            targetElem.addAttribute("to", target.getTo(), nullNS);
+        }
+
+        if (target.getSoapAction() != null) {
+            targetElem.addAttribute("soapAction", target.getSoapAction(), nullNS);
+        }
+
+        if (target.getSequenceRef() != null) {
+            targetElem.addAttribute("sequence", target.getSequenceRef(), nullNS);
+        }
+
+        if (target.getEndpointRef() != null) {
+            targetElem.addAttribute("endpoint", target.getEndpointRef(), nullNS);
+        }
+
+        if (target.getSequence() != null) {
+            SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
+            serializer.serializeAnonymousSequence(targetElem, target.getSequence());
+        }
+
+        if (target.getEndpoint() != null) {
+            targetElem.addChild(EndpointAbstractSerializer.getEndpointSerializer(
+                    target.getEndpoint()).serializeEndpoint(target.getEndpoint()));
+        }
+
+        return targetElem;
+    }
+}

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java?rev=576407&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
Mon Sep 17 06:04:13 2007
@@ -0,0 +1,221 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.mediators.eip;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Constants;
+import org.apache.synapse.core.axis2.Axis2MessageContext;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.description.TransportInDescription;
+import org.jaxen.JaxenException;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * Utility methods for the EIP implementations
+ */
+public class EIPUtils {
+
+    /**
+     * This will be used for logging purposes
+     */
+    private static final Log log = LogFactory.getLog(EIPUtils.class);
+
+    /**
+     * This static util method will be used to extract out the set of all elements described
by the
+     * given XPath over the given SOAPEnvelope
+     * 
+     * @param envelope - SOAPEnvelope from which the the elements will be extracted
+     * @param expression - AXIOMXPath expression describing the elements
+     * @return List of OMElements in the envelope matching the expression
+     */
+    public static List getElements(SOAPEnvelope envelope, AXIOMXPath expression) {
+        try {
+            Object o = expression.evaluate(envelope);
+            if (o instanceof OMNode) {
+                List list = new ArrayList();
+                list.add(o);
+                return list;
+            } else if (o instanceof List) {
+                return (List) o;
+            } else {
+                handleException("The evaluation of the XPath expression "
+                        + expression + " must result in an OMNode");
+            }
+        } catch (JaxenException e) {
+            handleException("Error evaluating XPath " + expression + " on message");
+        }
+
+        return null;
+    }
+
+    /**
+     * This static util method will be used to create a new MessageContext by passing the
+     * MessageContext and the SOAPEnvelope to be filled with the newly created MessageContext
+     *
+     * @param synCtx - MessageContext which is subjected to the creation of the new MC
+     * @param envelope - SOAPEnvelope to be set to the new MC
+     * @return MessageContext created from the paased arguments
+     */
+    public static MessageContext createNewMessageContext(
+            MessageContext synCtx, SOAPEnvelope envelope) {
+
+        // create the message context and then copy the transportIn/Out from the original
message
+        MessageContext newCtx = synCtx.getEnvironment().createMessageContext();
+        org.apache.axis2.context.MessageContext axis2MC
+                = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
+        org.apache.axis2.context.MessageContext newAxis2MC
+                = ((Axis2MessageContext) newCtx).getAxis2MessageContext();
+
+        newAxis2MC.setTransportIn(axis2MC.getTransportIn());
+        newAxis2MC.setTransportOut(axis2MC.getTransportOut());
+
+        newAxis2MC.setServiceContext(axis2MC.getServiceContext());
+        newAxis2MC.setOperationContext(axis2MC.getOperationContext());
+        newAxis2MC.setAxisMessage(axis2MC.getAxisMessage());
+        newAxis2MC.getAxisMessage().setParent(axis2MC.getAxisOperation());
+        newAxis2MC.setAxisService(axis2MC.getAxisService());
+
+        newAxis2MC.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
+                axis2MC.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
+
+        try {
+            newCtx.setEnvelope(envelope);
+
+            // copy all the properties to the newCtx
+            Iterator propItr = synCtx.getPropertyKeySet().iterator();
+            while (propItr.hasNext()) {
+                Object o = propItr.next();
+                // If there are non String keyed properties neglect them rathern than trow
exception
+                if (o instanceof String) {
+                    newCtx.setProperty((String) o, synCtx.getProperty((String) o));
+                }
+            }
+
+            // set the parent details to the splitted MC 
+            newCtx.setProperty(Constants.AGGREGATE_CORELATION, synCtx.getMessageID());
+
+            // set the parent properties to the splitted MC
+            newCtx.setTo(synCtx.getTo());
+            newCtx.setReplyTo(synCtx.getReplyTo());
+            newCtx.setSoapAction(synCtx.getSoapAction());
+            newCtx.setWSAAction(synCtx.getWSAAction());
+
+        } catch (AxisFault axisFault) {
+            handleException("Unable to split the message" + axisFault.getMessage(), axisFault);
+        }
+
+        return newCtx;
+    }
+
+    /**
+     * This static util method will be used to enrich the envelope passed, by the element
described
+     * by the XPath over the enricher envelope
+     * 
+     * @param envelope - SOAPEnvelope to be enriched with the content
+     * @param enricher - SOAPEnvelope from which the enriching element will be extracted
+     * @param expression - AXIOMXPath describing the enriching element
+     */
+    public static void enrichEnvelope(SOAPEnvelope envelope,
+                                      SOAPEnvelope enricher, AXIOMXPath expression) {
+        OMElement enrichingElement;
+        Object o = getElements(envelope, expression).get(0);
+        if (o instanceof OMElement && ((OMElement) o).getParent() instanceof OMElement)
{
+            enrichingElement = (OMElement) ((OMElement) o).getParent();
+        } else {
+            enrichingElement = envelope.getBody();
+        }
+        
+        Iterator itr = getElements(enricher, expression).iterator();
+        while (itr.hasNext()) {
+            o = itr.next();
+            if (o != null && o instanceof OMElement) {
+                enrichingElement.addChild((OMElement) o);
+            }
+        }
+        
+    }
+
+    /**
+     * This static util method will be used to clone the SOAPEnvelope passed to the method
+     * 
+     * @param env - SOAPEnvelope to be cloned
+     * @return SOAPEnvelope cloned from env
+     */
+    public static SOAPEnvelope cloneEnvelope(SOAPEnvelope env) {
+
+        SOAPEnvelope envelope;
+        if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
+                env.getBody().getNamespace().getNamespaceURI())) {
+            envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+        } else {
+            envelope = OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope();
+        }
+        
+        Iterator itr = env.getHeader().getChildren();
+        while (itr.hasNext()) {
+            envelope.getHeader().addChild(((OMElement) itr.next()).cloneOMElement());
+        }
+        
+        itr = env.getBody().getChildren();
+        while (itr.hasNext()) {
+            envelope.getBody().addChild(((OMElement) itr.next()).cloneOMElement());
+        }
+        
+        return envelope;
+    }
+
+    /**
+     * Private method to handle exceptions
+     *
+     * @param message - String message to be logged and to be put as the exception message
+     */
+    private static void handleException(String message) {
+        if (log.isDebugEnabled()) {
+            log.debug(message);
+        }
+        throw new SynapseException(message);
+    }
+
+    /**
+     * Private method to handle exceptions
+     *
+     * @param message - String message to be logged and to be put as the exception message
+     * @param e - Cause Exception for this exception
+     */
+    private static void handleException(String message, Exception e) {
+        if (log.isDebugEnabled()) {
+            log.debug(message);
+        }
+        throw new SynapseException(message, e);
+    }
+}

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java?rev=576407&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java
Mon Sep 17 06:04:13 2007
@@ -0,0 +1,139 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.mediators.eip;
+
+import org.apache.synapse.Mediator;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.mediators.base.SequenceMediator;
+
+/**
+ * This class will be a bean which carries the target information for most of the EIP mediators
+ */
+public class Target {
+
+    /**
+     * Holds the to address of the target endpoint
+     */
+    private String to = null;
+
+    /**
+     * Holds the soapAction of the target service
+     */
+    private String soapAction = null;
+
+    /**
+     * Holds the target mediation sequence as an annonymous sequence
+     */
+    private SequenceMediator sequence = null;
+
+    /**
+     * Holds the target mediation sequence as a sequence reference
+     */
+    private String sequenceRef = null;
+
+    /**
+     * Holds the target endpoint to which the message will be sent
+     */
+    private Endpoint endpoint = null;
+
+    /**
+     * Holds the reference to the target endpoint to which the message will be sent
+     */
+    private String endpointRef = null;
+
+    /**
+     * This method will be called by the EIP mediators to mediated the target (may be to
mediate
+     * using the target sequence, send message to the target endpoint or both)
+     * 
+     * @param synCtx - MessageContext to be mediated
+     * @return boolean true if the sequence does not drop the message, false if it does
+     */
+    public boolean mediate(MessageContext synCtx) {
+
+        if (sequence != null) {
+            return sequence.mediate(synCtx);
+        } else if (sequenceRef != null) {
+            Mediator refSequence = synCtx.getConfiguration().getSequence(sequenceRef);
+            if (refSequence != null) {
+                return refSequence.mediate(synCtx);
+            }
+        } else if (endpoint != null) {
+            endpoint.send(synCtx);
+        } else if (endpointRef != null) {
+            Endpoint epr = synCtx.getConfiguration().getEndpoint(endpointRef);
+            if (epr != null) {
+                epr.send(synCtx);
+            }
+        } else {
+            synCtx.getEnvironment().injectMessage(synCtx);
+        }
+
+        return true;
+    }
+
+    public String getTo() {
+        return to;
+    }
+
+    public void setTo(String to) {
+        this.to = to;
+    }
+
+    public String getSoapAction() {
+        return soapAction;
+    }
+
+    public void setSoapAction(String soapAction) {
+        this.soapAction = soapAction;
+    }
+
+    public SequenceMediator getSequence() {
+        return sequence;
+    }
+
+    public void setSequence(SequenceMediator sequence) {
+        this.sequence = sequence;
+    }
+
+    public String getSequenceRef() {
+        return sequenceRef;
+    }
+
+    public void setSequenceRef(String sequenceRef) {
+        this.sequenceRef = sequenceRef;
+    }
+
+    public Endpoint getEndpoint() {
+        return endpoint;
+    }
+
+    public void setEndpoint(Endpoint endpoint) {
+        this.endpoint = endpoint;
+    }
+
+    public String getEndpointRef() {
+        return endpointRef;
+    }
+
+    public void setEndpointRef(String endpointRef) {
+        this.endpointRef = endpointRef;
+    }
+}
\ No newline at end of file

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java?rev=576407&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
Mon Sep 17 06:04:13 2007
@@ -0,0 +1,82 @@
+package org.apache.synapse.mediators.eip.splitter;
+
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.synapse.mediators.eip.EIPUtils;
+import org.apache.synapse.mediators.eip.Target;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.Constants;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.endpoints.Endpoint;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * This mediator will clone the message in to different messages and mediated as specified
in
+ * the target elements.
+ */
+public class CloneMediator extends AbstractMediator {
+
+    private static final Log log = LogFactory.getLog(CloneMediator.class);
+
+    private boolean continueParent = false;
+
+    private List targets = new ArrayList();
+
+    public boolean mediate(MessageContext synCtx) {
+        
+        if (targets.size() != 0) {
+            
+            for (int i=0; i<targets.size(); i++) {
+                MessageContext newContext = getClonedMessageContext(synCtx, i, targets.size());
+                Object o = targets.get(i);
+                
+                if (o instanceof Target) {
+                    Target target = (Target) o;
+                    target.mediate(newContext);
+                }
+            }
+        }
+        
+        return continueParent;
+    }
+
+    private MessageContext getClonedMessageContext(MessageContext synCtx,
+                                                   int messageSequence, int messageCount)
{
+        
+        MessageContext newCtx = EIPUtils.createNewMessageContext(synCtx, synCtx.getEnvelope());
+        newCtx.setProperty(Constants.MESSAGE_SEQUENCE,
+                String.valueOf(messageSequence) + Constants.MESSAGE_SEQUENCE_DELEMITER +
messageCount);
+
+        return newCtx;
+    }
+
+    public boolean isContinueParent() {
+        return continueParent;
+    }
+
+    public void setContinueParent(boolean continueParent) {
+        this.continueParent = continueParent;
+    }
+
+    public List getTargets() {
+        return targets;
+    }
+
+    public void setTargets(List targets) {
+        this.targets = targets;
+    }
+
+    public void addTarget(Target target) {
+        this.targets.add(target);
+    }
+
+}



---------------------------------------------------------------------
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