You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by pz...@apache.org on 2006/06/01 11:28:27 UTC

svn commit: r410809 [4/10] - in /incubator/synapse/tags/M2: ./ bin/ etc/ modules/ modules/core/ modules/core/conf/ modules/core/src/ modules/core/src/org/ modules/core/src/org/apache/ modules/core/src/org/apache/synapse/ modules/core/src/org/apache/syn...

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,111 @@
+/*
+* 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;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.synapse.mediators.MediatorProperty;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * A utility class capable of creating instances of MediatorProperty objects by reading
+ * through a given XML configuration
+ *
+ * <pre>
+ * &lt;element&gt;
+ *    &lt;property name="string" (value="literal" | expression="xpath")/&gt;*
+ * &lt;/element&gt;
+ * </pre>
+ */
+public class MediatorPropertyFactory {
+
+    private static final Log log = LogFactory.getLog(MediatorPropertyFactory.class);
+
+    public static List getMediatorProperties(OMElement elem) {
+
+        List propertyList = new ArrayList();
+
+        Iterator iter = elem.getChildrenWithName(new QName(Constants.NULL_NAMESPACE, "property"));
+        while (iter.hasNext()) {
+
+            OMElement propEle = (OMElement) iter.next();
+            OMAttribute attName  = propEle.getAttribute(MediatorProperty.ATT_NAME_Q);
+            OMAttribute attValue = propEle.getAttribute(MediatorProperty.ATT_VALUE_Q);
+            OMAttribute attExpr  = propEle.getAttribute(MediatorProperty.ATT_EXPR_Q);
+
+            MediatorProperty prop = new MediatorProperty();
+
+            if (attName == null || attName.getAttributeValue() == null ||
+                attName.getAttributeValue().trim().length() == 0) {
+                String msg = "Property name is a required attribute for a Log property";
+                log.error(msg);
+                throw new SynapseException(msg);
+            } else {
+                prop.setName(attName.getAttributeValue());
+            }
+
+            // if a value is specified, use it, else look for an expression
+            if (attValue != null) {
+                if (attValue.getAttributeValue() == null || attValue.getAttributeValue().trim().length() == 0) {
+                    String msg = "Property attribute value (if specified) is required for a Log property";
+                    log.error(msg);
+                    throw new SynapseException(msg);
+                } else {
+                    prop.setValue(attValue.getAttributeValue());
+                }
+
+            } else if (attExpr != null) {
+
+                if (attExpr.getAttributeValue() == null || attExpr.getAttributeValue().trim().length() == 0) {
+                    String msg = "Property attribute expression (if specified) is required for a mediator property";
+                    log.error(msg);
+                    throw new SynapseException(msg);
+
+                } else {
+                    try {
+                        AXIOMXPath xp = new AXIOMXPath(attExpr.getAttributeValue());
+                        Util.addNameSpaces(xp, propEle, log);
+                        prop.setExpression(xp);
+
+                    } catch (JaxenException e) {
+                        String msg = "Invalid XPapth expression : " + attExpr.getAttributeValue();
+                        log.error(msg);
+                        throw new SynapseException(msg, e);
+                    }
+                }
+
+            } else {
+                String msg = "Property attribute value OR expression must be specified for a mediator property";
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+
+            propertyList.add(prop);
+        }
+
+        return propertyList;
+    }
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/OutMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/OutMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/OutMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/OutMediatorFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,47 @@
+/*
+* 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;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.filters.OutMediator;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Creates an Out mediator instance
+ *
+ * <pre>
+ * &lt;out&gt;
+ *    mediator+
+ * &lt;/out&gt;
+ * </pre>
+ */
+public class OutMediatorFactory extends AbstractListMediatorFactory {
+
+    private static final QName IN_Q = new QName(Constants.SYNAPSE_NAMESPACE, "out");
+
+    public Mediator createMediator(OMElement elem) {
+        OutMediator filter = new OutMediator();
+        super.addChildren(elem, filter);
+        return filter;
+    }
+
+    public QName getTagQName() {
+        return IN_Q;
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/PropertyMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/PropertyMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/PropertyMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/PropertyMediatorFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,83 @@
+/*
+* 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;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.builtin.PropertyMediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Creates a set-property mediator through the supplied XML configuration
+ *
+ * <pre>
+ * &lt;set-property name="string" (value="literal" | expression="xpath")/&gt;
+ * </pre>
+ */
+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");
+
+    public Mediator createMediator(OMElement elem) {
+
+        PropertyMediator propMediator = new PropertyMediator();
+        OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
+        OMAttribute expression = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "expression"));
+
+        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";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        propMediator.setName(name.getAttributeValue());
+        if (value != null) {
+            propMediator.setValue(value.getAttributeValue());
+        } else {
+            try {
+                AXIOMXPath xp = new AXIOMXPath(expression.getAttributeValue());
+                Util.addNameSpaces(xp, elem, log);
+                propMediator.setExpression(xp);
+
+            } catch (JaxenException e) {
+                String msg = "Invalid XPath expression for attribute 'expression' : " + expression.getAttributeValue();
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+        }
+
+        return propMediator;
+    }
+
+    public QName getTagQName() {
+        return PROP_Q;
+    }
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import javax.xml.namespace.QName;
+
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.builtin.SendMediator;
+import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.SynapseException;
+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 java.util.Iterator;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * The Send mediator factory parses a Send element and creates an instance of the mediator
+ *
+ * //TODO support endpoints, failover and loadbalacing
+ *
+ * The &lt;send&gt; element is used to send messages out of Synapse to some endpoint. In the simplest case,
+ * the place to send the message to is implicit in the message (via a property of the message itself)-
+ * that is indicated by the following
+ * <pre>
+ *  &lt;send/&gt;
+ * </pre>
+ *
+ * If the message is to be sent to one or more endpoints, then the following is used:
+ * <pre>
+ *  &lt;send&gt;
+ *   (endpointref | endpoint)+
+ *  &lt;/send&gt;
+ * </pre>
+ * where the endpointref token refers to the following:
+ * <pre>
+ * &lt;endpoint ref="name"/&gt;
+ * </pre>
+ * and the endpoint token refers to an anonymous endpoint defined inline:
+ * <pre>
+ *  &lt;endpoint address="url"/&gt;
+ * </pre>
+ * If the message is to be sent to an endpoint selected by load balancing across a set of endpoints,
+ * then it is indicated by the following:
+ * <pre>
+ * &lt;send&gt;
+ *   &lt;load-balance algorithm="uri"&gt;
+ *     (endpointref | endpoint)+
+ *   &lt;/load-balance&gt;
+ * &lt;/send&gt;
+ * </pre>
+ * Similarly, if the message is to be sent to an endpoint with failover semantics, then it is indicated by the following:
+ * <pre>
+ * &lt;send&gt;
+ *   &lt;failover&gt;
+ *     (endpointref | endpoint)+
+ *   &lt;/failover&gt;
+ * &lt;/send&gt;
+ * </pre>
+ */
+public class SendMediatorFactory extends AbstractMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SendMediatorFactory.class);
+
+    private static final QName SEND_Q = new QName(Constants.SYNAPSE_NAMESPACE, "send");
+
+    private static final QName ATT_REF_Q = new QName(Constants.NULL_NAMESPACE, "ref");
+    private static final QName ATT_ADDRESS_Q = new QName(Constants.NULL_NAMESPACE, "address");
+
+    public Mediator createMediator(OMElement elem) {
+
+        SendMediator sm =  new SendMediator();
+
+        Iterator iter = elem.getChildrenWithName(new QName(Constants.SYNAPSE_NAMESPACE, "endpoint"));
+        while (iter.hasNext()) {
+
+            OMElement endptElem = (OMElement) iter.next();
+            OMAttribute ref = endptElem.getAttribute(ATT_REF_Q);
+            OMAttribute address = endptElem.getAttribute(ATT_ADDRESS_Q);
+
+            Endpoint endpt = new Endpoint();
+            if (ref != null) {
+                endpt.setRef(ref.getAttributeValue());
+            } else if (address != null) {
+                try {
+                    endpt.setAddress(new URL(address.getAttributeValue()));
+                } catch (MalformedURLException e) {
+                    String msg = "Invalid endpoint address : " + address.getAttributeValue();
+                    log.error(msg, e);
+                    throw new SynapseException(msg, e);
+                }
+            } else {
+                String msg = "An endpoint used within a send mediator definition must contain a " +
+                    "'ref' (reference) or 'address' (absolute URL) attribute";
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+
+            sm.addEndpoint(endpt);
+        }
+
+        return sm;
+    }
+
+    public QName getTagQName() {
+        return SEND_Q;
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SequenceMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SequenceMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SequenceMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SequenceMediatorFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,77 @@
+/*
+* 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;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Builds an instance of a Sequence mediator through the Synapse configuration. It follows the following
+ *
+ * <pre>
+ * &lt;sequence name="string"&gt;
+ *   mediator+
+ * &lt;/sequence&gt;
+ * </pre>
+ *
+ * OR
+ *
+ * <pre>
+ * &lt;sequence ref="name"/&gt;
+ * </pre>
+ */
+public class SequenceMediatorFactory extends AbstractListMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SequenceMediatorFactory.class);
+
+    private static final QName SEQUENCE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "sequence");
+
+    public QName getTagQName() {
+        return SEQUENCE_Q;
+    }
+
+    public Mediator createMediator(OMElement elem) {
+
+        SequenceMediator seqMediator = new SequenceMediator();
+
+        OMAttribute n = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        if (n != null) {
+            seqMediator.setName(n.getAttributeValue());
+            super.addChildren(elem, seqMediator);
+
+        } else {
+            n = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "ref"));
+            if (n != null) {
+                seqMediator.setRef(n.getAttributeValue());
+                
+            } else {
+                String msg = "A sequence mediator should be a named sequence or a reference to another sequence " +
+                    "(i.e. a name attribute or ref attribute is required.";
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+        }
+        return seqMediator;
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,47 @@
+/*
+* 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;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.filters.SwitchCaseMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Create an instance of a Switch mediators' default case (i.e. a SwitchCaseMedaitor
+ * which returns isDefault() true
+ */
+public class SwitchCaseDefaultMediatorFactory extends AbstractListMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SwitchCaseDefaultMediatorFactory.class);
+
+    private final QName SWITCH_CASE_DEFAULT_Q = new QName(Constants.SYNAPSE_NAMESPACE, "default");
+
+    public Mediator createMediator(OMElement elem) {
+
+        SwitchCaseMediator switchCaseMediator = new SwitchCaseMediator();
+        switchCaseMediator.setDefaultCase(true);
+        super.addChildren(elem, switchCaseMediator);
+        return switchCaseMediator;
+    }
+
+    public QName getTagQName() {
+        return SWITCH_CASE_DEFAULT_Q;
+    }
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,61 @@
+/*
+* 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;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.filters.SwitchCaseMediator;
+import org.apache.synapse.SynapseException;
+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;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+public class SwitchCaseMediatorFactory extends AbstractListMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SwitchCaseMediatorFactory.class);
+
+    private final QName SWITCH_CASE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "case");
+
+    public Mediator createMediator(OMElement elem) {
+
+        SwitchCaseMediator switchCaseMediator = new SwitchCaseMediator();
+        OMAttribute regex = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "regex"));
+        if (regex == null) {
+            String msg = "The 'regex' attribute is required for a switch case definition";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        try {
+            switchCaseMediator.setRegex(Pattern.compile(regex.getAttributeValue()));
+        } catch (PatternSyntaxException pse) {
+            String msg = "Invalid Regular Expression for attribute 'regex' : " + regex.getAttributeValue();
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+
+        super.addChildren(elem, switchCaseMediator);
+        return switchCaseMediator;
+    }
+
+    public QName getTagQName() {
+        return SWITCH_CASE_Q;
+    }
+}
\ No newline at end of file

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SwitchMediatorFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,96 @@
+/*
+* 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;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.filters.SwitchMediator;
+import org.apache.synapse.mediators.filters.SwitchCaseMediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * Constructs a Switch mediator instance from the given XML configuration
+ *
+ * <pre>
+ * &lt;switch source="xpath"&gt;
+ *   &lt;case regex="string"&gt;
+ *     mediator+
+ *   &lt;/case&gt;+
+ *   &lt;default&gt;
+ *     mediator+
+ *   &lt;/default&gt;?
+ * &lt;/switch&gt;
+ * </pre>
+ */
+public class SwitchMediatorFactory extends AbstractMediatorFactory {
+
+    private static final Log log = LogFactory.getLog(SwitchMediatorFactory.class);
+
+    private static final QName SWITCH_Q  = new QName(Constants.SYNAPSE_NAMESPACE, "switch");
+    private static final QName CASE_Q    = new QName(Constants.SYNAPSE_NAMESPACE, "case");
+    private static final QName DEFAULT_Q = new QName(Constants.SYNAPSE_NAMESPACE, "default");
+
+    public Mediator createMediator(OMElement elem) {
+
+        SwitchMediator switchMediator = new SwitchMediator();
+
+        OMAttribute source = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "source"));
+        if (source == null) {
+            String msg = "A 'source' XPath attribute is required for a switch mediator";
+            log.error(msg);
+            throw new SynapseException(msg);
+        } else {
+            try {
+                AXIOMXPath sourceXPath = new AXIOMXPath(source.getAttributeValue());
+                Util.addNameSpaces(sourceXPath, elem, log);
+                switchMediator.setSource(sourceXPath);
+
+            } catch (JaxenException e) {
+                String msg = "Invalid XPath for attribute 'source' : " + source.getAttributeValue();
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+        }
+
+        Iterator iter = elem.getChildrenWithName(CASE_Q);
+        while (iter.hasNext()) {
+            switchMediator.addCase((SwitchCaseMediator)
+                MediatorFactoryFinder.getInstance().getMediator((OMElement) iter.next()));
+        }
+
+        iter = elem.getChildrenWithName(DEFAULT_Q);
+        while (iter.hasNext()) {
+            switchMediator.addCase((SwitchCaseMediator)
+                MediatorFactoryFinder.getInstance().getMediator((OMElement) iter.next()));
+            break; // add only the *first* default if multiple are specified, ignore rest if any
+        }
+
+        return switchMediator;
+    }
+
+    public QName getTagQName() {
+        return SWITCH_Q;
+    }
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SynapseMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SynapseMediatorFactory.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SynapseMediatorFactory.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/SynapseMediatorFactory.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+import javax.xml.namespace.QName;
+
+import org.apache.synapse.config.xml.Constants;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.base.SynapseMediator;
+import org.apache.axiom.om.OMElement;
+
+/**
+ * Builds the main mediator (@see SynapseConfiguration) of the Synapse instance
+ *
+ * <pre>
+ * &lt;rules&gt;
+ *   mediator+
+ * &lt;rules&gt;
+ * </pre>
+ */
+public class SynapseMediatorFactory extends AbstractListMediatorFactory {
+
+    private final static QName tagname = new QName(Constants.SYNAPSE_NAMESPACE, "rules");
+
+    public QName getTagQName() {
+        return tagname;
+    }
+
+    public Mediator createMediator(OMElement elem) {
+        SynapseMediator sm = new SynapseMediator();
+        super.addChildren(elem, sm);
+        return sm;
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationBuilder.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,197 @@
+/*
+* 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;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.synapse.mediators.base.SynapseMediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.namespace.QName;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+
+/**
+ * Builds a Synapse Configuration model from an XML input stream.
+ */
+public class XMLConfigurationBuilder {
+
+    private static Log log = LogFactory.getLog(XMLConfigurationBuilder.class);
+    ExtensionFactoryFinder extensionFacFinder = ExtensionFactoryFinder.getInstance();
+
+    public SynapseConfiguration getConfiguration(InputStream is) {
+
+        log.info("Generating the Synapse configuration model by parsing the XML configuration");
+        SynapseConfiguration config = new SynapseConfiguration();
+
+        OMElement root = null;
+        try {
+            root = new StAXOMBuilder(is).getDocumentElement();
+        } catch (XMLStreamException e) {
+            handleException("Error parsing Synapse configuration : " + e.getMessage(), e);
+        }
+        root.build();
+
+        OMContainer definitions = root.getFirstChildWithName(Constants.DEFINITIONS_ELT);
+        if (definitions != null) {
+
+            Iterator iter = definitions.getChildren();
+            while (iter.hasNext()) {
+                Object o = iter.next();
+                if (o instanceof OMElement) {
+                    OMElement elt = (OMElement) o;
+                    if (Constants.SEQUENCE_ELT.equals(elt.getQName())) {
+                        defineSequence(config, elt);
+                    } else if (Constants.ENDPOINT_ELT.equals(elt.getQName())) {
+                        defineEndpoint(config, elt);
+                    } else if (Constants.PROPERTY_ELT.equals(elt.getQName())) {
+                        defineProperty(config, elt);
+                    } else {
+                        defineExtension(config, elt);
+                    }
+                }
+            }
+        }
+
+        OMElement elem = root.getFirstChildWithName(Constants.RULES_ELT);
+        if (elem == null) {
+            handleException("A valid Synapse configuration MUST specify the main mediator using the <rules> element");
+        } else {
+            SynapseMediator sm = (SynapseMediator) MediatorFactoryFinder.getInstance().getMediator(elem);
+            if (sm.getList().isEmpty()) {
+                handleException("Invalid configuration, the main mediator specified by the <rules> element is empty");
+            } else {
+                config.setMainMediator(sm);
+            }
+        }
+
+        if (is != null) {
+            try {
+                is.close();
+            } catch (IOException e) {}
+        }
+
+        return config;
+    }
+
+    /**
+     * <pre>
+     * &lt;set-property name="string" value="string"/&gt;
+     * </pre>
+     * @param elem
+     */
+    private void defineProperty(SynapseConfiguration config, OMElement elem) {
+        OMAttribute name  = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        OMAttribute value = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "value"));
+        if (name == null || value == null) {
+            handleException("The 'name' and 'value' attributes are required");
+        }
+        config.addProperty(name.getAttributeValue(), value.getAttributeValue());
+    }
+
+    /**
+     * <pre>
+     * &lt;sequence name="string&gt;
+     *    Mediator+
+     * &lt;/sequence&gt;
+     * </pre>
+     * @param ele
+     */
+    private void defineSequence(SynapseConfiguration config, OMElement ele) {
+        SequenceMediator seq = (SequenceMediator) MediatorFactoryFinder.getInstance().getMediator(ele);
+        config.addNamedMediator(seq.getName(), seq);
+    }
+
+    /**
+     * Create an endpoint definition digesting an XML fragment
+     *
+     * <pre>
+     * &lt;endpoint name="string" [address="url"]&gt;
+     *    .. extensibility ..
+     * &lt;/endpoint&gt;
+     * </pre>
+     * @param ele the &lt;endpoint&gt; element
+     */
+    private void defineEndpoint(SynapseConfiguration config, OMElement ele) {
+
+        OMAttribute name = ele.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        if (name == null) {
+            handleException("The 'name' attribute is required for a named endpoint definition");
+        } else {
+            Endpoint endpoint = new Endpoint();
+            endpoint.setName(name.getAttributeValue());
+
+            OMAttribute address = ele.getAttribute(new QName(Constants.NULL_NAMESPACE, "address"));
+            if (address != null) {
+                try {
+                    endpoint.setAddress(new URL(address.getAttributeValue()));
+                    config.addNamedEndpoint(endpoint.getName(), endpoint);
+                } catch (MalformedURLException e) {
+                    handleException("Invalid URL specified for 'address' : " + address.getAttributeValue(), e);
+                }
+            }
+        }
+    }
+
+    /**
+     * Digest extensions into Synapse configuration definitions
+     *
+     * An extension *must* have a unique 'name' attribute. The instance
+     * created through the ExtensionFactoryFinder will be set as a
+     * global property into the SynapseConfiguration with this name as
+     * the key.
+     *
+     * e.g. The Spring configuration extension is as follows
+     * <pre>
+     * &lt;configuration name="string" src="string"/&gt;
+     * </pre>
+     *
+     * @param elem the XML element defining the configuration
+     */
+    private void defineExtension(SynapseConfiguration config, OMElement elem) {
+
+        OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+
+        if (name == null) {
+            handleException("The 'name' attribute is required for an extension configuration definition");
+        } else {
+            config.addProperty(name.getAttributeValue(), extensionFacFinder.getExtension(elem));
+        }
+    }
+
+    private void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseException(msg);
+    }
+
+    private void handleException(String msg, Exception e) {
+        log.error(msg, e);
+        throw new SynapseException(msg, e);
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/SynapseEnvironment.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/SynapseEnvironment.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/SynapseEnvironment.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,44 @@
+/*
+* 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.core;
+
+import org.apache.synapse.MessageContext;
+
+/**
+ * The SynapseEnvironment allows access into the the host SOAP engine. It allows
+ * the sending of messages, classloader access etc.
+ */
+public interface SynapseEnvironment {
+
+    /**
+     * This method injects a new message into the Synapse engine. This is used by
+     * the underlying SOAP engine to inject messages into Synapse for mediation.
+     * e.g. The SynapseMessageReceiver used by Axis2 invokes this to inject new messages
+     */
+    public void injectMessage(MessageContext smc);
+
+    /**
+     * Mediators may get access to the relevant classloader through this
+     */
+    public ClassLoader getClassLoader();
+
+    /**
+     * This method allows a message to be sent through the underlying SOAP engine.
+     * <p/>
+     * This will send request messages on (forward), and send the response messages back to the client
+     */
+    public void send(MessageContext smc);
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,185 @@
+/*
+ * 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.core.axis2;
+
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.deployment.util.PhasesInfo;
+import org.apache.axis2.description.*;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.util.UUIDGenerator;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.synapse.Constants;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+
+/**
+ * This is a simple client that handles both in only and in out
+ */
+public class Axis2FlexibleMEPClient {
+
+    public static SOAPEnvelope outEnvelopeConfiguration(MessageContext axisMsgCtx) {
+        SOAPEnvelope env = axisMsgCtx.getEnvelope();
+        SOAPHeader soapHeader = env.getHeader();
+        ArrayList addressingHeaders;
+        if (soapHeader != null) {
+            addressingHeaders = soapHeader.getHeaderBlocksWithNSURI(
+                AddressingConstants.Submission.WSA_NAMESPACE);
+            if (addressingHeaders != null && addressingHeaders.size() != 0) {
+                detachAddressingInformation(addressingHeaders);
+
+            } else {
+                addressingHeaders = soapHeader.getHeaderBlocksWithNSURI(
+                    AddressingConstants.Final.WSA_NAMESPACE);
+                if (addressingHeaders != null && addressingHeaders.size() != 0) {
+                    detachAddressingInformation(addressingHeaders);
+                }
+            }
+        }
+        return env;
+    }
+
+    /**
+     * @param headerInformation
+     */
+    private static void detachAddressingInformation(ArrayList headerInformation) {
+        Iterator iterator = headerInformation.iterator();
+        while (iterator.hasNext()) {
+            SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) iterator.next();
+            headerBlock.detach();
+        }
+
+    }
+
+    // Following code is based on Axis2 Client code.
+    public static MessageContext send(MessageContext axisMsgCtx) throws AxisFault {
+        // In this logic Synapse Work as a Client to a Server
+        // So here this logic should expect 200 ok, 202 ok and 500 internal server error
+        // current state of the code in Synchronus
+
+        // This is the original_configuration_context
+        ConfigurationContext cc = axisMsgCtx.getConfigurationContext();
+        AxisConfiguration ac = cc.getAxisConfiguration();
+        PhasesInfo phasesInfo = ac.getPhasesInfo();
+
+        // setting operation default chains
+        if (ac.getService("__ANONYMOUS_SERVICE__") == null) {
+            // Lets default be OUT_IN
+            OutInAxisOperation outInOperation =
+                new OutInAxisOperation(new QName(
+                    "__OPERATION_OUT_IN__"));
+            AxisService axisAnonymousService =
+                new AxisService("__ANONYMOUS_SERVICE__");
+            axisAnonymousService.addOperation(outInOperation);
+            ac.addService(axisAnonymousService);
+            phasesInfo.setOperationPhases(outInOperation);
+        }
+        ServiceGroupContext sgc = new ServiceGroupContext(cc,
+            (AxisServiceGroup) ac.getService("__ANONYMOUS_SERVICE__").getParent());
+        ServiceContext sc =
+            sgc.getServiceContext(new AxisService("__ANONYMOUS_SERVICE__"));
+
+        MessageContext mc = new MessageContext();
+        mc.setConfigurationContext(sc.getConfigurationContext());
+        ///////////////////////////////////////////////////////////////////////
+        // filtering properties
+        if (axisMsgCtx.getSoapAction() != null)
+            mc.setSoapAction(axisMsgCtx.getSoapAction());
+        if (axisMsgCtx.getWSAAction() != null)
+            mc.setWSAAction(axisMsgCtx.getWSAAction());
+        if (axisMsgCtx.getFrom() != null)
+            mc.setFrom(axisMsgCtx.getFrom());
+        if (axisMsgCtx.getMessageID() != null)
+            mc.setMessageID(axisMsgCtx.getMessageID());
+        else
+            mc.setMessageID(String.valueOf("uuid:"
+                + UUIDGenerator.getUUID()));
+        if (axisMsgCtx.getReplyTo() != null)
+            mc.setReplyTo(axisMsgCtx.getReplyTo());
+        //if (axisMsgCtx.getRelatesTo() != null)
+            //mc.setRelatesTo(axisMsgCtx.getRelatesTo());
+            if (axisMsgCtx.getTo() != null) {
+                mc.setTo(axisMsgCtx.getTo());
+            } else {
+                throw new AxisFault(
+                    "To canno't be null, if null Synapse can't infer the transport");
+            }
+        if (axisMsgCtx.isDoingREST()) {
+            mc.setDoingREST(true);
+        }
+
+        // handling the outbound message with addressing
+        AxisModule module = ac.getModule(new QName(org.apache.axis2.Constants.MODULE_ADDRESSING));
+        if ((axisMsgCtx.getProperty(Constants.ENGAGE_ADDRESSING_IN_MESSAGE) != null) ||
+            (axisMsgCtx.getProperty(
+                Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE) != null)) {
+            if (!ac.getService("__ANONYMOUS_SERVICE__")
+                .isEngaged(module.getName())) {
+                ac.getService("__ANONYMOUS_SERVICE__").engageModule(module, ac);
+            }
+        }
+
+        //TODO; following line needed to be removed
+
+        mc.setEnvelope(outEnvelopeConfiguration(axisMsgCtx));
+
+        AxisOperation axisAnonymousOperation =
+            ac.getService("__ANONYMOUS_SERVICE__")
+                .getOperation(new QName("__OPERATION_OUT_IN__"));
+
+        //Options class from Axis2 holds client side settings
+        Options options = new Options();
+        OperationClient mepClient =
+            axisAnonymousOperation.createClient(sc, options);
+        mepClient.addMessageContext(mc);
+        mepClient.execute(true);
+        MessageContext response = mepClient
+            .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+        response.setProperty(MessageContext.TRANSPORT_OUT,
+            axisMsgCtx.getProperty(MessageContext.TRANSPORT_OUT));
+        response.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
+            axisMsgCtx.getProperty(
+                org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
+
+        // If request is REST we assume the response is REST, so set the
+        // variable
+        response.setDoingREST(axisMsgCtx.isDoingREST());
+        response.setProperty(Constants.ISRESPONSE_PROPERTY, Boolean.TRUE);
+
+        if (ac.getService("__ANONYMOUS_SERVICE__")
+            .isEngaged(module.getName())) {
+            ac.getService("__ANONYMOUS_SERVICE__")
+                .disEngageModule(ac.getModule(module.getName()));
+        }
+        return response;
+    }
+
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContext.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContext.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContext.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContext.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,215 @@
+/*
+* 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.core.axis2;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.Constants;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.RelatesTo;
+import org.apache.axis2.AxisFault;
+import org.apache.axiom.soap.SOAPEnvelope;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+
+public class Axis2MessageContext implements MessageContext {
+
+    private SynapseConfiguration cfg = null;
+    private SynapseEnvironment   env = null;
+    private Map properties = new HashMap();
+
+    /** The Axis2 MessageContext reference */
+    private org.apache.axis2.context.MessageContext axis2MessageContext = null;
+
+    private boolean response = false;
+
+    private boolean faultResponse = false;
+
+    public SynapseConfiguration getConfiguration() {
+        return cfg;
+    }
+
+    public void setConfiguration(SynapseConfiguration cfg) {
+        this.cfg = cfg;
+    }
+
+    public SynapseEnvironment getEnvironment() {
+        return env;
+    }
+
+    public void setEnvironment(SynapseEnvironment env) {
+        this.env = env;
+    }
+
+    public Object getProperty(String key) {
+        Object ret = properties.get(key);
+        if (ret != null) {
+            return ret;
+        } else if (getConfiguration() != null) {
+            return getConfiguration().getProperty(key);
+        } else {
+            return null;
+        }
+    }
+
+    public void setProperty(String key, Object value) {
+        properties.put(key, value);
+    }
+
+    public Set getPropertyKeySet() {
+        return properties.keySet();
+    }
+
+    //--------------------
+    public Axis2MessageContext(org.apache.axis2.context.MessageContext axisMsgCtx,
+                               SynapseConfiguration synCfg, SynapseEnvironment synEnv) {
+        setAxis2MessageContext(axisMsgCtx);
+        cfg = synCfg;
+        env = synEnv;
+    }
+
+    public EndpointReference getFaultTo() {
+        return axis2MessageContext.getFaultTo();
+    }
+
+    public void setFaultTo(EndpointReference reference) {
+        axis2MessageContext.setFaultTo(reference);
+    }
+
+    public EndpointReference getFrom() {
+        return axis2MessageContext.getFrom();
+    }
+
+    public void setFrom(EndpointReference reference) {
+        axis2MessageContext.setFrom(reference);
+    }
+
+    public SOAPEnvelope getEnvelope() {
+        return axis2MessageContext.getEnvelope();
+    }
+
+    public void setEnvelope(SOAPEnvelope envelope) throws AxisFault {
+        axis2MessageContext.setEnvelope(envelope);
+    }
+
+    public String getMessageID() {
+        return axis2MessageContext.getMessageID();
+    }
+
+    public void setMessageID(String string) {
+        axis2MessageContext.setMessageID(string);
+    }
+
+    public RelatesTo getRelatesTo() {
+        return axis2MessageContext.getRelatesTo();
+    }
+
+    public void setRelatesTo(RelatesTo[] reference) {
+        axis2MessageContext.setRelationships(reference);
+    }
+
+    public EndpointReference getReplyTo() {
+        return axis2MessageContext.getReplyTo();
+    }
+
+    public void setReplyTo(EndpointReference reference) {
+        axis2MessageContext.setReplyTo(reference);
+    }
+
+    public EndpointReference getTo() {
+        return axis2MessageContext.getTo();
+    }
+
+    public void setTo(EndpointReference reference) {
+        axis2MessageContext.setTo(reference);
+    }
+
+    public void setWSAAction(String actionURI) {
+        axis2MessageContext.setWSAAction(actionURI);
+    }
+
+    public String getWSAAction() {
+        return axis2MessageContext.getWSAAction();
+    }
+
+    public void setMessageId(String messageID) {
+        axis2MessageContext.setWSAMessageId(messageID);
+    }
+
+    public String getMessageId() {
+        return axis2MessageContext.getMessageID();
+    }
+
+    public String getSoapAction() {
+        return axis2MessageContext.getSoapAction();
+    }
+
+    public void setSoapAction(String string) {
+        axis2MessageContext.setSoapAction(string);
+    }
+
+    public boolean isDoingMTOM() {
+        return axis2MessageContext.isDoingMTOM();
+    }
+
+    public void setDoingMTOM(boolean b) {
+        axis2MessageContext.setDoingMTOM(b);
+    }
+
+    public boolean isDoingREST() {
+        return axis2MessageContext.isDoingREST();
+    }
+
+    public void setDoingREST(boolean b) {
+        axis2MessageContext.setDoingREST(b);
+    }
+
+    public boolean isSOAP11() {
+        return axis2MessageContext.isSOAP11();
+    }
+
+    public void setResponse(boolean b) {
+        response = b;
+        axis2MessageContext.setProperty(Constants.ISRESPONSE_PROPERTY, Boolean.valueOf(b));
+    }
+
+    public boolean isResponse() {
+        return response;
+    }
+
+    public void setFaultResponse(boolean b) {
+        this.faultResponse = b;
+    }
+
+    public boolean isFaultResponse() {
+        return this.faultResponse;
+    }
+
+    public org.apache.axis2.context.MessageContext getAxis2MessageContext() {
+        return axis2MessageContext;
+    }
+
+    public void setAxis2MessageContext(org.apache.axis2.context.MessageContext axisMsgCtx) {
+        this.axis2MessageContext = axisMsgCtx;
+        Boolean resp = (Boolean) axisMsgCtx.getProperty(Constants.ISRESPONSE_PROPERTY);
+        if (resp != null)
+            response = resp.booleanValue();
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContextFinder.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContextFinder.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContextFinder.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContextFinder.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,129 @@
+/*
+ * 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.core.axis2;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Constants;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.config.SynapseConfigurationBuilder;
+import org.apache.synapse.config.SynapseConfiguration;
+
+import java.io.InputStream;
+
+/**
+ * <p/>
+ * The MessageContext needs to be set up and then is used by the SynapseMessageReceiver to inject messages.
+ * This class is used by the SynapseMessageReceiver to find the environment. The env is stored in a Parameter to the Axis2 config
+ */
+public class Axis2MessageContextFinder implements Constants {
+
+    private static Log log = LogFactory.getLog(Axis2MessageContextFinder.class);
+
+    public static MessageContext getSynapseMessageContext(org.apache.axis2.context.MessageContext axisMsgCtx) {
+
+        // we get the configuration on each message from the Axis2 configuration since the Synapse configuration
+        // may be updated externally and thus should not be cached.
+
+        SynapseConfiguration synCfg = getSynapseConfig(axisMsgCtx);
+        SynapseEnvironment   synEnv = getSynapseEnvironment(axisMsgCtx);
+
+        if (synCfg == null || synEnv == null) {
+            initializeSynapse(axisMsgCtx);
+            synCfg = getSynapseConfig(axisMsgCtx);
+            synEnv = getSynapseEnvironment(axisMsgCtx);
+        }
+
+        return new Axis2MessageContext(axisMsgCtx, synCfg, synEnv);
+    }
+
+    /**
+     * Create the SynapseConfiguration and SynapseEnvironment objects and set them into the Axis2 configuration
+     * for reuse
+     * @param mc the current Axis2 message context
+     */
+    private static synchronized void initializeSynapse(org.apache.axis2.context.MessageContext mc) {
+
+        if (getSynapseConfig(mc) != null && getSynapseEnvironment(mc) != null) {
+            // is this a second thread which came in just after initialization?
+            return;
+        }
+
+        log.info("Initializing Synapse...");
+        SynapseConfiguration synCfg = null;
+        AxisConfiguration axisCfg = mc.getConfigurationContext().getAxisConfiguration();
+
+        // if the system property synapse.xml is specified, use it.. else default config
+        String config = System.getProperty(Constants.SYNAPSE_XML);
+        if (config != null) {
+            log.info("System property '" + Constants.SYNAPSE_XML +
+                "' specifies synapse configuration as " + config);
+            synCfg = SynapseConfigurationBuilder.getConfiguration(config);
+        } else {
+            log.warn("System property '" + Constants.SYNAPSE_XML + "' is not specified. Using default configuration");
+            synCfg = SynapseConfigurationBuilder.getDefaultConfiguration();
+        }
+
+        // set the Synapse configuration and environment into the Axis2 configuration
+        Parameter synapseCtxParam = new Parameter(SYNAPSE_CONFIG, null);
+        synapseCtxParam.setValue(synCfg);
+
+        Parameter synapseEnvParam = new Parameter(SYNAPSE_ENV, null);
+        synapseEnvParam.setValue(new Axis2SynapseEnvironment(axisCfg));
+
+        try {
+            axisCfg.addParameter(synapseCtxParam);
+            axisCfg.addParameter(synapseEnvParam);
+
+        } catch (AxisFault e) {
+            handleException(
+                "Could not set parameters '" + SYNAPSE_CONFIG + "' and/or '" + SYNAPSE_ENV +
+                "'to the Axis2 configuration : " + e.getMessage(), e);
+        }
+
+        log.info("Synapse initialized...");
+    }
+
+    private static void handleException(String msg, Exception e) {
+        log.error(msg, e);
+        throw new SynapseException(msg, e);
+    }
+
+    private static SynapseConfiguration getSynapseConfig(org.apache.axis2.context.MessageContext mc) {
+        AxisConfiguration ac = mc.getConfigurationContext().getAxisConfiguration();
+        Parameter synConfigParam = ac.getParameter(SYNAPSE_CONFIG);
+        if (synConfigParam != null) {
+            return (SynapseConfiguration) synConfigParam.getValue();
+        }
+        return null;
+    }
+
+    private static SynapseEnvironment getSynapseEnvironment(org.apache.axis2.context.MessageContext mc) {
+        AxisConfiguration ac = mc.getConfigurationContext().getAxisConfiguration();
+        Parameter synEnvParam = ac.getParameter(SYNAPSE_ENV);
+        if (synEnvParam != null) {
+            return (SynapseEnvironment) synEnvParam.getValue();
+        }
+        return null;
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2Sender.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2Sender.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2Sender.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2Sender.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,107 @@
+/*
+ * 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.core.axis2;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.synapse.Constants;
+import org.apache.synapse.SynapseException;
+
+import java.util.Set;
+import java.util.Iterator;
+
+/**
+ * This class helps the Axis2SynapseEnvironment implement the send method
+ */
+public class Axis2Sender {
+
+    public static void sendOn(org.apache.synapse.MessageContext synapseInMessageContext) {
+
+        try {
+            MessageContext axis2MessageContext = ((Axis2MessageContext) synapseInMessageContext).getAxis2MessageContext();
+            // At any time any QOS is disengaged. It's engaged iff, a flag is
+            // set in execution chain. ex: addressing will be engage in outpath iff ADDRESSING_PROCESSED is set.
+
+            if (synapseInMessageContext.getProperty(Constants.ENGAGE_ADDRESSING_IN_MESSAGE) != null) {
+                axis2MessageContext.setProperty(Constants.ENGAGE_ADDRESSING_IN_MESSAGE, Boolean.TRUE);
+            }
+
+            //Now handle the outbound message with addressing
+            if (synapseInMessageContext.getProperty(Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE) != null) {
+                axis2MessageContext.setProperty(Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE, Boolean.TRUE);
+            }
+
+            MessageContext axisOutMsgContext = Axis2FlexibleMEPClient.send(axis2MessageContext);
+
+            // run all rules on response
+            synapseInMessageContext.setResponse(true);
+            axisOutMsgContext.setServerSide(true);
+            axisOutMsgContext.setProperty(
+                MessageContext.TRANSPORT_OUT,
+                axis2MessageContext.getProperty(MessageContext.TRANSPORT_OUT));
+
+            axisOutMsgContext.setTransportIn(
+                axis2MessageContext.getTransportIn());
+
+            // create the synapse message context for the response
+            org.apache.synapse.MessageContext synapseOutMessageContext =
+                new Axis2MessageContext(
+                    axisOutMsgContext,
+                    synapseInMessageContext.getConfiguration(),
+                    synapseInMessageContext.getEnvironment());
+
+            // now set properties to co-relate to the request i.e. copy over
+            // correlate/* messgae properties from original message to response received
+            Iterator iter = synapseInMessageContext.getPropertyKeySet().iterator();
+            while (iter.hasNext()) {
+                Object key = iter.next();
+                if (key instanceof String && ((String)key).startsWith(Constants.CORRELATE)) {
+                    synapseOutMessageContext.setProperty(
+                        (String) key,
+                        synapseInMessageContext.getProperty((String) key)
+                    );
+                }
+            }
+
+
+            // send the response message through the synapse mediation flow
+            synapseInMessageContext.getEnvironment().injectMessage(synapseOutMessageContext);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new SynapseException(e);
+        }
+    }
+
+    public static void sendBack(org.apache.synapse.MessageContext smc) {
+
+        MessageContext messageContext = ((Axis2MessageContext) smc).getAxis2MessageContext();
+
+        AxisEngine ae = new AxisEngine(messageContext.getConfigurationContext());
+        try {
+            messageContext.setProperty(Constants.ISRESPONSE_PROPERTY, Boolean.TRUE);
+            // check for addressing is alredy engaged for this message.
+            // if engage we should use the address enable Configuraion context.
+            ae.send(messageContext);
+
+        } catch (AxisFault e) {
+            throw new SynapseException(e);
+        }
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,80 @@
+/*
+ * 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.core.axis2;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.axis2.engine.AxisConfiguration;
+
+/**
+ * <p> This is the Axis2 implementation of the MessageContext
+ */
+public class Axis2SynapseEnvironment implements SynapseEnvironment {
+
+    private ClassLoader cl = null;
+    /** If synapse is initialized by the SynapseAxis2Interceptor, the Axis2
+     * class loaders were not initialized properly at init time. Hence in such
+     * a case, the axisCfg would be set to refer to the Axis configuration
+     * from which the correct and properly initialized classloader could be picked
+     * up at runtime. This would be used only if the explicit classloader referrenced
+     * by "cl" is null (i.e. has not been set) and the axisCfg is available.
+     */
+    private AxisConfiguration axisCfg = null;
+    private static final Log log = LogFactory.getLog(Axis2SynapseEnvironment.class);
+
+    public Axis2SynapseEnvironment() {
+        super();
+    }
+
+    public Axis2SynapseEnvironment(ClassLoader cl) {
+        super();
+        this.cl = cl;
+    }
+
+    public Axis2SynapseEnvironment(AxisConfiguration axisCfg) {
+        super();
+        this.axisCfg = axisCfg;
+    }
+
+    public void injectMessage(MessageContext synCtx) {
+        synCtx.setEnvironment(this);
+        synCtx.getConfiguration().getMainMediator().mediate(synCtx);
+    }
+
+    public void send(MessageContext synCtx) {
+        if (synCtx.isResponse())
+            Axis2Sender.sendBack(synCtx);
+        else
+            Axis2Sender.sendOn(synCtx);
+    }
+
+    public ClassLoader getClassLoader() {
+        if (cl != null) {
+            return cl;
+        } else if (axisCfg != null) {
+            axisCfg.getServiceClassLoader();
+        }
+        return null;
+    }
+
+    public void setClassLoader(ClassLoader cl) {
+        this.cl = cl;
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/DynamicAxisOperation.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/DynamicAxisOperation.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/DynamicAxisOperation.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/DynamicAxisOperation.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,172 @@
+/*
+ * 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.core.axis2;
+
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.*;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.synapse.SynapseException;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+
+/**
+ * DynamicAxisOperation which switch dynamically between MEPs
+ */
+public class DynamicAxisOperation extends InOutAxisOperation {
+    public DynamicAxisOperation() {
+        super();
+    }
+
+    public DynamicAxisOperation(QName name) {
+        super(name);
+    }
+
+    public void addMessageContext(MessageContext msgContext,
+                                  OperationContext opContext) throws AxisFault {
+        HashMap mep = opContext.getMessageContexts();
+        MessageContext immsgContext = (MessageContext) mep
+            .get(MESSAGE_LABEL_IN_VALUE);
+        MessageContext outmsgContext = (MessageContext) mep
+            .get(MESSAGE_LABEL_OUT_VALUE);
+
+        if ((immsgContext != null) && (outmsgContext != null)) {
+            throw new AxisFault(
+                "Invalid message addition , operation context completed");
+        }
+
+        if (outmsgContext == null) {
+            mep.put(MESSAGE_LABEL_OUT_VALUE, msgContext);
+        } else {
+            mep.put(MESSAGE_LABEL_IN_VALUE, msgContext);
+            opContext.setComplete(true);
+        }
+    }
+
+
+    public OperationClient createClient(ServiceContext sc, Options options) {
+        return new DynamicOperationClient(this, sc, options);
+    }
+
+}
+
+class DynamicOperationClient implements OperationClient {
+    private DynamicAxisOperation axisOp;
+    private ServiceContext sc;
+    private OperationContext oc;
+    private Options options;
+
+    public DynamicOperationClient(DynamicAxisOperation axisOp, ServiceContext sc, Options options) {
+        this.options = options;
+        this.axisOp = axisOp;
+        this.sc = sc;
+        this.oc = new OperationContext(axisOp, sc);
+        this.oc.setParent(this.sc);
+    }
+
+    public void setOptions(Options options) {
+        // Not supported
+    }
+
+    public Options getOptions() {
+        throw new SynapseException("Not Supported");
+    }
+
+    public void addMessageContext(MessageContext mc) throws AxisFault {
+        mc.setServiceContext(sc);
+        axisOp.registerOperationContext(mc, oc);
+    }
+
+    public MessageContext getMessageContext(String messageLabel) throws AxisFault {
+        return oc.getMessageContext(messageLabel);
+    }
+
+    public void setCallback(Callback callback) {
+        // Not supported
+    }
+
+    public void execute(boolean block) throws AxisFault {
+        if (block) {
+            ConfigurationContext cc = sc.getConfigurationContext();
+
+            // copy interesting info from options to message context.
+            MessageContext mc = oc
+                .getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+            if (mc == null) {
+                throw new AxisFault(
+                    "Out message context is null ,"
+                        + " please set the out message context before calling this method");
+            }
+
+            EndpointReference toEPR = mc.getTo();
+
+            TransportOutDescription transportOut = ClientUtils.inferOutTransport(cc
+                .getAxisConfiguration(), toEPR, mc);
+            mc.setTransportOut(transportOut);
+
+            /*
+            Options need to Infer TransportInDescription
+            */
+            if (mc.getTransportIn() == null) {
+                TransportInDescription transportIn = options.getTransportIn();
+                if (transportIn == null) {
+                    mc.setTransportIn(ClientUtils.inferInTransport(cc
+                        .getAxisConfiguration(), options, mc));
+                } else {
+                    mc.setTransportIn(transportIn);
+                }
+            }
+
+            if (mc.getSoapAction() == null || "".equals(mc.getSoapAction())) {
+                Parameter soapaction = axisOp.getParameter(AxisOperation.SOAP_ACTION);
+                if (soapaction != null) {
+                    mc.setSoapAction((String) soapaction.getValue());
+                }
+            }
+
+            oc.addMessageContext(mc);
+            // ship it out
+            AxisEngine engine = new AxisEngine(cc);
+            engine.send(mc);
+        }
+
+    }
+
+    public OperationContext getOperationContext() {
+        return oc;
+    }
+
+    public void reset() throws AxisFault {
+        // Not supported
+    }
+
+    public void complete(MessageContext msgCtxt) throws AxisFault {
+        // Not supported
+    }
+
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/EmptyMessageReceiver.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/EmptyMessageReceiver.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/EmptyMessageReceiver.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/EmptyMessageReceiver.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,34 @@
+/*
+ * 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.core.axis2;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.synapse.Constants;
+
+/**
+ * <p>Does nothing! Used as an endpoint so we can engage modules
+ */
+public class EmptyMessageReceiver implements MessageReceiver {
+
+    public void receive(MessageContext mc) throws AxisFault {
+        mc.setProperty(Constants.MEDIATOR_RESPONSE_PROPERTY, Boolean
+            .valueOf(true));
+    }
+
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/SynapseAxis2Interceptor.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/SynapseAxis2Interceptor.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/SynapseAxis2Interceptor.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/SynapseAxis2Interceptor.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,120 @@
+/*
+* 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.core.axis2;
+
+import org.apache.axis2.engine.AxisObserver;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.AxisEvent;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.AxisFault;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Constants;
+import org.apache.synapse.config.SynapseConfigurationBuilder;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+/**
+ * The Synapse Axis2 interceptor will be invoked by Axis2 upon Axis initialization.
+ * This allows the Synapse engine to be initialized at Axis2 startup, and store the
+ * initial Synapse configuration into the AxisConfiguration for subsequent lookup.
+ */
+public class SynapseAxis2Interceptor implements AxisObserver, Constants {
+
+    private static final Log log = LogFactory.getLog(SynapseAxis2Interceptor.class);
+
+    /**
+     * This is where Synapse is initialized at Axis2 startup
+     * @param axisCfg the Axis2 Configuration
+     */
+    public void init(AxisConfiguration axisCfg) {
+
+        log.info("Initializing Synapse...");
+
+        SynapseConfiguration synCfg = null;
+
+        // if the system property synapse.xml is specified, use it.. else default config
+        String config = System.getProperty(Constants.SYNAPSE_XML);
+        if (config != null) {
+            log.info("System property '" + Constants.SYNAPSE_XML +
+                "' specifies synapse configuration as " + config);
+            synCfg = SynapseConfigurationBuilder.getConfiguration(config);
+        } else {
+            log.warn("System property '" + Constants.SYNAPSE_XML + "' is not specified. Using default configuration");
+            synCfg = SynapseConfigurationBuilder.getDefaultConfiguration();
+        }
+
+        // set the Synapse configuration and environment into the Axis2 configuration
+        Parameter synapseCtxParam = new Parameter(SYNAPSE_CONFIG, null);
+        synapseCtxParam.setValue(synCfg);
+
+        Parameter synapseEnvParam = new Parameter(SYNAPSE_ENV, null);
+        synapseEnvParam.setValue(new Axis2SynapseEnvironment(axisCfg));
+
+        try {
+            axisCfg.addParameter(synapseCtxParam);
+            axisCfg.addParameter(synapseEnvParam);
+
+        } catch (AxisFault e) {
+            handleException(
+                "Could not set parameters '" + SYNAPSE_CONFIG + "' and/or '" + SYNAPSE_ENV +
+                "'to the Axis2 configuration : " + e.getMessage(), e);
+        }
+
+        log.info("Synapse initialized...");
+    }
+
+    private void handleException(String msg, Exception e) {
+        log.error(msg, e);
+        throw new SynapseException(msg, e);
+    }
+
+    //---------------------------------------------------------------------------------------
+    public void serviceUpdate(AxisEvent axisEvent, AxisService axisService) {
+    }
+
+    public void moduleUpdate(AxisEvent axisEvent, AxisModule axisModule) {
+    }
+
+    public void addParameter(Parameter parameter) throws AxisFault {
+    }
+
+    public void removeParameter(Parameter parameter) throws AxisFault {
+    }
+
+    public void deserializeParameters(OMElement elem) throws AxisFault {
+    }
+
+    public Parameter getParameter(String string) {
+        return null;
+    }
+
+    public ArrayList getParameters() {
+        return null;
+    }
+
+    public boolean isParameterLocked(String string) {
+        return false;
+    }
+}

Added: incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java?rev=410809&view=auto
==============================================================================
--- incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java (added)
+++ incubator/synapse/tags/M2/modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java Thu Jun  1 02:28:13 2006
@@ -0,0 +1,60 @@
+/*
+ * 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.core.axis2;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.HandlerDescription;
+import org.apache.axis2.engine.AbstractDispatcher;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This is the Axis2 Dispatcher which is registered with the Axis2 engine. It dispatches
+ * each and every message received to the SynapseMessageReceiver for processing.
+ */
+public class SynapseDispatcher extends AbstractDispatcher {
+
+    private static final Log log = LogFactory.getLog(SynapseDispatcher.class);
+
+    private static final long serialVersionUID = -6970206989111592645L;
+
+    private static final String SYNAPSE_SERVICE_NAME = "synapse";
+
+    private static final QName MEDIATE_OPERATION_NAME = new QName("mediate");
+
+    public void initDispatcher() {
+        QName qn = new QName("http://synapse.apache.org", "SynapseDispatcher");
+        HandlerDescription hd = new HandlerDescription(qn);
+        super.init(hd);
+    }
+
+    public AxisService findService(MessageContext mc) throws AxisFault {
+        AxisConfiguration ac = mc.getConfigurationContext().getAxisConfiguration();
+        AxisService as = ac.getService(SYNAPSE_SERVICE_NAME);
+        return as;
+    }
+
+    public AxisOperation findOperation(AxisService svc, MessageContext mc) throws AxisFault {
+        AxisOperation ao = svc.getOperation(MEDIATE_OPERATION_NAME);
+        return ao;
+    }
+}



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