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 14:27:25 UTC
svn commit: r405035 - in /incubator/synapse/trunk/scratch/synapse2: etc/
modules/core/src/org/apache/synapse/config/xml/
modules/core/src/org/apache/synapse/mediators/builtin/
modules/core/src/org/apache/synapse/mediators/ext/
modules/core/test-resourc...
Author: saminda
Date: Mon May 8 05:27:19 2006
New Revision: 405035
URL: http://svn.apache.org/viewcvs?rev=405035&view=rev
Log:
introduce a few new unit tests and prepare code for checkin to main
Added:
incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java
incubator/synapse/trunk/scratch/synapse2/modules/core/test-resources/misc/
incubator/synapse/trunk/scratch/synapse2/modules/core/test-resources/misc/validate.xsd
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessage.java
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessageContext.java
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediateHandler.java
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediator.java
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/builtin/
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTest.java
incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTestMediator.java
Modified:
incubator/synapse/trunk/scratch/synapse2/etc/project.properties
incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java
incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java
incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java
incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java
incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/InjectRedirect.java
incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/Logger.java
Modified: incubator/synapse/trunk/scratch/synapse2/etc/project.properties
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/etc/project.properties?rev=405035&r1=405034&r2=405035&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/etc/project.properties (original)
+++ incubator/synapse/trunk/scratch/synapse2/etc/project.properties Mon May 8 05:27:19 2006
@@ -18,8 +18,11 @@
# -------------------------------------------------------------------
# JUnit
# -------------------------------------------------------------------
-maven.junit.jvmargs=-Djava.awt.headless=true
+# explicit setting of Sax parser as below is a hack to avoid Junit from loading its own parsers ignoring maven.test.excludeXmlApis
+maven.junit.jvmargs=-Djava.awt.headless=true -Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
maven.junit.fork=true
+#maven.junit.dir=${basedir}/modules/core
+
# -------------------------------------------------------------------
# Compile
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java?rev=405035&r1=405034&r2=405035&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/ClassMediatorFactory.java Mon May 8 05:27:19 2006
@@ -23,35 +23,51 @@
import org.apache.synapse.mediators.ext.ClassMediator;
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;
/**
+ * Creates an instance of a Class mediator using XML configuration specified
*
- * <xmp><synapse:classmediator name="nm" class="org.fremantle.mediator"</synapse:classmediator></xmp>
- * TODO add ability to configure properties with Strings/OMElements based on children.
+ * <class name="class-name">
+ * <property name="string" (value="literal" | expression="xpath")/>*
+ * </class>
*/
public class ClassMediatorFactory extends AbstractMediatorFactory {
- private static final QName CLM_Q = new QName(Constants.SYNAPSE_NAMESPACE,
- "classmediator");
- public Mediator createMediator(OMElement el) {
- ClassMediator cmp = new ClassMediator();
- OMAttribute clsName = el.getAttribute(new QName("class"));
- if (clsName == null)
- throw new SynapseException("missing class attribute on element"
- + el.toString());
+
+ private static final Log log = LogFactory.getLog(LogMediatorFactory.class);
+
+ private static final QName CLASS_Q = new QName(Constants.SYNAPSE_NAMESPACE, "class");
+
+ public Mediator createMediator(OMElement elem) {
+
+ ClassMediator classMediator = new ClassMediator();
+
+ OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+ if (name == null) {
+ String msg = "The name of the actual mediator class is a required attribute";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
try {
- //TODO replace this hack to get the classloader from the synapse env - temp fix
- Class clazz = getClass().getClassLoader().loadClass(clsName.getAttributeValue());
- cmp.setClazz(clazz);
+ Class clazz = getClass().getClassLoader().loadClass(name.getAttributeValue());
+ classMediator.setClazz(clazz);
} catch (ClassNotFoundException e) {
- throw new SynapseException("class loading error", e);
+ String msg = "Cannot find class : " + name.getAttributeValue();
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
}
- return cmp;
+ classMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
+
+ return classMediator;
}
public QName getTagQName() {
- return CLM_Q;
+ return CLASS_Q;
}
-
}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java?rev=405035&r1=405034&r2=405035&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java Mon May 8 05:27:19 2006
@@ -30,6 +30,7 @@
import org.jaxen.JaxenException;
import java.util.Iterator;
+import java.util.List;
/**
* Created a Log mediator that logs messages using commons-logging.
@@ -76,61 +77,7 @@
logMediator.setSeperator(seperator.getAttributeValue());
}
- // parse custom properties and set them into the mediator
- 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 Log property";
- log.error(msg);
- throw new SynapseException(msg);
-
- } else {
- try {
- prop.setExpression(new AXIOMXPath(attExpr.getAttributeValue()));
-
- } 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 Log property";
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- logMediator.addProperty(prop);
- }
+ logMediator.addAllProperties(MediatorPropertyFactory.getMediatorProperties(elem));
return logMediator;
}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/xml/MediatorPropertyFactory.java Mon May 8 05:27:19 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.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.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
+ *
+ * <element>
+ * <property name="string" (value="literal" | expression="xpath")/>*
+ * </element>
+ */
+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 {
+ prop.setExpression(new AXIOMXPath(attExpr.getAttributeValue()));
+
+ } 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;
+ }
+}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java?rev=405035&r1=405034&r2=405035&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java Mon May 8 05:27:19 2006
@@ -153,4 +153,8 @@
properties.add(p);
}
+ public void addAllProperties(List list) {
+ properties.addAll(list);
+ }
+
}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java?rev=405035&r1=405034&r2=405035&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/ValidateMediator.java Mon May 8 05:27:19 2006
@@ -88,7 +88,7 @@
}
try {
- Object o = source.evaluate(synMsg.getEnvelope());;
+ Object o = source.evaluate(synMsg.getEnvelope());
if (o instanceof OMNode) {
return (OMNode) o;
} else if (o instanceof List && !((List) o).isEmpty()) {
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java?rev=405035&r1=405034&r2=405035&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java Mon May 8 05:27:19 2006
@@ -13,46 +13,85 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.synapse.mediators.ext;
-
-import org.apache.synapse.SynapseException;
+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.Util;
import org.apache.synapse.api.Mediator;
import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.mediators.MediatorProperty;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.lang.reflect.Method;
/**
- * This executes the "mediate" operation on a new instance of the specified class
- * <p/>
- * TODO add support for simple properties to be set
- * TODO Requires refactoring and cleanup - revisit later
+ * The class mediator delegates the mediation to a new instance of a specified class. The specified class
+ * must implement the Mediator interface
+ *
+ * @see Mediator
*/
public class ClassMediator extends AbstractMediator {
+ private static final Log log = LogFactory.getLog(ClassMediator.class);
+
private Class clazz = null;
+ private List properties = new ArrayList();
- private static final Log log = LogFactory.getLog(ClassMediator.class);
+ /**
+ * 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) {
- public boolean mediate(SynapseContext smc) {
log.debug(getType() + " mediate()");
Mediator m = null;
-
try {
- m = (Mediator) getClazz().newInstance();
+ m = (Mediator) clazz.newInstance();
+
} catch (Exception e) {
- throw new SynapseException(e);
+ String msg = "Error while creating an instance of the specified mediator class : " + clazz.getName();
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
}
- /*if (EnvironmentAware.class.isAssignableFrom(m.getClass())) {
- ((EnvironmentAware) m).initializeSynapse(se);
- }*/
- return m.mediate(smc);
+ 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;
@@ -60,6 +99,14 @@
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/scratch/synapse2/modules/core/test-resources/misc/validate.xsd
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/test-resources/misc/validate.xsd?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/test-resources/misc/validate.xsd (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/test-resources/misc/validate.xsd Mon May 8 05:27:19 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
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessage.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessage.java?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessage.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessage.java Mon May 8 05:27:19 2006
@@ -0,0 +1,141 @@
+/*
+* 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;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.RelatesTo;
+
+public class TestSynapseMessage implements SynapseMessage {
+
+ SOAPEnvelope envelope = null;
+
+ public SOAPEnvelope getEnvelope() {
+ if (envelope == null)
+ return OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+ else
+ return envelope;
+ }
+
+ public void setEnvelope(SOAPEnvelope envelope) throws AxisFault {
+ this.envelope = envelope;
+ }
+
+ public EndpointReference getFaultTo() {
+ return null;
+ }
+
+ public void setFaultTo(EndpointReference reference) {
+ }
+
+ public EndpointReference getFrom() {
+ return null;
+ }
+
+ public void setFrom(EndpointReference reference) {
+ }
+
+ public String getMessageID() {
+ return null;
+ }
+
+ public void setMessageID(String string) {
+ }
+
+ public RelatesTo getRelatesTo() {
+ return null;
+ }
+
+ public void setRelatesTo(RelatesTo[] reference) {
+ }
+
+ public EndpointReference getReplyTo() {
+ return null;
+ }
+
+ public void setReplyTo(EndpointReference reference) {
+ }
+
+ public EndpointReference getTo() {
+ return null;
+ }
+
+ public void setTo(EndpointReference reference) {
+ }
+
+ public void setWSAAction(String actionURI) {
+ }
+
+ public String getWSAAction() {
+ return null;
+ }
+
+ public String getSoapAction() {
+ return null;
+ }
+
+ public void setSoapAction(String string) {
+ }
+
+ public void setMessageId(String messageID) {
+ }
+
+ public String getMessageId() {
+ return null;
+ }
+
+ public boolean isDoingMTOM() {
+ return false;
+ }
+
+ public void setDoingMTOM(boolean b) {
+ }
+
+ public boolean isDoingREST() {
+ return false;
+ }
+
+ public void setDoingREST(boolean b) {
+ }
+
+ public boolean isSOAP11() {
+ return false;
+ }
+
+ public void setResponse(boolean b) {
+ }
+
+ public boolean isResponse() {
+ return false;
+ }
+
+ public void setFaultResponse(boolean b) {
+ }
+
+ public boolean isFaultResponse() {
+ return false;
+ }
+
+ public SynapseContext getSynapseContext() {
+ return null;
+ }
+
+ public void setSynapseContext(SynapseContext env) {
+ }
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessageContext.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessageContext.java?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessageContext.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/TestSynapseMessageContext.java Mon May 8 05:27:19 2006
@@ -0,0 +1,56 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse;
+
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.core.SynapseEnvironment;
+
+public class TestSynapseMessageContext implements SynapseContext {
+
+ private SynapseMessage synMsg = null;
+
+ public SynapseConfiguration getConfiguration() {
+ return null;
+ }
+
+ public void setConfiguration(SynapseConfiguration cfg) {
+ }
+
+ public SynapseEnvironment getSynapseEnvironment() {
+ return null;
+ }
+
+ public void setSynapseEnvironment(SynapseEnvironment se) {
+ }
+
+ public void setSynapseMessage(SynapseMessage sm) {
+ synMsg = sm;
+ }
+
+ public SynapseMessage getSynapseMessage() {
+ if (synMsg == null)
+ return new TestSynapseMessage();
+ else
+ return synMsg;
+ }
+
+ public Object getProperty(String key) {
+ return null;
+ }
+
+ public void setProperty(String key, Object value) {
+ }
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediateHandler.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediateHandler.java?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediateHandler.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediateHandler.java Mon May 8 05:27:19 2006
@@ -0,0 +1,23 @@
+/*
+* 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;
+
+public interface TestMediateHandler {
+
+ public void handle(SynapseContext synCtx);
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediator.java?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/TestMediator.java Mon May 8 05:27:19 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.mediators;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseContext;
+
+/**
+ * Test mediator class.
+ */
+public class TestMediator implements Mediator {
+
+ private TestMediateHandler handlerTest = null;
+
+ public TestMediator() {
+ }
+
+ public boolean mediate(SynapseContext synCtx) {
+ if (handlerTest != null) {
+ handlerTest.handle(synCtx);
+ }
+ return true;
+ }
+
+ public String getType() {
+ return null;
+ }
+
+ public TestMediateHandler getHandler() {
+ return handlerTest;
+ }
+
+ public void setHandler(TestMediateHandler handlerTest) {
+ this.handlerTest = handlerTest;
+ }
+}
\ No newline at end of file
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java Mon May 8 05:27:19 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.mediators.builtin;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.*;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.TestSynapseMessage;
+import org.apache.synapse.TestSynapseMessageContext;
+import org.apache.synapse.mediators.TestMediateHandler;
+import org.apache.synapse.mediators.TestMediator;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import java.io.StringReader;
+import java.io.File;
+
+public class ValidateMediatorTest extends TestCase implements TestMediateHandler {
+
+ private static final String VALID_ENVELOPE =
+ "<m0:CheckPriceRequest xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
+ "\t<m0:Code>String</m0:Code>\n" +
+ "</m0:CheckPriceRequest>\n";
+
+ private static final String IN_VALID_ENVELOPE =
+ "<m0:CheckPriceRequest xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
+ "\t<m0:Codes>String</m0:Codes>\n" +
+ "</m0:CheckPriceRequest>\n";
+
+ private boolean onFailInvoked = false;
+ private TestMediator testMediator = null;
+
+ public void setUp() {
+ testMediator = new TestMediator();
+ testMediator.setHandler(this);
+ }
+
+ public void handle(SynapseContext synCtx) {
+ onFailInvoked = true;
+ }
+
+ public void setOnFailInvoked(boolean onFailInvoked) {
+ this.onFailInvoked = onFailInvoked;
+ }
+
+ public void testValidateMedaitorValidCase() throws Exception {
+ setOnFailInvoked(false);
+
+ // create a validate mediator
+ ValidateMediator validate = new ValidateMediator();
+
+ // set the schema url, source xpath and any name spaces
+ System.out.println("Current Dir : " + new File(".").getAbsolutePath());
+ validate.setSchemaUrl("test-resources/misc/validate.xsd");
+ AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
+ source.addNamespace("m0", "http://www.apache-synapse.org/test");
+ validate.setSource(source);
+
+ // set dummy mediator to be called on fail
+ validate.addChild(testMediator);
+
+ // test validate mediator, with static enveope
+ validate.mediate(getTestContext(VALID_ENVELOPE));
+
+ assertTrue(!onFailInvoked);
+ }
+
+ public void testValidateMedaitorInvalidCase() throws Exception {
+ setOnFailInvoked(false);
+
+ // create a validate mediator
+ ValidateMediator validate = new ValidateMediator();
+
+ // set the schema url, source xpath and any name spaces
+ validate.setSchemaUrl("modules/core/test-resources/misc/validate.xsd");
+ AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
+ source.addNamespace("m0", "http://www.apache-synapse.org/test");
+ validate.setSource(source);
+
+ // set dummy mediator to be called on fail
+ validate.addChild(testMediator);
+
+ // test validate mediator, with static enveope
+ validate.mediate(getTestContext(IN_VALID_ENVELOPE));
+
+ assertTrue(onFailInvoked);
+ }
+
+ private TestSynapseMessageContext getTestContext(String bodyText) throws Exception {
+
+ // create a test synapse context
+ TestSynapseMessageContext synCtx = new TestSynapseMessageContext();
+ TestSynapseMessage synMsg = new TestSynapseMessage();
+
+ SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+ OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
+ omDoc.addChild(envelope);
+
+ XMLStreamReader parser = XMLInputFactory.newInstance().
+ createXMLStreamReader(new StringReader(bodyText));
+ StAXOMBuilder builder = new StAXOMBuilder(parser);
+
+ // set a dummy static message
+ envelope.getBody().addChild(builder.getDocumentElement());
+
+ synMsg.setEnvelope(envelope);
+ synCtx.setSynapseMessage(synMsg);
+ return synCtx;
+ }
+
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTest.java?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTest.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTest.java Mon May 8 05:27:19 2006
@@ -0,0 +1,58 @@
+/*
+* 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.ext;
+
+import junit.framework.TestCase;
+import org.apache.synapse.TestSynapseMessageContext;
+import org.apache.synapse.mediators.MediatorProperty;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+
+/**
+ * Tests the class mediator instantiation and setting of literal and
+ * XPath parameters at runtime.
+ */
+public class ClassMediatorTest extends TestCase {
+
+ public void testCreationWithoutProperties() throws Exception {
+ ClassMediator cm = new ClassMediator();
+ cm.setClazz(ClassMediatorTestMediator.class);
+ cm.mediate(new TestSynapseMessageContext());
+ assertTrue(ClassMediatorTestMediator.invoked);
+ }
+
+ public void testCreationWithLiteralProperties() throws Exception {
+ ClassMediator cm = new ClassMediator();
+ MediatorProperty mp = new MediatorProperty();
+ mp.setName("testProp");
+ mp.setValue("testValue");
+ cm.addProperty(mp);
+ cm.setClazz(ClassMediatorTestMediator.class);
+ cm.mediate(new TestSynapseMessageContext());
+ assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
+ }
+
+ public void testCreationWithXPathProperties() throws Exception {
+ ClassMediator cm = new ClassMediator();
+ MediatorProperty mp = new MediatorProperty();
+ mp.setName("testProp");
+ mp.setExpression(new AXIOMXPath("concat('XPath ','is ','FUN!')"));
+ cm.addProperty(mp);
+ cm.setClazz(ClassMediatorTestMediator.class);
+ cm.mediate(new TestSynapseMessageContext());
+ assertTrue(ClassMediatorTestMediator.testProp.equals("XPath is FUN!"));
+ }
+
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTestMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTestMediator.java?rev=405035&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTestMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/test/org/apache/synapse/mediators/ext/ClassMediatorTestMediator.java Mon May 8 05:27:19 2006
@@ -0,0 +1,48 @@
+/*
+* 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.ext;
+
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.SynapseContext;
+
+/**
+ * Since the class mediator always "instantiates" a new instance of a class
+ * use a static member variable just to test this.. This class is not nice.. :-)
+ * but does what is expected... :-(
+ */
+public class ClassMediatorTestMediator implements Mediator {
+
+ public static boolean invoked = false;
+
+ public static String testProp = null;
+
+ public boolean mediate(SynapseContext synCtx) {
+ invoked = true;
+ return false;
+ }
+
+ public String getType() {
+ return null;
+ }
+
+ public void setTestProp(String s) {
+ testProp = s;
+ }
+
+ public String getTestProp() {
+ return testProp;
+ }
+}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/InjectRedirect.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/InjectRedirect.java?rev=405035&r1=405034&r2=405035&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/InjectRedirect.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/InjectRedirect.java Mon May 8 05:27:19 2006
@@ -16,22 +16,21 @@
package sampleMediators;
import org.apache.axis2.addressing.EndpointReference;
-import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.SynapseContext;
import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.synapse.api.Mediator;
public class InjectRedirect extends AbstractMediator {
- private String uri = null;
+ private String uri = null;
- public void setUri(String uri) {
- this.uri = uri;
- }
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
- public boolean mediate(SynapseMessage mc) {
+ public boolean mediate(SynapseContext mc) {
- System.out.println("Redirect.mediate: " + uri);
+ System.out.println("Redirect.mediate: " + uri);
- mc.setTo(new EndpointReference(uri));
- return true;
- }
+ mc.getSynapseMessage().setTo(new EndpointReference(uri));
+ return true;
+ }
}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/Logger.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/Logger.java?rev=405035&r1=405034&r2=405035&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/Logger.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/samples/src/sampleMediators/Logger.java Mon May 8 05:27:19 2006
@@ -15,9 +15,9 @@
*/
package sampleMediators;
+import org.apache.synapse.SynapseContext;
import org.apache.synapse.SynapseMessage;
import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.synapse.api.Mediator;
import org.apache.axiom.soap.SOAPEnvelope;
/**
@@ -33,7 +33,8 @@
*
* @see org.apache.synapse.mediator.Mediator#mediate(org.apache.axis2.context.MessageContext)
*/
- public boolean mediate(SynapseMessage mc) {
+ public boolean mediate(SynapseContext mctx) {
+ SynapseMessage mc = mctx.getSynapseMessage();
System.out.println("Logger.mediate:");
if (mc.getTo() != null && mc.getTo().getAddress() != null)
System.out.println("Logger.mediate to:" + mc.getTo().getAddress());
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org