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:32:02 UTC

svn commit: r348945 - in /incubator/synapse/trunk/scratch/prototype3: SpringMediator/META-INF/services/ SpringMediator/org/apache/synapse/processors/mediatortypes/spring/ src/org/apache/synapse/ src/org/apache/synapse/processors/ src/org/apache/synapse...

Author: pzf
Date: Fri Nov 25 05:31:53 2005
New Revision: 348945

URL: http://svn.apache.org/viewcvs?rev=348945&view=rev
Log:
more xml separation

Added:
    incubator/synapse/trunk/scratch/prototype3/SpringMediator/META-INF/services/org.apache.synapse.ProcessorConfigurator
    incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessorConfigurator.java
    incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/HeaderType.java
    incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/ListProcessor.java
    incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/FaultProcessor.java

Added: incubator/synapse/trunk/scratch/prototype3/SpringMediator/META-INF/services/org.apache.synapse.ProcessorConfigurator
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/SpringMediator/META-INF/services/org.apache.synapse.ProcessorConfigurator?rev=348945&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/SpringMediator/META-INF/services/org.apache.synapse.ProcessorConfigurator (added)
+++ incubator/synapse/trunk/scratch/prototype3/SpringMediator/META-INF/services/org.apache.synapse.ProcessorConfigurator Fri Nov 25 05:31:53 2005
@@ -0,0 +1 @@
+org.apache.synapse.processors.mediatortypes.spring.SpringMediatorProcessorConfigurator
\ No newline at end of file

Added: incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessorConfigurator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessorConfigurator.java?rev=348945&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessorConfigurator.java (added)
+++ incubator/synapse/trunk/scratch/prototype3/SpringMediator/org/apache/synapse/processors/mediatortypes/spring/SpringMediatorProcessorConfigurator.java Fri Nov 25 05:31:53 2005
@@ -0,0 +1,78 @@
+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.Processor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseException;
+
+
+
+import org.apache.synapse.xml.AbstractProcessorConfigurator;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ByteArrayResource;
+
+
+
+public class SpringMediatorProcessorConfigurator extends AbstractProcessorConfigurator {
+	private static final QName tagName = new QName(Constants.SYNAPSE_NAMESPACE+"/spring", "springmediator");
+	public Processor compile(SynapseEnvironment se, OMElement el) {
+		SpringMediatorProcessor smp = new SpringMediatorProcessor();
+		super.compile(se,el,smp);
+		
+		OMAttribute bean = el.getAttribute(new QName("bean"));
+		if (bean == null) throw new SynapseException("missing bean attribute on "+el.toString());
+		
+		smp.setBeanName(bean.getAttributeValue().trim());
+		
+		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();
+		smp.setContext(ctx);
+		return smp;
+		
+		
+		
+	}
+
+	public QName getTagQName() {
+		
+		return tagName;
+	}
+
+}

Added: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/HeaderType.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/HeaderType.java?rev=348945&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/HeaderType.java (added)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/HeaderType.java Fri Nov 25 05:31:53 2005
@@ -0,0 +1,107 @@
+package org.apache.synapse;
+
+import org.apache.axis2.addressing.EndpointReference;
+
+public class HeaderType {
+
+	private final static int TO = 1, FROM = 2, FAULT = 3, ACTION = 4,
+			REPLYTO = 5;
+
+	public final static String STRTO = "to", STRFROM = "from",
+			STRFAULT = "faultto", STRACTION = "action", STRREPLYTO = "replyto";
+
+	private int headerType = 0;
+
+	public void setHeaderType(String header) {
+		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 type");
+	}
+
+	public String getHeaderType() {
+		switch (headerType) {
+
+		case TO:
+			return STRTO;
+		case FROM:
+			return STRFROM;
+		case FAULT:
+			return STRFAULT;
+		case ACTION:
+			return STRACTION;
+		case REPLYTO:
+			return STRREPLYTO;
+
+		}
+		return null;
+	}
+
+	public String getHeader(SynapseMessage sm) {
+		switch (headerType) {
+		case TO: {
+			if (sm.getTo() != null)
+				return sm.getTo().getAddress();
+
+		}
+		case FROM: {
+			if (sm.getFrom() != null)
+				return sm.getFrom().getAddress();
+			break;
+		}
+		case FAULT: {
+			if (sm.getFaultTo() != null)
+				return sm.getFaultTo().getAddress();
+			break;
+		}
+		case ACTION: {
+			if (sm.getWSAAction() != null)
+				return sm.getWSAAction();
+			break;
+		}
+		case REPLYTO: {
+			if (sm.getReplyTo() != null)
+				return sm.getReplyTo().getAddress();
+			break;
+		}
+		}
+
+		return null;
+	}
+
+	public void setHeader(SynapseMessage sm, String value) {
+		switch (headerType) {
+		case 0: {
+			throw new SynapseException(
+					"headerType=0 in setHeader. Assume called setHeader before setHeaderType");
+		}
+
+		case TO: {
+
+			sm.setTo(new EndpointReference(value));
+			break;
+		}
+		case FROM: {
+			sm.setFrom(new EndpointReference(value));
+			break;
+		}
+		case REPLYTO: {
+			sm.setReplyTo(new EndpointReference(value));
+			break;
+		}
+		case ACTION: {
+			sm.setWSAAction(value);
+			break;
+		}
+
+		}
+	}
+}

