You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by sa...@apache.org on 2006/05/08 15:16:08 UTC

svn commit: r405043 [3/4] - in /incubator/synapse/trunk/java: ./ bin/ etc/ modules/core/ modules/core/src/org/apache/synapse/ modules/core/src/org/apache/synapse/api/ modules/core/src/org/apache/synapse/axis2/ modules/core/src/org/apache/synapse/config...

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/DynamicAxisOperation.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/DynamicAxisOperation.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/DynamicAxisOperation.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/DynamicAxisOperation.java Mon May  8 06:15:47 2006
@@ -14,29 +14,23 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.axis2;
+package org.apache.synapse.core.axis2;
 
 
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.context.ServiceContext;
-import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.wsdl.WSDLConstants;
-import org.apache.axis2.engine.AxisEngine;
 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.description.AxisOperation;
-import org.apache.axis2.description.ClientUtils;
-import org.apache.axis2.description.InOutAxisOperation;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.description.TransportOutDescription;
+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;
 
@@ -56,13 +50,13 @@
                                   OperationContext opContext) throws AxisFault {
         HashMap mep = opContext.getMessageContexts();
         MessageContext immsgContext = (MessageContext) mep
-                .get(MESSAGE_LABEL_IN_VALUE);
+            .get(MESSAGE_LABEL_IN_VALUE);
         MessageContext outmsgContext = (MessageContext) mep
-                .get(MESSAGE_LABEL_OUT_VALUE);
+            .get(MESSAGE_LABEL_OUT_VALUE);
 
         if ((immsgContext != null) && (outmsgContext != null)) {
             throw new AxisFault(
-                    "Invalid message addition , operation context completed");
+                "Invalid message addition , operation context completed");
         }
 
         if (outmsgContext == null) {
@@ -75,7 +69,7 @@
 
 
     public OperationClient createClient(ServiceContext sc, Options options) {
-        return new DynamicOperationClient(this,sc,options);
+        return new DynamicOperationClient(this, sc, options);
     }
 
 }
@@ -86,11 +80,11 @@
     private OperationContext oc;
     private Options options;
 
-    public DynamicOperationClient(DynamicAxisOperation axisOp, ServiceContext sc, 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 = new OperationContext(axisOp, sc);
         this.oc.setParent(this.sc);
     }
 
@@ -121,17 +115,17 @@
 
             // copy interesting info from options to message context.
             MessageContext mc = oc
-                    .getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+                .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");
+                    "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);
+                .getAxisConfiguration(), toEPR, mc);
             mc.setTransportOut(transportOut);
 
             /*
@@ -141,7 +135,7 @@
                 TransportInDescription transportIn = options.getTransportIn();
                 if (transportIn == null) {
                     mc.setTransportIn(ClientUtils.inferInTransport(cc
-                            .getAxisConfiguration(), options, mc));
+                        .getAxisConfiguration(), options, mc));
                 } else {
                     mc.setTransportIn(transportIn);
                 }
@@ -161,8 +155,9 @@
         }
 
     }
+
     public OperationContext getOperationContext() {
-    	return oc;
+        return oc;
     }
 
     public void reset() throws AxisFault {

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/EmptyMessageReceiver.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/EmptyMessageReceiver.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/EmptyMessageReceiver.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/EmptyMessageReceiver.java Mon May  8 06:15:47 2006
@@ -14,24 +14,21 @@
  * limitations under the License.
  */
 
-package org.apache.synapse.axis2;
+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));
-	}
+    public void receive(MessageContext mc) throws AxisFault {
+        mc.setProperty(Constants.MEDIATOR_RESPONSE_PROPERTY, Boolean
+            .valueOf(true));
+    }
 
 }

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java Mon May  8 06:15:47 2006
@@ -13,9 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.synapse.axis2;
-
-import javax.xml.namespace.QName;
+package org.apache.synapse.core.axis2;
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
@@ -25,39 +23,38 @@
 import org.apache.axis2.engine.AbstractDispatcher;
 import org.apache.axis2.engine.AxisConfiguration;
 
