You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by pz...@apache.org on 2005/11/25 14:28:28 UTC
svn commit: r348942 - in /incubator/synapse/trunk/scratch/prototype3:
SpringMediator/org/apache/synapse/processors/mediatortypes/spring/
src/org/apache/synapse/ src/org/apache/synapse/axis2/
src/org/apache/synapse/processors/ src/org/apache/synapse/pro...
Author: pzf
Date: Fri Nov 25 05:28:14 2005
New Revision: 348942
URL: http://svn.apache.org/viewcvs?rev=348942&view=rev
Log:
separated XML processing out
Modified:
incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/Processor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2Sender.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/AbstractProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/StageProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/SynapseProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/HeaderProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/SendProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/AddressingProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/ClassMediatorProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/axis2/ServiceMediatorProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/RegexProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/XPathProcessor.java
incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/xml/Configurator.java
Modified: incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessor.java Fri Nov 25 05:28:14 2005
@@ -1,84 +1,54 @@
package org.apache.synapse.processors.mediatortypes.spring;
-import java.io.ByteArrayOutputStream;
-import java.util.Iterator;
+
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamWriter;
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMElement;
import org.apache.synapse.Constants;
import org.apache.synapse.SynapseEnvironment;
-import org.apache.synapse.SynapseException;
import org.apache.synapse.SynapseMessage;
-
import org.apache.synapse.api.EnvironmentAware;
import org.apache.synapse.api.Mediator;
import org.apache.synapse.processors.AbstractProcessor;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.core.io.ByteArrayResource;
-
-
public class SpringMediatorProcessor extends AbstractProcessor {
- private static final QName tagName = new QName(Constants.SYNAPSE_NAMESPACE+"/spring", "springmediator");
+ private static final QName tagName = new QName(Constants.SYNAPSE_NAMESPACE
+ + "/spring", "springmediator");
+
private GenericApplicationContext ctx = null;
- private String beanName = null;
- public void compile(SynapseEnvironment se, OMElement el) {
-
- OMAttribute bean = el.getAttribute(new QName("bean"));
- if (bean == null) throw new SynapseException("missing bean attribute on "+el.toString());
- beanName = bean.getAttributeValue();
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- baos.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">"
- .getBytes());
- XMLStreamWriter xsw = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
- OMElement beans = null;
- Iterator it = el.getChildElements();
- while (it.hasNext()) {
- OMElement ths = (OMElement)it.next();
- if (ths.getLocalName().toLowerCase().equals("beans")) {
- beans = ths;
- break;
- }
- }
- if (beans==null) throw new SynapseException("<beans> element not found in "+el.toString());
- xsw.setDefaultNamespace(beans.getNamespace().getName());
- beans.serialize(xsw);
- } catch (Exception e) {
- throw new SynapseException(e);
- }
-
- GenericApplicationContext ctx = new GenericApplicationContext();
- XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(
- ctx);
- xbdr.setValidating(false);
- xbdr.loadBeanDefinitions(new ByteArrayResource(baos.toByteArray()));
- ctx.setClassLoader(se.getClassLoader());
- ctx.refresh();
-
-
-
- }
+
+ private String beanName = null;
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
- Mediator m = (Mediator)ctx.getBean(beanName);
- if (EnvironmentAware.class.isAssignableFrom(m.getClass())) {
- ((EnvironmentAware)m).setSynapseEnvironment(se);
- }
+ Mediator m = (Mediator) getContext().getBean(getBeanName());
+ if (EnvironmentAware.class.isAssignableFrom(m.getClass())) {
+ ((EnvironmentAware) m).setSynapseEnvironment(se);
+ }
return m.mediate(smc);
-
+
}
public QName getTagQName() {
-
+
return tagName;
+ }
+
+ public void setContext(GenericApplicationContext ctx) {
+ this.ctx = ctx;
+ }
+
+ public GenericApplicationContext getContext() {
+ return ctx;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public String getBeanName() {
+ return beanName;
}
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/Processor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/Processor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/Processor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/Processor.java Fri Nov 25 05:28:14 2005
@@ -1,27 +1,18 @@
package org.apache.synapse;
-import javax.xml.namespace.QName;
-
-import org.apache.axis2.om.OMElement;
/**
- * @author Paul Fremantle This interface implements the core of Synapse. The
- * processor is bootstrapped from a piece of config XML (the el
- * OMElement).
+ * @author Paul Fremantle This interface implements the core of Synapse.
*
* The processor then deals with a message. It returns false if no further
- * processing is desired It can have a name (or null)
+ * processing is desired. It can have a name (or null)
*
* Processors can either devolve processing to other processors (e.g. a rule,
* stage, etc) or deal with the message itself (e.g. mediator)
*
*/
public interface Processor {
- public void compile(SynapseEnvironment se, OMElement el);
-
- public boolean process(SynapseEnvironment se, SynapseMessage smc);
-
+ public boolean process(SynapseEnvironment se, SynapseMessage sm);
public String getName();
-
- public QName getTagQName();
+ public void setName(String name);
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2Sender.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2Sender.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2Sender.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2Sender.java Fri Nov 25 05:28:14 2005
@@ -67,6 +67,7 @@
ae.receive(outMsgContext);
} catch (Exception e) {
+ e.printStackTrace();
throw new SynapseException(e);
}
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/axis2/Axis2SynapseEnvironment.java Fri Nov 25 05:28:14 2005
@@ -6,10 +6,10 @@
import org.apache.synapse.SynapseEnvironment;
import org.apache.synapse.SynapseMessage;
-import org.apache.synapse.processors.SynapseProcessor;
+import org.apache.synapse.xml.Configurator;
public class Axis2SynapseEnvironment implements SynapseEnvironment {
- private Processor processor = new SynapseProcessor();
+ private Processor processor = null;
private ClassLoader cl = null;
@@ -17,7 +17,7 @@
ClassLoader cl) {
super();
this.cl = cl;
- processor.compile(this, synapseConfiguration);
+ processor = Configurator.getProcessor(this, synapseConfiguration);
}
public void injectMessage(SynapseMessage smc) {
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/AbstractProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/AbstractProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/AbstractProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/AbstractProcessor.java Fri Nov 25 05:28:14 2005
@@ -24,4 +24,7 @@
public String getName() {
return name;
}
+ public void setName(String name) {
+ this.name = name;
+ }
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/StageProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/StageProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/StageProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/StageProcessor.java Fri Nov 25 05:28:14 2005
@@ -1,19 +1,9 @@
package org.apache.synapse.processors;
-import javax.xml.namespace.QName;
-
-import org.apache.synapse.Constants;
/**
* @author Paul Fremantle A stage is really just an alias for <all>
*
*/
-public class StageProcessor extends AllProcessor {
- private static final QName STAGE_Q = new QName(Constants.SYNAPSE_NAMESPACE,
- "stage");
-
- public QName getTagQName() {
- return STAGE_Q;
- }
-
+public class StageProcessor extends ListProcessor {
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/SynapseProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/SynapseProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/SynapseProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/SynapseProcessor.java Fri Nov 25 05:28:14 2005
@@ -16,16 +16,5 @@
package org.apache.synapse.processors;
-import javax.xml.namespace.QName;
-
-import org.apache.synapse.Constants;
-
-public class SynapseProcessor extends AllProcessor {
- private final static QName tagname = new QName(Constants.SYNAPSE_NAMESPACE,
- "synapse");
-
- public QName getTagQName() {
- return tagname;
- }
-
+public class SynapseProcessor extends ListProcessor {
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/HeaderProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/HeaderProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/HeaderProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/HeaderProcessor.java Fri Nov 25 05:28:14 2005
@@ -1,15 +1,7 @@
package org.apache.synapse.processors.builtin;
-import javax.xml.namespace.QName;
-
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMElement;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.Constants;
+import org.apache.synapse.HeaderType;
import org.apache.synapse.SynapseEnvironment;
-import org.apache.synapse.SynapseException;
import org.apache.synapse.SynapseMessage;
import org.apache.synapse.processors.AbstractProcessor;
@@ -17,93 +9,37 @@
/**
* @author Paul Fremantle
* <p>
- * <xmp><synapse:header type="to|from|faultto|replyto|action"
- * value="newvalue"/> </xmp>
- *
+ *
*
*/
public class HeaderProcessor extends AbstractProcessor {
- private static final QName HEADER_Q = new QName(
- Constants.SYNAPSE_NAMESPACE, "header");
-
- private Log log = LogFactory.getLog(getClass());
-
- private int headerType = 0;
+
+ private HeaderType headerType = new HeaderType();
private String value = null;
- private static final QName TYPE_ATT_Q = new QName("type"),
- VALUE_ATT_Q = new QName("value");
-
- private final static int TO = 1, FROM = 2, FAULT = 3, ACTION = 4,
- REPLYTO = 5;
-
- private final static String STRTO = "to", STRFROM = "from",
- STRFAULT = "faultto", STRACTION = "action", STRREPLYTO = "replyto";
-
- public void compile(SynapseEnvironment se, OMElement el) {
- super.compile(se, el);
-
- OMAttribute val = el.getAttribute(VALUE_ATT_Q);
- OMAttribute type = el.getAttribute(TYPE_ATT_Q);
- if (val == null || type == null) {
- throw new SynapseException("<header> must have both " + VALUE_ATT_Q
- + " and " + TYPE_ATT_Q + " attributes: " + el.toString());
- }
-
- String header = type.getAttributeValue();
- if (header.equalsIgnoreCase(STRTO))
- headerType = TO;
- else if (header.equalsIgnoreCase(STRFROM))
- headerType = FROM;
- else if (header.equalsIgnoreCase(STRFAULT))
- headerType = FAULT;
- else if (header.equalsIgnoreCase(STRACTION))
- headerType = ACTION;
- else if (header.equalsIgnoreCase(STRREPLYTO))
- headerType = REPLYTO;
- else
- throw new SynapseException(
- "unknown header attribute value in <header>: " + header);
- value = val.getAttributeValue();
+ public void setHeaderType(String ht) {
+ headerType.setHeaderType(ht);
}
+
+ public String getHeaderType() {
+ return headerType.getHeaderType();
+ }
+
+ public boolean process(SynapseEnvironment se, SynapseMessage sm) {
- public boolean process(SynapseEnvironment se, SynapseMessage smc) {
-
- switch (headerType) {
- case 0: {
- log.debug("unknown header type");
- return true;
- }
-
- case TO: {
- log.debug("set to: " + value);
- smc.setTo(new EndpointReference(value));
- break;
- }
- case FROM: {
- log.debug("set from: " + value);
- smc.setFrom(new EndpointReference(value));
- break;
- }
- case REPLYTO: {
- log.debug("set replyto: " + value);
- smc.setReplyTo(new EndpointReference(value));
- break;
- }
- case ACTION: {
- log.debug("set action: " + value);
- smc.setWSAAction(value);
- break;
- }
+ headerType.setHeader(sm, getValue());
+ return true;
+ }
- }
+
- return true;
+ public void setValue(String value) {
+ this.value = value;
}
- public QName getTagQName() {
- return HEADER_Q;
+ public String getValue() {
+ return value;
}
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/SendProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/SendProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/SendProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/SendProcessor.java Fri Nov 25 05:28:14 2005
@@ -1,28 +1,17 @@
package org.apache.synapse.processors.builtin;
-import javax.xml.namespace.QName;
-
-import org.apache.axis2.om.OMElement;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.processors.AbstractProcessor;
-import org.apache.synapse.Constants;
import org.apache.synapse.SynapseEnvironment;
import org.apache.synapse.SynapseMessage;
public class SendProcessor extends AbstractProcessor {
- private static final QName SEND_Q = new QName(Constants.SYNAPSE_NAMESPACE,
- "send");
-
private Log log = LogFactory.getLog(getClass());
- public void compile(SynapseEnvironment se, OMElement el) {
- super.compile(se, el);
-
- }
-
+
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
log.debug("process");
if (smc.isResponse()) {
@@ -36,9 +25,6 @@
}
- public QName getTagQName() {
-
- return SEND_Q;
- }
+
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/AddressingProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/AddressingProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/AddressingProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/AddressingProcessor.java Fri Nov 25 05:28:14 2005
@@ -33,9 +33,6 @@
*
*/
public class AddressingProcessor extends AbstractProcessor {
- private static final QName ADD_Q = new QName(Constants.SYNAPSE_NAMESPACE,
- "addressing");
-
private Log log = LogFactory.getLog(getClass());
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
@@ -75,9 +72,5 @@
return true;
}
- public QName getTagQName() {
-
- return ADD_Q;
- }
-
+
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/ClassMediatorProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/ClassMediatorProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/ClassMediatorProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/ClassMediatorProcessor.java Fri Nov 25 05:28:14 2005
@@ -1,10 +1,6 @@
package org.apache.synapse.processors.mediatortypes;
-import javax.xml.namespace.QName;
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMElement;
-import org.apache.synapse.Constants;
import org.apache.synapse.SynapseEnvironment;
import org.apache.synapse.SynapseException;
import org.apache.synapse.SynapseMessage;
@@ -12,31 +8,16 @@
import org.apache.synapse.processors.AbstractProcessor;
public class ClassMediatorProcessor extends AbstractProcessor {
- private static final QName CLM_Q = new QName(Constants.SYNAPSE_NAMESPACE,
- "classmediator");
private Class clazz = null;
- public void compile(SynapseEnvironment se, OMElement el) {
- super.compile(se, el);
-
- OMAttribute clsName = el.getAttribute(new QName("class"));
- if (clsName == null)
- throw new SynapseException("missing class attribute on element"
- + el.toString());
- try {
- clazz = se.getClassLoader().loadClass(clsName.getAttributeValue());
- } catch (ClassNotFoundException e) {
- throw new SynapseException("class loading error", e);
- }
-
- }
+
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
Mediator m = null;
try {
- m = (Mediator) clazz.newInstance();
+ m = (Mediator) getClazz().newInstance();
} catch (Exception e) {
throw new SynapseException(e);
}
@@ -44,8 +25,13 @@
}
- public QName getTagQName() {
- return CLM_Q;
+
+ public void setClazz(Class clazz) {
+ this.clazz = clazz;
+ }
+
+ public Class getClazz() {
+ return clazz;
}
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/axis2/ServiceMediatorProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/axis2/ServiceMediatorProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/axis2/ServiceMediatorProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/mediatortypes/axis2/ServiceMediatorProcessor.java Fri Nov 25 05:28:14 2005
@@ -1,6 +1,6 @@
package org.apache.synapse.processors.mediatortypes.axis2;
-import javax.xml.namespace.QName;
+
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
@@ -12,8 +12,6 @@
import org.apache.axis2.description.AxisService;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.AxisEngine;
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMElement;
import org.apache.axis2.util.Utils;
import org.apache.synapse.Constants;
import org.apache.synapse.SynapseEnvironment;
@@ -23,19 +21,10 @@
import org.apache.synapse.processors.AbstractProcessor;
public class ServiceMediatorProcessor extends AbstractProcessor {
- private static final QName tagName = new QName(Constants.SYNAPSE_NAMESPACE,
- "servicemediator");
+
private String serviceName = null;
- public void compile(SynapseEnvironment se, OMElement el) {
- OMAttribute attr = el.getAttribute(new QName("service"));
- if (attr == null)
- throw new SynapseException(
- "<servicemediator> must have <service> attribute");
- serviceName = attr.getAttributeValue();
- }
-
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
MessageContext messageContext = null;
try {
@@ -57,10 +46,10 @@
AxisService as = null;
AxisOperation ao = null;
- as = ac.getService(serviceName);
+ as = ac.getService(getServiceName());
if (as == null)
throw new SynapseException("cannot locate service "
- + serviceName);
+ + getServiceName());
ao = as.getOperation(Constants.MEDIATE_OPERATION_NAME);
OperationContext oc = OperationContextFactory
@@ -89,9 +78,12 @@
}
- public QName getTagQName() {
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
- return tagName;
+ public String getServiceName() {
+ return serviceName;
}
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/RegexProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/RegexProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/RegexProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/RegexProcessor.java Fri Nov 25 05:28:14 2005
@@ -2,81 +2,50 @@
import java.util.regex.Pattern;
-import javax.xml.namespace.QName;
-
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMElement;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.Constants;
+
+import org.apache.synapse.HeaderType;
import org.apache.synapse.SynapseEnvironment;
-import org.apache.synapse.SynapseException;
import org.apache.synapse.SynapseMessage;
-import org.apache.synapse.processors.AllProcessor;
+
+import org.apache.synapse.processors.ListProcessor;
/**
* @author Paul Fremantle
*
*/
-public class RegexProcessor extends AllProcessor {
- private static final String REGEX = "regex";
-
- private static final QName REGEX_Q = new QName(Constants.SYNAPSE_NAMESPACE,
- REGEX);
-
- private static final QName REGEX_PATTERN_ATT_Q = new QName("pattern");
-
- private static final QName REGEX_PROPERTY_ATT_Q = new QName("property");
-
- private static final QName REGEX_HEADER_ATT_Q = new QName("message-address");
-
+public class RegexProcessor extends ListProcessor {
private Pattern pattern = null;
private Log log = LogFactory.getLog(getClass());
- private int headerType = 0;
+ private HeaderType headerType = new HeaderType();
private String property = null;
- private final static int TO = 1, FROM = 2, FAULT = 3, ACTION = 4;
+ public void setHeaderType(String header) {
+ headerType.setHeaderType(header);
+ }
+
+ public String getHeaderType() {
+ return headerType.getHeaderType();
+ }
- private final static String STRTO = "to", STRFROM = "from",
- STRFAULT = "faultto", STRACTION = "action";
+ public void setPattern(String p) {
+ pattern = Pattern.compile(p);
+ }
- public void compile(SynapseEnvironment se, OMElement el) {
- super.compile(se, el);
- OMAttribute patt = el.getAttribute(REGEX_PATTERN_ATT_Q);
- if (patt == null) {
- throw new SynapseException(REGEX + " must have "
- + REGEX_PATTERN_ATT_Q + " attribute: " + el.toString());
- }
+ public String getPattern() {
+ return pattern.toString();
+ }
- OMAttribute prop = el.getAttribute(REGEX_PROPERTY_ATT_Q);
- OMAttribute head = el.getAttribute(REGEX_HEADER_ATT_Q);
- if (prop == null && head == null) {
- throw new SynapseException(REGEX + " must have either "
- + REGEX_PROPERTY_ATT_Q + " or " + REGEX_HEADER_ATT_Q
- + " attributes: " + el.toString());
- }
- pattern = Pattern.compile(patt.getAttributeValue());
- if (prop != null) {
- property = prop.getAttributeValue();
- } else {
- String header = head.getAttributeValue();
- if (header.equalsIgnoreCase(STRTO))
- headerType = TO;
- else if (header.equalsIgnoreCase(STRFROM))
- headerType = FROM;
- else if (header.equalsIgnoreCase(STRFAULT))
- headerType = FAULT;
- else if (header.equalsIgnoreCase(STRACTION))
- headerType = ACTION;
- else
- throw new SynapseException(
- "unknown header attribute value in regex: " + header);
+ public void setPropertyName(String p) {
+ this.property = p;
+ }
- }
+ public String getPropertyName() {
+ return property;
}
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
@@ -89,49 +58,16 @@
if (property != null) {
toMatch = smc.getProperty(property).toString();
} else {
- // must be header type if we got here
-
- switch (headerType) {
- case 0: {
- log.debug("trying to process with empty property and header");
- return true;
- }
- case TO: {
- if (smc.getTo() == null)
- return true;
- toMatch = smc.getTo().getAddress();
- break;
- }
- case FROM: {
- if (smc.getFrom() == null)
- return true;
- toMatch = smc.getFrom().getAddress();
- break;
- }
- case FAULT: {
- if (smc.getFaultTo() == null)
- return true;
- toMatch = smc.getFaultTo().getAddress();
- break;
- }
- case ACTION: {
- if (smc.getWSAAction() == null)
- return true;
- toMatch = smc.getWSAAction();
- break;
- }
- }
+ toMatch = headerType.getHeader(smc);
}
+ if (toMatch==null) return true;
+
if (pattern.matcher(toMatch).matches()) {
log.debug("Regex pattern " + pattern.toString() + " matched "
+ toMatch);
return super.process(se, smc);
}
return true;
- }
-
- public QName getTagQName() {
- return REGEX_Q;
}
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/XPathProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/XPathProcessor.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/XPathProcessor.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/rules/XPathProcessor.java Fri Nov 25 05:28:14 2005
@@ -1,20 +1,12 @@
package org.apache.synapse.processors.rules;
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axis2.om.OMAttribute;
-import org.apache.axis2.om.OMElement;
-import org.apache.axis2.om.OMNamespace;
import org.apache.axis2.om.xpath.AXIOMXPath;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.Constants;
import org.apache.synapse.SynapseEnvironment;
import org.apache.synapse.SynapseException;
import org.apache.synapse.SynapseMessage;
-import org.apache.synapse.processors.AllProcessor;
+import org.apache.synapse.processors.ListProcessor;
import org.jaxen.JaxenException;
/**
@@ -25,44 +17,17 @@
* if the test is true
*
*/
-public class XPathProcessor extends AllProcessor {
- private static final String XPATH = "xpath";
-
- private static final QName XPATH_Q = new QName(Constants.SYNAPSE_NAMESPACE,
- "xpath");
-
- private static final QName XPATH_EXPRESSION_ATT_Q = new QName("expr");
+public class XPathProcessor extends ListProcessor {
private Log log = LogFactory.getLog(getClass());
private AXIOMXPath xp = null;
- /* (non-Javadoc)
- * @see org.apache.synapse.spi.Processor#compile(org.apache.synapse.api.SynapseEnvironment, org.apache.axis2.om.OMElement)
- */
- public void compile(SynapseEnvironment se, OMElement el) {
- super.compile(se, el);
- OMAttribute xpath = el.getAttribute(XPATH_EXPRESSION_ATT_Q);
- if (xpath == null) {
- throw new SynapseException(XPATH + " must have "
- + XPATH_EXPRESSION_ATT_Q + " attribute: " + el.toString());
- }
-
- try {
- xp = new AXIOMXPath(xpath.getAttributeValue());
- Iterator it = el.getAllDeclaredNamespaces();
- while (it.hasNext()) {
- OMNamespace n = (OMNamespace) it.next();
- xp.addNamespace(n.getPrefix(), n.getName());
- }
- } catch (JaxenException e) {
- throw new SynapseException("Problem with xpath expression "
- + xpath.getAttributeValue(), e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.synapse.spi.Processor#process(org.apache.synapse.api.SynapseEnvironment, org.apache.synapse.api.SOAPMessageContext)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.synapse.spi.Processor#process(org.apache.synapse.api.SynapseEnvironment,
+ * org.apache.synapse.api.SOAPMessageContext)
*/
public boolean process(SynapseEnvironment se, SynapseMessage smc) {
if (xp == null) {
@@ -83,9 +48,25 @@
return true;
}
- public QName getTagQName() {
+ public void setXPathExpr(String expr) {
+ try {
+ xp = new AXIOMXPath(expr);
+ } catch (JaxenException je) {
+ throw new SynapseException(je);
+ }
+ }
+
+ public String getXPathExpr() {
+ return xp.toString();
+ }
+
+ public void addXPathNamespace(String prefix, String uri) {
+ try {
+ xp.addNamespace(prefix, uri);
+ } catch (JaxenException je) {
+ throw new SynapseException(je);
+ }
- return XPATH_Q;
}
}
Modified: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/xml/Configurator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/xml/Configurator.java?rev=348942&r1=348941&r2=348942&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/xml/Configurator.java (original)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/xml/Configurator.java Fri Nov 25 05:28:14 2005
@@ -27,11 +27,12 @@
*/
public static Processor getProcessor(SynapseEnvironment synapseEnv, OMElement element) {
OMNamespace n = element.getNamespace();
- Class cls = ProcessorFinder.find(new QName(n.getName(), element
+ System.out.println(n.getName());
+ Class cls = ProcessorConfiguratorFinder.find(new QName(n.getName(), element
.getLocalName()));
try {
- Processor p = (Processor) cls.newInstance();
- p.compile(synapseEnv, element);
+ ProcessorConfigurator pc = (ProcessorConfigurator) cls.newInstance();
+ Processor p = pc.compile(synapseEnv, element);
return p;
} catch (InstantiationException e) {
throw new SynapseException(e);
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org