Added: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/ListProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/ListProcessor.java?rev=348945&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/ListProcessor.java (added)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/ListProcessor.java Fri Nov 25 05:31:53 2005
@@ -0,0 +1,49 @@
+package org.apache.synapse.processors;
+
+import java.util.Iterator;
+
+import java.util.List;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Processor;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseMessage;
+
+
+/**
+ * @author Paul Fremantle This class simply runs the message through all rules,
+ *         stages, mediations that it has as subelements It is a way of grouping
+ *         stuff.
+ * 
+ */
+public abstract class ListProcessor extends AbstractProcessor {
+	
+	private Log log = LogFactory.getLog(getClass());
+
+	List processors = null;
+
+	
+	public boolean process(SynapseEnvironment se, SynapseMessage smc) {
+		if (processors == null) {
+			log.info("process called on empty processor list");
+			return true;
+		}
+		Iterator it = processors.iterator();
+		while (it.hasNext()) {
+			Processor p = (Processor) it.next();
+			if (!p.process(se,smc))
+				return false;
+		}
+		return true;
+	}
+
+	public void setList(List p) {
+		processors = p;
+	}
+	public List getList() {
+		return processors;
+	}
+
+}

Added: incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/FaultProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/FaultProcessor.java?rev=348945&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/FaultProcessor.java (added)
+++ incubator/synapse/trunk/scratch/prototype3/src/org/apache/synapse/processors/builtin/axis2/FaultProcessor.java Fri Nov 25 05:31:53 2005
@@ -0,0 +1,60 @@
+package org.apache.synapse.processors.builtin.axis2;
+
+
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseEnvironment;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.axis2.Axis2SOAPMessageContext;
+import org.apache.synapse.processors.AbstractProcessor;
+
+/**
+ * @author Paul Fremantle
+ *         <p>
+ *         <xmp><synapse:fault/> </xmp>
+ * 
+ * 
+ */
+public class FaultProcessor extends AbstractProcessor {
+	
+	private Log log = LogFactory.getLog(getClass());
+
+	public boolean process(SynapseEnvironment se, SynapseMessage smc) {
+		log.debug("process");
+		try {
+
+			MessageContext messageContext = ((Axis2SOAPMessageContext) smc)
+					.getMessageContext();
+			MessageContext outMC = Utils
+					.createOutMessageContext(messageContext);
+			outMC.setConfigurationContext(messageContext.getSystemContext());
+			outMC.setServerSide(true);
+
+			outMC.setEnvelope(OMAbstractFactory.getSOAP11Factory()
+					.getDefaultFaultEnvelope());
+
+			AxisEngine ae = new AxisEngine(messageContext.getSystemContext());
+			Object os = messageContext
+					.getProperty(MessageContext.TRANSPORT_OUT);
+			outMC.setProperty(MessageContext.TRANSPORT_OUT, os);
+			Object ti = messageContext
+					.getProperty(HTTPConstants.HTTPOutTransportInfo);
+			outMC.setProperty(HTTPConstants.HTTPOutTransportInfo, ti);
+
+			ae.send(outMC);
+		} catch (AxisFault e) {
+			throw new SynapseException(e);
+		}
+		return false;
+	}
+
+	
+}



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