+import javax.xml.namespace.QName;
+
 /**
- *
- * 
  * This sends every message to the SynapseMessageReceiver so that it can pass them to Synapse
- *
  */
 public class SynapseDispatcher extends AbstractDispatcher {
-	// FOR EVERY REQUEST - ALWAYS DISPATH TO THE SYNAPSE SERVICE
+    // FOR EVERY REQUEST - ALWAYS DISPATH TO THE SYNAPSE SERVICE
 
-	private static final long serialVersionUID = -6970206989111592645L;
+    private static final long serialVersionUID = -6970206989111592645L;
 
-	private static final String SYNAPSE_SERVICE_NAME = "synapse";
+    private static final String SYNAPSE_SERVICE_NAME = "synapse";
 
-	private static final QName MEDIATE_OPERATION_NAME = new QName("mediate");
+    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 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 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 {
+    public AxisOperation findOperation(AxisService svc, MessageContext mc)
+        throws AxisFault {
 
-		AxisOperation ao = svc.getOperation(MEDIATE_OPERATION_NAME);
-		return ao;
-	}
+        AxisOperation ao = svc.getOperation(MEDIATE_OPERATION_NAME);
+        return ao;
+    }
 
 }

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseMessageReceiver.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseMessageReceiver.java?rev=405043&r1=405035&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseMessageReceiver.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/SynapseMessageReceiver.java Mon May  8 06:15:47 2006
@@ -13,41 +13,38 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.synapse.axis2;
+package org.apache.synapse.core.axis2;
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.MessageContext;
-
 import org.apache.axis2.engine.MessageReceiver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseContext;
 import org.apache.synapse.SynapseMessage;
 
 /**
- * <p/>
- * <p/>
- * This is used to "catch" messages in Axis2 and pass them to Synapse for processing.
+ * This message receiver should be configured in the Axis2 configuration as the
+ * default message receiver, which will handle all incoming messages through the
+ * synapse mediation
  */
 public class SynapseMessageReceiver implements MessageReceiver {
 
-    private Log log = LogFactory.getLog(getClass());
+    private static final Log log = LogFactory.getLog(SynapseMessageReceiver.class);
 
     public void receive(MessageContext mc) throws AxisFault {
-        log.debug("receiving message");
-        SynapseEnvironment env = Axis2SynapseEnvironmentFinder
-                .getSynapseEnvironment(mc);
+
+        log.debug("Synapse received message");
+        SynapseContext synCtx = Axis2SynapseContextFinder.getSynapseContext(mc);
         ////////////////////////////////////////////////////////////////////////
-        // SynapseEnvironment is set as a property in MessageContext. This is due
+        // SynapseContext is set as a property in MessageContext. This is due
         // use we can expect in ServiceMediatorProcessor and many extensions yet to come
         // So it a mediator uses EnvironmentAware, that mediator will be injected with the correct environment
-        
+
         ////////////////////////////////////////////////////////////////////////
-        SynapseMessage smc = new Axis2SynapseMessage(mc,env);
-        smc.setSynapseEnvironment(env);
-        env.injectMessage(smc);
+        SynapseMessage smc = new Axis2SynapseMessage(mc, synCtx);
+        synCtx.getSynapseEnvironment().injectMessage(synCtx);
 
         ///////////////////////////////////////////////////////////////////////
         // Response handling mechanism for 200/202 and 5XX
@@ -56,12 +53,12 @@
         // smc.isFaultRespose = true then the response is a fault with 500 Internal Server Error
         if (smc.isResponse()) {
             mc.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN,
-                    Constants.VALUE_TRUE);
+                Constants.VALUE_TRUE);
         }
         if (smc.isFaultResponse()) {
             // todo: a good way to inject faultSoapEnv to the Axis2 Transport 
             throw new AxisFault(
-                    "Synapse Encounters an Error - Please See Log for More Details");
+                "Synapse Encounters an Error - Please See Log for More Details");
         }
         ///////////////////////////////////////////////////////////////////////
     }

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,72 @@
+/*
+ * 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.mediators;
+
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.api.ListMediator;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This class implements the base functionality of a List mediator
+ *
+ * @see ListMediator
+ */
+public abstract class AbstractListMediator extends AbstractMediator implements ListMediator {
+
+    private static final Log log = LogFactory.getLog(AbstractListMediator.class);
+
+    protected List mediators = new ArrayList();
+
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+
+        Iterator it = mediators.iterator();
+        while (it.hasNext()) {
+            Mediator m = (Mediator) it.next();
+            if (!m.mediate(synCtx)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public List getList() {
+        return mediators;
+    }
+
+    public boolean addChild(Mediator m) {
+        return mediators.add(m);
+    }
+
+    public Mediator getChild(int pos) {
+        return (Mediator) mediators.get(pos);
+    }
+
+    public boolean removeChild(Mediator m) {
+        return mediators.remove(m);
+    }
+
+    public Mediator removeChild(int pos) {
+        return (Mediator) mediators.remove(pos);
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,35 @@
+/*
+* 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.mediators;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.api.Mediator;
+
+/**
+ * This class is an abstract Mediator, that defines the logging and debugging
+ * elements of a mediator class.
+ */
+public abstract class AbstractMediator implements Mediator {
+
+    /**
+     * Returns the class name of the mediator
+     * @return the class name of the mediator
+     */
+    public String getType() {
+        return getClass().getSimpleName();
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java Mon May  8 06:15:47 2006
@@ -0,0 +1,71 @@
+/*
+* 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.mediators;
+
+import org.apache.synapse.config.xml.Constants;
+import org.apache.synapse.Util;
+import org.apache.synapse.SynapseContext;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+
+import javax.xml.namespace.QName;
+
+/**
+ * A mediator property is a name-value or name-expression pair which could be supplied
+ * for certain mediators. If expressions are supplied they are evaluated at the runtime
+ * against the current message into literal String values.
+ */
+public class MediatorProperty {
+
+    public static final QName PROPERTY_Q  = new QName(Constants.SYNAPSE_NAMESPACE, "property");
+    public static final QName ATT_NAME_Q  = new QName(Constants.NULL_NAMESPACE, "name");
+    public static final QName ATT_VALUE_Q = new QName(Constants.NULL_NAMESPACE, "value");
+    public static final QName ATT_EXPR_Q  = new QName(Constants.NULL_NAMESPACE, "expression");
+
+    private String name;
+    private String value;
+    private AXIOMXPath expression;
+
+    public MediatorProperty() {}
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public AXIOMXPath getExpression() {
+        return expression;
+    }
+
+    public void setExpression(AXIOMXPath expression) {
+        this.expression = expression;
+    }
+
+    public String getEvaluatedExpression(SynapseContext synCtx) {
+        return Util.getStringValue(expression, synCtx);
+    }
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,78 @@
+/*
+* 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.mediators.base;
+
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.AbstractListMediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The Sequence mediator either refers to another Sequence mediator instance
+ * or is a *Named* list/sequence of other (child) Mediators
+ */
+public class SequenceMediator extends AbstractListMediator {
+
+    private static final Log log = LogFactory.getLog(SequenceMediator.class);
+    private String name = null;
+    private String ref = null;
+
+    /**
+     * If this mediator refers to another named Sequence, execute that. Else
+     * execute the list of mediators (children) contained within this. If a referenced
+     * named sequence mediator instance cannot be found at runtime, an exception is
+     * thrown. This may occur due to invalid configuration of an erroneous runtime
+     * change of the synapse configuration. It is the responsibility of the
+     * SynapseConfiguration builder to ensure that dead references are not present.
+     *
+     * @param synCtx the synapse message
+     * @return as per standard mediator result
+     */
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+        if (ref == null) {
+            return super.mediate(synCtx);
+
+        } else {
+            Mediator m = synCtx.getConfiguration().getNamedMediator(ref);
+            if (m == null) {
+                String msg = "Sequence mediator instance named " + ref + " cannot be found.";
+                log.error(msg);
+                throw new SynapseException(msg);
+            } else {
+                return m.mediate(synCtx);
+            }
+        }
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getRef() {
+        return ref;
+    }
+
+    public void setRef(String ref) {
+        this.ref = ref;
+    }
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java?rev=405043&r1=405042&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java Mon May  8 06:15:47 2006
@@ -16,12 +16,16 @@
 
 package org.apache.synapse.mediators.base;
 
+import org.apache.synapse.mediators.AbstractListMediator;
+
 /**
+ * The SynapseMediator is the "mainmediator" of the synapse engine. It is
+ * given each message on arrival at the synapse engine. The synapse configuration
+ * holds a reference to this special mediator instance. The SynapseMediator
+ * holds the list of mediators supplied within the <rules> element of an XML
+ * based Synapse configuration
  *
- * 
- * This implements the main processor. Delegates to ListProcessor
- * Here in case we need the main <synapse> to do anything special
- *
+ * @see org.apache.synapse.config.SynapseConfiguration#getMainMediator()
  */
 public class SynapseMediator extends AbstractListMediator {
 }

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java?rev=405043&r1=405042&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java Mon May  8 06:15:47 2006
@@ -16,20 +16,29 @@
 
 package org.apache.synapse.mediators.builtin;
 
-import org.apache.synapse.api.Mediator;
-
-import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
- * Implementaion of <drop/>
+ * Halts further processing/mediation of the current message. i.e. returns false
  */
-public class DropMediator implements Mediator  {
-    
-    public boolean mediate(SynapseMessage sm) {
-        if (sm.getTo() == null) {
+public class DropMediator extends AbstractMediator {
+
+    private static final Log log = LogFactory.getLog(LogMediator.class);
+
+    /**
+     * Halts further mediation of the current message by returning false.
+     * @param synCtx the current message
+     * @return false always
+     */
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+        if (synCtx.getSynapseMessage().getTo() == null) {
             return false;
-        }else{
-            sm.setTo(null);
+        } else {
+            synCtx.getSynapseMessage().setTo(null);
             return false;
         }
     }

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java?rev=405043&r1=405042&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java Mon May  8 06:15:47 2006
@@ -16,40 +16,145 @@
 
 package org.apache.synapse.mediators.builtin;
 
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.MediatorProperty;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.synapse.SynapseMessage;
-
-import org.apache.synapse.api.Mediator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
 
 
 /**
- *
- * <p>
- * Logs the message using commons logging
- * 
- * <p>
- * TODO make configurable - short or detailed logs
- *
+ * Logs the specified message into the configured logger. The log levels specify
+ * which attributes would be logged, and is configurable. Additionally custom
+ * properties may be defined to the logger, where literal values or expressions
+ * could be specified for logging. The custom properties are printed into the log
+ * using the defined seperator (\n, "," etc)
  */
-public class LogMediator implements Mediator {
-	
-	private Log log = LogFactory.getLog(getClass());
-
-	public boolean mediate(SynapseMessage smc) {
-		log.info("---------------------------------------");
-		if (smc.getTo() != null)
-			log.info("To: " + smc.getTo().getAddress());
-		if (smc.getFrom() != null)
-			log.info("From: " + smc.getFrom().getAddress());
-		if (smc.getReplyTo() != null)
-			log.info("ReplyTo: " + smc.getReplyTo().getAddress());
-		if (smc.getEnvelope() != null)
-			log.info("Envelope: " + smc.getEnvelope().toString());
-		log.info("---------------------------------------");
-		return true;
-	}
+public class LogMediator extends AbstractMediator {
+
+    private static final Log log = LogFactory.getLog(LogMediator.class);
 
+    public static final int CUSTOM = 0;
+    public static final int SIMPLE = 1;
+    public static final int HEADERS = 2;
+    public static final int FULL = 3;
+
+    private int logLevel = SIMPLE;
+    private String SEP = ", ";
+    private List properties = new ArrayList();
+
+    /**
+     * Logs the current message according to the supplied semantics
+     * @param synCtx (current) message to be logged
+     * @return true always
+     */
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+        log.info(getLogMessage(synCtx));
+        return true;
+    }
+
+    private String getLogMessage(SynapseContext synCtx) {
+        switch (logLevel) {
+            case CUSTOM:
+                return getCustomLogMessage(synCtx);
+            case SIMPLE:
+                return getSimpleLogMessage(synCtx);
+            case HEADERS:
+                return getHeadersLogMessage(synCtx);
+            case FULL:
+                return getFullLogMessage(synCtx);
+            default:
+                return "Invalid log level specified";
+        }
+    }
+
+    private String getCustomLogMessage(SynapseContext synCtx) {
+        StringBuffer sb = new StringBuffer();
+        setCustomProperties(sb, synCtx);
+        return sb.toString();
+    }
+
+    private String getSimpleLogMessage(SynapseContext synCtx) {
+        SynapseMessage synMsg = synCtx.getSynapseMessage();
+        StringBuffer sb = new StringBuffer();
+        if (synMsg.getTo() != null)
+            sb.append("To: " + synMsg.getTo().getAddress());
+        if (synMsg.getFrom() != null)
+            sb.append(SEP + "From: " + synMsg.getFrom().getAddress());
+        if (synMsg.getWSAAction() != null)
+            sb.append(SEP + "WSAction: " + synMsg.getWSAAction());
+        if (synMsg.getSoapAction() != null)
+            sb.append(SEP + "SOAPAction: " + synMsg.getSoapAction());
+        if (synMsg.getReplyTo() != null)
+            sb.append(SEP + "ReplyTo: " + synMsg.getReplyTo().getAddress());
+        if (synMsg.getMessageID() != null)
+            sb.append(SEP + "MessageID: " + synMsg.getMessageID());
+        setCustomProperties(sb, synCtx);
+        return sb.toString();
+    }
+
+    private String getHeadersLogMessage(SynapseContext synCtx) {
+        SynapseMessage synMsg = synCtx.getSynapseMessage();
+        StringBuffer sb = new StringBuffer();
+        Iterator iter = synMsg.getEnvelope().getHeader().examineAllHeaderBlocks();
+        while (iter.hasNext()) {
+            SOAPHeader header = (SOAPHeader) iter.next();
+            sb.append(SEP + header.getLocalName() + " : " + header.getText());
+        }
+        setCustomProperties(sb, synCtx);
+        return sb.toString();
+    }
+
+    private String getFullLogMessage(SynapseContext synCtx) {
+        SynapseMessage synMsg = synCtx.getSynapseMessage();
+        StringBuffer sb = new StringBuffer();
+        sb.append(getSimpleLogMessage(synCtx));
+        if (synMsg.getEnvelope() != null)
+            sb.append(SEP + "Envelope: " + synMsg.getEnvelope());
+        setCustomProperties(sb, synCtx);
+        return sb.toString();
+    }
+
+    private void setCustomProperties(StringBuffer sb, SynapseContext synCtx) {
+        if (properties != null && !properties.isEmpty()) {
+            Iterator iter = properties.iterator();
+            while (iter.hasNext()) {
+                MediatorProperty prop = (MediatorProperty) iter.next();
+                sb.append(SEP + prop.getName() + " = " +
+                    (prop.getValue() != null ? prop.getValue() : prop.getEvaluatedExpression(synCtx)));
+            }
+        }
+    }
+
+    public int getLogLevel() {
+        return logLevel;
+    }
+
+    public void setLogLevel(int logLevel) {
+        this.logLevel = logLevel;
+    }
+
+    public String getSeperator() {
+        return SEP;
+    }
+
+    public void setSeperator(String SEP) {
+        this.SEP = SEP;
+    }
+
+    public void addProperty(MediatorProperty p) {
+        properties.add(p);
+    }
+
+    public void addAllProperties(List list) {
+        properties.addAll(list);
+    }
 
 }

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/PropertyMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/PropertyMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/PropertyMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/PropertyMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,68 @@
+/*
+* 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.mediators.builtin;
+
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.Util;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+
+/**
+ * The property mediator would save a named property as a local property
+ * of the Synapse Message Context. Properties set this way could be
+ * extracted through the XPath extension function "synapse:get-property(prop-name)"
+ */
+public class PropertyMediator extends AbstractMediator {
+
+    private String name = null;
+    private String value = null;
+    private AXIOMXPath expression = null;
+
+    /**
+     * Sets a property into the current (local) Synapse Context
+     * @param smc the message context
+     * @return true always
+     */
+    public boolean mediate(SynapseContext smc) {
+        smc.setProperty(getName(),
+            (value != null ? getValue() : Util.getStringValue(getExpression(), smc)));
+        return true;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public AXIOMXPath getExpression() {
+        return expression;
+    }
+
+    public void setExpression(AXIOMXPath expression) {
+        this.expression = expression;
+    }
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java?rev=405043&r1=405042&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java Mon May  8 06:15:47 2006
@@ -16,31 +16,34 @@
 
 package org.apache.synapse.mediators.builtin;
 
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.mediators.AbstractMediator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.api.Mediator;
-import org.apache.synapse.SynapseMessage;
 
 /**
- *
- * <p>
- * 
- * This sends the message on (or back)
- *
+ * The Send mediator sends the message using the following semantics.
+ * <p/>
+ * This is a leaf mediator (i.e. further processing halts after this mediator completes)
+ * <p/>
+ * TODO support endpoints, loadbalancing and failover
  */
-public class SendMediator implements Mediator {
-	
-
-	private Log log = LogFactory.getLog(getClass());
-
-	
-	public boolean mediate(SynapseMessage smc) {
-		log.debug("mediate");
-		smc.getSynapseEnvironment().send(smc);
-		return false;
-
-	}
-
-	
+public class SendMediator extends AbstractMediator {
 
+    private static final Log log = LogFactory.getLog(SendMediator.class);
+    /**
+     * This is a leaf mediator. i.e. processing stops once send is invoked,
+     * as it always returns false
+     *
+     * @param synCtx the current message to be sent
+     * @return false always as this is a leaf mediator
+     */
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+        log.debug("Sending To: " + (synCtx.getSynapseMessage().getTo() != null ?
+            synCtx.getSynapseMessage().getTo().getAddress() : "null"));
+        log.debug("Body : \n" + synCtx.getSynapseMessage().getEnvelope());
+        synCtx.getSynapseEnvironment().send(synCtx);
+        return false;
+    }
 }

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,198 @@
+/*
+* 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.mediators.builtin;
+
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.AbstractListMediator;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseMessage;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+import org.jaxen.JaxenException;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLOutputFactory;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * Validate a message or an element against a schema
+ */
+public class ValidateMediator extends AbstractListMediator {
+
+    private static final Log log = LogFactory.getLog(ValidateMediator.class);
+
+    private String schemaUrl = null;
+    private AXIOMXPath source = null;
+
+    private static final String SCHEMA_LOCATION_NO_NS =
+        "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
+    private static final String SCHEMA_LOCATION_NS =
+        "http://apache.org/xml/properties/schema/external-schemaLocation";
+    private static final String FULL_CHECKING = "http://apache.org/xml/features/validation/schema-full-checking";
+    private static final String SCHEMA_VALIDATION = "http://apache.org/xml/features/validation/schema";
+    private static final String VALIDATION = "http://xml.org/sax/features/validation";
+
+    public String getSchemaUrl() {
+        return schemaUrl;
+    }
+
+    public void setSchemaUrl(String schemaUrl) {
+        this.schemaUrl = schemaUrl;
+    }
+
+    public AXIOMXPath getSource() {
+        return source;
+    }
+
+    public void setSource(AXIOMXPath source) {
+        this.source = source;
+    }
+
+    private OMNode getValidateSource(SynapseMessage synMsg) {
+
+        if (source == null) {
+            try {
+                source = new AXIOMXPath("//SOAP-ENV:Body");
+                source.addNamespace("SOAP-ENV", synMsg.isSOAP11() ?
+                    SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI : SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+            } catch (JaxenException e) {}
+        }
+
+        try {
+            Object o = source.evaluate(synMsg.getEnvelope());
+            if (o instanceof OMNode) {
+                return (OMNode) o;
+            } else if (o instanceof List && !((List) o).isEmpty()) {
+                return (OMNode) ((List) o).get(0);  // Always fetches *only* the first
+            } else {
+                String msg = "The evaluation of the XPath expression " + source + " must result in an OMNode";
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+
+        } catch (JaxenException e) {
+            String msg = "Error evaluating XPath " + source + " on message";
+            log.error(msg);
+            throw new SynapseException(msg, e);
+        }
+    }
+
+    public boolean mediate(SynapseContext synCtx) {
+
+        ByteArrayInputStream baisFromSource = null;
+        StringBuffer nsLocations = new StringBuffer();
+
+        try {
+            // create a byte array output stream and serialize the source node into it
+            ByteArrayOutputStream baosForSource = new ByteArrayOutputStream();
+            XMLStreamWriter xsWriterForSource = XMLOutputFactory.newInstance().createXMLStreamWriter(baosForSource);
+
+            // save the list of defined namespaces for validation against the schema
+            OMNode sourceNode = getValidateSource(synCtx.getSynapseMessage());
+            if (sourceNode instanceof OMElement) {
+                Iterator iter = ((OMElement) sourceNode).getAllDeclaredNamespaces();
+                while (iter.hasNext()) {
+                    OMNamespace omNS = (OMNamespace) iter.next();
+                    nsLocations.append(omNS.getName() + " " + getSchemaUrl());
+                }
+            }
+            sourceNode.serialize(xsWriterForSource);
+            baisFromSource = new ByteArrayInputStream(baosForSource.toByteArray());
+
+        } catch (Exception e) {
+            String msg = "Error accessing source element for validation : " + source;
+            log.error(msg);
+            throw new SynapseException(msg, e);
+        }
+
+        try {
+            SAXParserFactory spFactory = SAXParserFactory.newInstance();
+            spFactory.setNamespaceAware(true);
+            spFactory.setValidating(true);
+            SAXParser parser = spFactory.newSAXParser();
+
+            parser.setProperty(VALIDATION, Boolean.TRUE);
+            parser.setProperty(SCHEMA_VALIDATION, Boolean.TRUE);
+            parser.setProperty(FULL_CHECKING, Boolean.TRUE);
+            parser.setProperty(SCHEMA_LOCATION_NS, nsLocations.toString());
+            parser.setProperty(SCHEMA_LOCATION_NO_NS, getSchemaUrl());
+
+            Validator handler = new Validator();
+            parser.parse(baisFromSource, handler);
+
+            if (handler.isValidationError()) {
+                log.debug("Validation failed :" + handler.getSaxParseException().getMessage());
+                // super.mediate() invokes the "on-fail" sequence of mediators
+                return super.mediate(synCtx);
+            }
+
+        }
+        catch (Exception e) {
+            String msg = "Error validating " + source + " against schema : " + schemaUrl + " : " + e.getMessage();
+            log.error(msg);
+            throw new SynapseException(msg, e);
+        }
+
+        return true;
+    }
+
+    /**
+     * This class handles validation errors to be used for error reporting
+     */
+    private class Validator extends DefaultHandler {
+
+        private boolean validationError = false;
+        private SAXParseException saxParseException = null;
+
+        public void error(SAXParseException exception) throws SAXException {
+            validationError = true;
+            saxParseException = exception;
+        }
+
+        public void fatalError(SAXParseException exception) throws SAXException {
+            validationError = true;
+            saxParseException = exception;
+        }
+
+        public void warning(SAXParseException exception) throws SAXException {
+        }
+
+        public boolean isValidationError() {
+            return validationError;
+        }
+
+        public SAXParseException getSaxParseException() {
+            return saxParseException;
+        }
+    }
+
+}

Copied: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java (from r405035, incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/types/ClassMediator.java)
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java?p2=incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java&p1=incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/types/ClassMediator.java&r1=405035&r2=405043&rev=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/types/ClassMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java Mon May  8 06:15:47 2006
@@ -13,52 +13,100 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.synapse.mediators.ext;
 
-package org.apache.synapse.mediators.types;
-
-
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseContext;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.Util;
 import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.MediatorProperty;
 
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.lang.reflect.Method;
 
 /**
+ * The class mediator delegates the mediation to a new instance of a specified class. The specified class
+ * must implement the Mediator interface
  *
- * 
- * This executes the "mediate" operation on a new instance of the specified class
- * 
- * TODO add support for simple properties to be set
- *
+ * @see Mediator
  */
-public class ClassMediator implements Mediator{
-
-	private Class clazz = null;
+public class ClassMediator extends AbstractMediator {
 
-	
+    private static final Log log = LogFactory.getLog(ClassMediator.class);
 
-	public boolean mediate(SynapseMessage smc) {
-		Mediator m = null;
+    private Class clazz = null;
+    private List properties = new ArrayList();
 
-		try {
-			m = (Mediator) getClazz().newInstance();
-		} catch (Exception e) {
-			throw new SynapseException(e);
-		}
-		/*if (EnvironmentAware.class.isAssignableFrom(m.getClass())) {
-			((EnvironmentAware) m).setSynapseEnvironment(se);
-		}*/
-		return m.mediate(smc);
-
-	}
-
-	
-	public void setClazz(Class clazz) {
-		this.clazz = clazz;
-	}
-
-	public Class getClazz() {
-		return clazz;
-	}
+    /**
+     * Delegate mediation to a new instance of the specified class
+     * @param synCtx the message context
+     * @return as per standard semantics
+     */
+    public boolean mediate(SynapseContext synCtx) {
+
+        log.debug(getType() + " mediate()");
+        Mediator m = null;
+        try {
+            m = (Mediator) clazz.newInstance();
+
+        } catch (Exception e) {
+            String msg = "Error while creating an instance of the specified mediator class : " + clazz.getName();
+            log.error(msg, e);
+            throw new SynapseException(msg, e);
+        }
+
+        setProperties(m, synCtx);
+
+        return m.mediate(synCtx);
+    }
+
+    /**
+     * Only String properties are supported
+     * @param m the mediator
+     */
+    private void setProperties(Mediator m, SynapseContext synCtx) {
+        Iterator iter = properties.iterator();
+        while (iter.hasNext()) {
+            MediatorProperty mProp = (MediatorProperty) iter.next();
+
+            String mName = "set" + Character.toUpperCase(mProp.getName().charAt(0)) + mProp.getName().substring(1);
+            String value = (mProp.getValue() != null ?
+                mProp.getValue() :
+                Util.getStringValue(mProp.getExpression(), synCtx));
+
+
+            try {
+                Method method = m.getClass().getMethod(mName, new Class[] {String.class});
+                method.invoke(m, new Object[] { value });
+
+            } catch (Exception e) {
+                String msg = "Error setting property : " + mProp.getName() + " as a String property into class" +
+                    " mediator : " + m.getClass() + " : " + e.getMessage();
+                log.error(msg);
+                throw new SynapseException(msg, e);
+            }
+        }
+    }
+
+    public void setClazz(Class clazz) {
+        this.clazz = clazz;
+    }
+
+    public Class getClazz() {
+        return clazz;
+    }
+
+    public void addProperty(MediatorProperty p) {
+        properties.add(p);
+    }
+
+    public void addAllProperties(List list) {
+        properties.addAll(list);
+    }
 
 }

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,106 @@
+/*
+ * 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.mediators.filters;
+
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.synapse.Util;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.mediators.AbstractListMediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import java.util.regex.Pattern;
+
+/**
+ * The filter mediator combines the regex and xpath filtering functionality. If an xpath
+ * is set, it is evaluated; else the given regex is evaluated against the source xpath.
+ */
+public class FilterMediator extends AbstractListMediator implements org.apache.synapse.api.FilterMediator {
+
+    private static final Log log = LogFactory.getLog(FilterMediator.class);
+    private AXIOMXPath source = null;
+    private Pattern regex = null;
+    private AXIOMXPath xpath = null;
+
+    /**
+     * Executes the list of sub/child mediators, if the filter condition is satisfied
+     * @param synCtx the current message
+     * @return true if filter condition fails. else returns as per List mediator semantics
+     */
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+        if (test(synCtx)) {
+            return super.mediate(synCtx);
+        } else {
+            return true;
+        }
+    }
+
+    /**
+     * Tests the supplied condition after evaluation against the given XPath
+     * or Regex (against a source XPath). When a regular expression is supplied
+     * the source XPath is evaluated into a String value, and matched against
+     * the given regex
+     * @param synCtx the current message for evaluation of the test condition
+     * @return true if evaluation of the XPath/Regex results in true
+     */
+    public boolean test(SynapseContext synCtx) {
+        try {
+            if (xpath != null) {
+                return xpath.booleanValueOf(synCtx.getSynapseMessage().getEnvelope());
+
+            } else if (source != null && regex != null) {
+                return regex.matcher(Util.getStringValue(source, synCtx)).matches();
+
+            } else {
+                log.error("Invalid configuration specified");
+                return false;
+            }
+
+        } catch (JaxenException e) {
+            log.error("XPath error : " + e.getMessage());
+            return false;
+        }
+    }
+
+
+    public AXIOMXPath getSource() {
+        return source;
+    }
+
+    public void setSource(AXIOMXPath source) {
+        this.source = source;
+    }
+
+    public Pattern getRegex() {
+        return regex;
+    }
+
+    public void setRegex(Pattern regex) {
+        this.regex = regex;
+    }
+
+    public AXIOMXPath getXpath() {
+        return xpath;
+    }
+
+    public void setXpath(AXIOMXPath xpath) {
+        this.xpath = xpath;
+    }
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,50 @@
+/*
+* 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.mediators.filters;
+
+import org.apache.synapse.mediators.AbstractListMediator;
+
+import java.util.regex.Pattern;
+
+/**
+ * A SwitchCaseMediator is a list mediator which has a regex that is matched by
+ * its owning SwitchMediator for selection
+ */
+public class SwitchCaseMediator extends AbstractListMediator {
+
+    private Pattern regex = null;
+    private boolean defaultCase = false;
+
+    public Pattern getRegex() {
+        return regex;
+    }
+
+    public void setRegex(Pattern regex) {
+        this.regex = regex;
+    }
+
+    public boolean isDefaultCase() {
+        return defaultCase;
+    }
+
+    public void setDefaultCase(boolean defaultCase) {
+        this.defaultCase = defaultCase;
+    }
+
+    public boolean matches(String value) {
+        return regex.matcher(value).matches();
+    }
+}
\ No newline at end of file

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,78 @@
+/*
+* 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.mediators.filters;
+
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.AbstractListMediator;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.Util;
+import org.apache.synapse.api.Mediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+
+import java.util.regex.Pattern;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * The switch mediator implements the functionality of the "switch" contruct. It first
+ * evaluates the given XPath expression into a String value, and performs a match against
+ * the given list of cases. This is actually a list of sequences, and depending on the
+ * selected case, the selected sequence gets executed.
+ */
+public class SwitchMediator extends AbstractMediator {
+
+    private static final Log log = LogFactory.getLog(SwitchMediator.class);
+
+    private AXIOMXPath source = null;
+    private List cases = new ArrayList();
+    private SwitchCaseMediator defaultCase = null;
+
+    /**
+     * Iterate over switch cases and find match and execute selected sequence
+     * @param synCtx current context
+     * @return as per standard semantics
+     */
+    public boolean mediate(SynapseContext synCtx) {
+
+        String sourceText = Util.getStringValue(source, synCtx);
+        Iterator iter = cases.iterator();
+
+        while (iter.hasNext()) {
+            SwitchCaseMediator swCase = (SwitchCaseMediator) iter.next();
+            if (swCase.matches(sourceText)) {
+                return swCase.mediate(synCtx);
+            }
+        }
+
+        if (defaultCase != null) {
+            return defaultCase.mediate(synCtx);
+        }
+
+        return true;
+    }
+
+    /**
+     * Adds the given mediator (Should be a SwitchCaseMediator) to the list of cases
+     * of this Switch mediator
+     * @param m the SwitchCaseMediator instance to be added
+     */
+    public void addCase(SwitchCaseMediator m) {
+        cases.add(m);
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,142 @@
+/*
+ * 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.mediators.transform;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.soap.*;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.mediators.AbstractMediator;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This transforms the current message instance into a SOAP Fault message. If the
+ * original message was SOAP 1.1 the fault will also be SOAP 1.1 else, SOAP 1.2
+ *
+ * TODO this class needs more attention! - revisit later
+ */
+public class FaultMediator extends AbstractMediator {
+    
+    private static final Log log = LogFactory.getLog(FaultMediator.class);
+
+    public static final int SOAP11 = 1;
+    public static final int SOAP12 = 2;
+
+    private int soapVersion;
+    private QName code;
+    private String reason;
+
+    //TODO support SOAP 1.2 fault stuff..
+    //Node, Role, detail etc
+
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+        SynapseMessage synMsg = synCtx.getSynapseMessage();
+        SOAPEnvelope envelop = synMsg.getEnvelope();
+        SOAPFactory factory;
+
+        switch (soapVersion) {
+            case SOAP11:
+                factory = OMAbstractFactory.getSOAP11Factory();
+                break;
+            case SOAP12:
+                factory = OMAbstractFactory.getSOAP12Factory();
+                break;
+            default : {
+                if (envelop != null) {
+                    if (envelop.getNamespace().getName().equals(
+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
+                        factory = OMAbstractFactory.getSOAP12Factory();
+                    } else {
+                        factory = OMAbstractFactory.getSOAP11Factory();
+                    }
+                } else {
+                    factory = OMAbstractFactory.getSOAP11Factory();
+                }
+            }
+        }
+
+        OMDocument soapFaultDocument = factory.createOMDocument();
+        SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
+        soapFaultDocument.addChild(faultEnvelope);
+
+        /*SOAPFaultReason reason = factory.createSOAPFaultReason();
+        reason.setText(getReason());
+
+        SOAPFault fault = factory.createSOAPFault();
+        fault.setReason(reason);
+
+        SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
+        faultEnvelope.getBody().addFault(fault);*/
+
+        // set the fault message to the "faultTo" of the original message if it exists
+        // else to the "replyTo"
+        EndpointReference toEPR = synMsg.getTo();
+        EndpointReference faultToEPR = synMsg.getFaultTo();
+        if (faultToEPR != null) {
+            synMsg.setTo(faultToEPR);
+            synMsg.setReplyTo(toEPR);
+        } else {
+            EndpointReference replyToEPR = synMsg.getReplyTo();
+            synMsg.setTo(replyToEPR);
+            synMsg.setReplyTo(toEPR);
+        }
+        synMsg.setResponse(true);
+
+        try {
+            synMsg.setEnvelope(faultEnvelope);
+        } catch (AxisFault af) {
+            String msg = "Error replacing SOAP envelope with a fault envelope " + af.getMessage();
+            log.error(msg);
+            throw new SynapseException(af);
+        }
+        return true;
+    }
+
+    public QName getCode() {
+        return code;
+    }
+
+    public void setCode(QName code) {
+        this.code = code;
+    }
+
+    public String getReason() {
+        return reason;
+    }
+
+    public void setReason(String reason) {
+        this.reason = reason;
+    }
+
+    public int getSoapVersion() {
+        return soapVersion;
+    }
+
+    public void setSoapVersion(int soapVersion) {
+        this.soapVersion = soapVersion;
+    }
+
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,101 @@
+/*
+* 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.mediators.transform;
+
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.HeaderType;
+import org.apache.synapse.Util;
+import org.apache.synapse.SynapseContext;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The header mediator is able to set a given value as a SOAP header, or remove a given
+ * header from the current message instance. This supports the headers currently
+ * supported by the HeaderType class. If an expression is supplied, its runtime value
+ * is evaluated using the current message. Unless the action is set to remove, the
+ * default behaviour of this mediator is to set a header value.
+ *
+ * @see HeaderType
+ */
+public class HeaderMediator extends AbstractMediator {
+
+    private static final Log log = LogFactory.getLog(HeaderMediator.class);
+
+    public static final int ACTION_SET = 0;
+    public static final int ACTION_REMOVE = 1;
+
+    private String name = null;
+    private String value = null;
+    private int action = ACTION_SET;
+
+    private AXIOMXPath expression = null;
+    private HeaderType headerType = new HeaderType();
+
+    /**
+     * Sets/Removes a SOAP header on the current message
+     *
+     * @param synCtx the current message which is altered as necessary
+     * @return true always
+     */
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+
+        if (action == ACTION_SET) {
+            headerType.setHeader(synCtx.getSynapseMessage(),
+                (getValue() != null ? getValue() :
+                    Util.getStringValue(getExpression(), synCtx)));
+
+        } else {
+            headerType.removeHeader(synCtx.getSynapseMessage());
+        }
+        return true;
+    }
+
+    public int getAction() {
+        return action;
+    }
+
+    public void setAction(int action) {
+        this.action = action;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+        this.headerType.setHeaderType(name);
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public AXIOMXPath getExpression() {
+        return expression;
+    }
+
+    public void setExpression(AXIOMXPath expression) {
+        this.expression = expression;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java Mon May  8 06:15:47 2006
@@ -0,0 +1,176 @@
+package org.apache.synapse.mediators.transform;
+
+
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.*;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+/**
+ * The transform mediator performs an XSLT or XQuery transformation requested, using
+ * the current message. The source attribute (if available) spcifies the source element
+ * on which the transformation would be applied. Additional properties passed into this
+ * mediator would become parameters (for XSLT) or variables (XQuery).
+ */
+public class TransformMediator extends AbstractMediator {
+
+    private static final Log log = LogFactory.getLog(TransformMediator.class);
+
+    private URL xsltUrl = null;
+    private URL xQueryUrl = null;
+    private AXIOMXPath source = null;
+
+    /**
+     * Transforms this message (or its element specified as the source) using the
+     * given XSLT or XQuery transformation
+     * @param synCtx the current message where the transformation will apply
+     * @return true always
+     */
+    public boolean mediate(SynapseContext synCtx) {
+        log.debug(getType() + " mediate()");
+
+        if (xsltUrl != null) {
+            performXLST(synCtx.getSynapseMessage());
+            return true;
+
+        } else if (xQueryUrl != null) {
+            //TODO later revisit later
+            System.err.println("Unimplemented functionality..");
+            return true;
+
+        } else {
+            log.error("Invalid configuration - xslt/xq not specified");
+            return false;
+        }
+    }
+
+    private void performXLST(SynapseMessage synMsg) {
+        try {
+            // create a transformer
+            Transformer transformer = TransformerFactory.newInstance().newTransformer(
+                new StreamSource(xsltUrl.openStream()));
+
+            // create a byte array output stream and serialize the source node into it
+            ByteArrayOutputStream baosForSource = new ByteArrayOutputStream();
+            XMLStreamWriter xsWriterForSource = XMLOutputFactory.newInstance().createXMLStreamWriter(baosForSource);
+
+            OMNode sourceNode = getTransformSource(synMsg);
+            sourceNode.serialize(xsWriterForSource);
+            Source transformSrc = new StreamSource(new ByteArrayInputStream(baosForSource.toByteArray()));
+
+            // create a new Stream result over a new BAOS..
+            ByteArrayOutputStream baosForTarget = new ByteArrayOutputStream();
+            StreamResult transformTgt = new StreamResult(baosForTarget);
+
+            // perform transformation
+            transformer.transform(transformSrc, transformTgt);
+
+            StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(baosForTarget.toByteArray()));
+            OMContainer parent = sourceNode.getParent();
+
+            if (parent instanceof SOAPEnvelope) {
+                ((SOAPEnvelope) parent).getBody().getFirstOMChild().detach();
+                ((SOAPEnvelope) parent).getBody().setFirstChild(builder.getDocumentElement());
+            } else {
+                parent.getFirstOMChild().detach();
+                parent.addChild(builder.getDocumentElement());
+            }
+
+        } catch (MalformedURLException mue) {
+            handleException(mue);
+        } catch (TransformerConfigurationException tce) {
+            handleException(tce);
+        } catch (XMLStreamException xse) {
+            handleException(xse);
+        } catch (TransformerException te) {
+            handleException(te);
+        } catch (IOException ioe) {
+            handleException(ioe);
+        }
+    }
+
+    private OMNode getTransformSource(SynapseMessage synMsg) {
+
+        if (source == null) {
+            try {
+                source = new AXIOMXPath("//SOAP-ENV:Body");
+                source.addNamespace("SOAP-ENV", synMsg.isSOAP11() ?
+                    SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI : SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+            } catch (JaxenException e) {}
+        }
+
+        try {
+            Object o = source.evaluate(synMsg.getEnvelope());;
+            if (o instanceof OMNode) {
+                return (OMNode) o;
+            } else if (o instanceof List && !((List) o).isEmpty()) {
+                return (OMNode) ((List) o).get(0);  // Always fetches *only* the first
+            } else {
+                String msg = "The evaluation of the XPath expression " + source + " must result in an OMNode";
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+
+        } catch (JaxenException e) {
+            String msg = "Error evaluating XPath " + source + " on message";
+            log.error(msg);
+            throw new SynapseException(msg, e);
+        }
+    }
+
+    private void handleException(Exception e) {
+        String msg = "Error performing XSLT/XQ transformation " + e.getMessage();
+        log.error(msg);
+        throw new SynapseException(msg, e);
+    }
+
+    public AXIOMXPath getSource() {
+        return source;
+    }
+
+    public void setSource(AXIOMXPath source) {
+        this.source = source;
+    }
+
+    public URL getXsltUrl() {
+        return xsltUrl;
+    }
+
+    public void setXsltUrl(URL xsltUrl) {
+        this.xsltUrl = xsltUrl;
+    }
+
+    public URL getXQueryUrl() {
+        return xQueryUrl;
+    }
+
+    public void setXQueryUrl(URL xQueryUrl) {
+        this.xQueryUrl = xQueryUrl;
+    }
+
+}
+
+	

Modified: incubator/synapse/trunk/java/modules/core/test-resources/axis2/services/emptymediator/META-INF/services.xml
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test-resources/axis2/services/emptymediator/META-INF/services.xml?rev=405043&r1=405042&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test-resources/axis2/services/emptymediator/META-INF/services.xml (original)
+++ incubator/synapse/trunk/java/modules/core/test-resources/axis2/services/emptymediator/META-INF/services.xml Mon May  8 06:15:47 2006
@@ -1,6 +1,6 @@
 <service name="emptymediator">
     <operation name="mediate" > 
-          <messageReceiver class="org.apache.synapse.axis2.EmptyMessageReceiver" />
+          <messageReceiver class="org.apache.synapse.core.axis2.EmptyMessageReceiver" />
     </operation>
 </service>
   

Modified: incubator/synapse/trunk/java/modules/core/test-resources/axis2/services/synapse/META-INF/services.xml
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test-resources/axis2/services/synapse/META-INF/services.xml?rev=405043&r1=405042&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test-resources/axis2/services/synapse/META-INF/services.xml (original)
+++ incubator/synapse/trunk/java/modules/core/test-resources/axis2/services/synapse/META-INF/services.xml Mon May  8 06:15:47 2006
@@ -1,7 +1,7 @@
   <service name="synapse">
 
     <operation name="mediate" > 
-          <messageReceiver class="org.apache.synapse.axis2.SynapseMessageReceiver" />
+          <messageReceiver class="org.apache.synapse.core.axis2.SynapseMessageReceiver" />
     </operation>
     
   </service>

Added: incubator/synapse/trunk/java/modules/core/test-resources/misc/validate.xsd
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test-resources/misc/validate.xsd?rev=405043&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test-resources/misc/validate.xsd (added)
+++ incubator/synapse/trunk/java/modules/core/test-resources/misc/validate.xsd Mon May  8 06:15:47 2006
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.apache-synapse.org/test" elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="http://www.apache-synapse.org/test">
+	<xs:element name="CheckPriceRequest">
+		<xs:complexType>
+			<xs:sequence>
+				<xs:element name="Code" type="xs:string"/>
+			</xs:sequence>
+		</xs:complexType>
+	</xs:element>
+</xs:schema>
\ No newline at end of file

Modified: incubator/synapse/trunk/java/modules/core/test-resources/org/apache/axis2/META-INF/environmentaware-service.xml
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test-resources/org/apache/axis2/META-INF/environmentaware-service.xml?rev=405043&r1=405042&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test-resources/org/apache/axis2/META-INF/environmentaware-service.xml (original)
+++ incubator/synapse/trunk/java/modules/core/test-resources/org/apache/axis2/META-INF/environmentaware-service.xml Mon May  8 06:15:47 2006
@@ -6,6 +6,6 @@
         org.apache.axis2.test.EnvironmentAwareMediator</parameter>
     <operation name="mediate">
         <messageReceiver
-                class="org.apache.synapse.axis2.ServiceMediatorMessageReceiver"/>
+                class="org.apache.synapse.core.axis2.axis2.ServiceMediatorMessageReceiver"/>
     </operation>
 </service>

Modified: incubator/synapse/trunk/java/modules/core/test-resources/org/apache/axis2/META-INF/service-mediator.xml
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test-resources/org/apache/axis2/META-INF/service-mediator.xml?rev=405043&r1=405042&r2=405043&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test-resources/org/apache/axis2/META-INF/service-mediator.xml (original)
+++ incubator/synapse/trunk/java/modules/core/test-resources/org/apache/axis2/META-INF/service-mediator.xml Mon May  8 06:15:47 2006
@@ -6,6 +6,6 @@
         org.apache.axis2.test.TestMediator</parameter>
     <operation name="mediate">
         <messageReceiver
-                class="org.apache.synapse.axis2.ServiceMediatorMessageReceiver"/>
+                class="org.apache.synapse.core.axis2.axis2.ServiceMediatorMessageReceiver"/>
     </operation>
 </service>



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