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/04 01:13:46 UTC

svn commit: r330666 - in /incubator/synapse/trunk/scratch/paul2/synapsejoint: ./ org/apache/synapse/ org/apache/synapse/axis2/

Author: pzf
Date: Thu Nov  3 16:13:31 2005
New Revision: 330666

URL: http://svn.apache.org/viewcvs?rev=330666&view=rev
Log:
significant changes and bad coding

Modified:
    incubator/synapse/trunk/scratch/paul2/synapsejoint/.classpath
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/Rule.class
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/Rule.java
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleEngine.class
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleEngine.java
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleList.class
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleList.java
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/MediatorExecutor.class
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/MediatorExecutor.java
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/Sender.class
    incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/Sender.java

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/.classpath
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/.classpath?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/paul2/synapsejoint/.classpath (original)
+++ incubator/synapse/trunk/scratch/paul2/synapsejoint/.classpath Thu Nov  3 16:13:31 2005
@@ -5,5 +5,8 @@
 	<classpathentry kind="lib" path="C:/axdb/target/lib/axis2-0.92.jar"/>
 	<classpathentry kind="lib" path="C:/axdb/target/lib/stax-api-1.0.jar"/>
 	<classpathentry kind="lib" path="C:/axdb/target/lib/jaxen-1.1-beta-7.jar"/>
+	<classpathentry kind="lib" path="C:/spring/dist/spring-context.jar"/>
+	<classpathentry kind="lib" path="C:/spring/dist/spring-core.jar"/>
+	<classpathentry kind="lib" path="C:/spring/dist/spring.jar"/>
 	<classpathentry kind="output" path=""/>
 </classpath>

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/Rule.class
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/Rule.class?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/Rule.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/Rule.java?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/Rule.java (original)
+++ incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/Rule.java Thu Nov  3 16:13:31 2005
@@ -18,13 +18,13 @@
 import org.apache.synapse.axis2.Expression;
 
 
-
 public class Rule {
 	private Expression expr= null;
 	private String mediatorName = null;
 	private boolean secure = false;
 	private boolean reliable = false;
 	private boolean transactional = false;
+	private Object beanFactory = null;
 	public void setExpression(Expression expr) {
 		this.expr = expr;
 	}
@@ -74,4 +74,9 @@
 		
 		return sb.toString();
 	}
+	public void setSpringBeanFactory(Object bf) {
+		this.beanFactory  = bf;
+		
+	}
+	public Object getSpringBeanFactory() { return beanFactory; }
 }

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleEngine.class
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleEngine.class?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleEngine.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleEngine.java?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleEngine.java (original)
+++ incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleEngine.java Thu Nov  3 16:13:31 2005
@@ -22,7 +22,7 @@
 import org.apache.axis2.context.MessageContext;
 import org.apache.synapse.axis2.Expression;
 import org.apache.synapse.axis2.MediatorExecutor;
-import org.apache.synapse.axis2.Sender;
+
 
 // This class does the hard work, relying on OM/MC for the input
 // and using Expression to match, MedEx to dispatch, and Sender to call on
@@ -31,8 +31,8 @@
 	
 	public RuleEngine(String ruleFile) {
 		
-		//ClassLoader cl = getClass().getClassLoader();
-		//InputStream ruleIS = cl.getResourceAsStream(ruleFile);
+		ClassLoader cl = getClass().getClassLoader();
+		
 		InputStream ruleIS =null;
 		try {
 			ruleIS = new FileInputStream(ruleFile);
@@ -41,7 +41,7 @@
 			e.printStackTrace();
 		}
 		if (ruleIS==null) throw new SynapseException("Can't locate rule file: "+ruleFile);
-		rl = new RuleList(ruleIS);
+		rl = new RuleList(ruleIS, cl);
 	}
 	
 	public void process(MessageContext messageContext) {
@@ -54,13 +54,13 @@
 				if (e.match(messageContext))
 				{
 					
-					boolean cont = MediatorExecutor.execute(r.getMediatorName(), messageContext); 
+					boolean cont = MediatorExecutor.execute(r, messageContext); 
 					if (!cont) return;
 				}
 		}
 		// send now
 			
-		Sender.send(messageContext);
+		//Sender.send(messageContext);
 	}
 
 	

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleList.class
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleList.class?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleList.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleList.java?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleList.java (original)
+++ incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/RuleList.java Thu Nov  3 16:13:31 2005
@@ -14,85 +14,141 @@
  * limitations under the License.
  */
 package org.apache.synapse;
+
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
 
 import javax.xml.stream.XMLStreamReader;
 
 
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMNamespace;
+
 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
 import org.apache.synapse.axis2.Expression;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ByteArrayResource;
 
 public class RuleList extends ArrayList {
 	// private namespaceContext
-	
+
 	private String name = null;
 
 	private static final long serialVersionUID = 6108743941694238422L;
+
 	public static final String namespace = "http://ws.apache.org/synapse/ns/rulelist/1";
-	public static final QName ruleQ = new QName(namespace,"rule");
-	public static final QName rulelistQ = new QName(namespace,"rulelist");
-	public static final QName nameQ = new QName("","name");
-	public static final QName xpathQ = new QName("","xpath");
-	public static final QName mediatorQ = new QName("","mediator");
-	public static final QName secureQ = new QName("","secure");
-	public static final QName reliableQ = new QName("","reliable");
-	public static final QName transactionalQ = new QName("","transactional");
-	
-	public RuleList(InputStream in) {
+
+	public static final QName ruleQ = new QName(namespace, "rule");
+
+	public static final QName rulelistQ = new QName(namespace, "rulelist");
+
+	public static final QName nameQ = new QName("", "name");
+
+	public static final QName xpathQ = new QName("", "xpath");
+
+	public static final QName mediatorQ = new QName("", "mediator");
+
+	public static final QName secureQ = new QName("", "secure");
+
+	public static final QName reliableQ = new QName("", "reliable");
+
+	public static final QName transactionalQ = new QName("", "transactional");
+
+	public RuleList(InputStream in, ClassLoader cl) {
 		XMLInputFactory xif = XMLInputFactory.newInstance();
 		try {
 			XMLStreamReader xsr = xif.createXMLStreamReader(in);
 			StAXOMBuilder builder = new StAXOMBuilder(xsr);
 			OMElement rulelist = builder.getDocumentElement();
-			
-			
-		
-			
-			if (!rulelist.getQName().equals(rulelistQ)) throw new Exception("not a "+rulelistQ.toString()+" element");
-			
-			if (rulelist.getAttribute(nameQ)==null) throw new Exception("no "+nameQ.toString()+" attribute");
+
+			if (!rulelist.getQName().equals(rulelistQ))
+				throw new Exception("not a " + rulelistQ.toString()
+						+ " element");
+
+			if (rulelist.getAttribute(nameQ) == null)
+				throw new Exception("no " + nameQ.toString() + " attribute");
 			String rlname = rulelist.getAttribute(nameQ).getAttributeValue();
 			this.setName(rlname);
-			
-					
-			
+
 			Iterator ruleIt = rulelist.getChildrenWithName(ruleQ);
-			
+
 			while (ruleIt.hasNext()) {
-				OMElement rule = (OMElement)ruleIt.next();
+				OMElement rule = (OMElement) ruleIt.next();
 				Rule r = new Rule();
-				if (rule.getAttribute(xpathQ)==null) throw new Exception("missing "+xpathQ.toString()+" attribute");
-				
-				Expression expr = new Expression(rule.getAttribute(xpathQ).getAttributeValue());
+				if (rule.getAttribute(xpathQ) == null)
+					throw new Exception("missing " + xpathQ.toString()
+							+ " attribute");
+
+				Expression expr = new Expression(rule.getAttribute(xpathQ)
+						.getAttributeValue());
 				Iterator i = rulelist.getAllDeclaredNamespaces();
 				while (i.hasNext()) {
-					OMNamespace n = (OMNamespace)i.next();
-					expr.addNamespace(n.getPrefix(),n.getName());
+					OMNamespace n = (OMNamespace) i.next();
+					expr.addNamespace(n.getPrefix(), n.getName());
 				}
-					
+
 				r.setExpression(expr);
-				if (rule.getAttribute(mediatorQ)==null) throw new Exception("missing "+mediatorQ.toString()+" attribute");
-				r.setMediatorName(rule.getAttribute(mediatorQ).getAttributeValue());
-				if (rule.getAttribute(reliableQ)!=null) r.setReliable(isTrue(rule.getAttribute(reliableQ).getAttributeValue()));
-				if (rule.getAttribute(secureQ)!=null) r.setSecure(isTrue(rule.getAttribute(secureQ).getAttributeValue()));
-				if (rule.getAttribute(transactionalQ)!=null) r.setTransactional(isTrue(rule.getAttribute(transactionalQ).getAttributeValue()));
+				if (rule.getAttribute(mediatorQ) == null)
+					throw new Exception("missing " + mediatorQ.toString()
+							+ " attribute");
+				r.setMediatorName(rule.getAttribute(mediatorQ)
+						.getAttributeValue());
+				if (rule.getAttribute(reliableQ) != null)
+					r.setReliable(isTrue(rule.getAttribute(reliableQ)
+							.getAttributeValue()));
+				if (rule.getAttribute(secureQ) != null)
+					r.setSecure(isTrue(rule.getAttribute(secureQ)
+							.getAttributeValue()));
+				if (rule.getAttribute(transactionalQ) != null)
+					r.setTransactional(isTrue(rule.getAttribute(transactionalQ)
+							.getAttributeValue()));
+
+				Iterator it2 = rule.getChildElements();
+				while (it2.hasNext()) {
+					OMElement el = (OMElement) it2.next();
+					if (el.getLocalName().equals("beans")) {
+
+						ByteArrayOutputStream baos = new ByteArrayOutputStream();
+						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);
+						
+						xsw.setDefaultNamespace(el.getNamespace().getName());
+						el.serialize(xsw);
+						baos.close();
+						GenericApplicationContext ctx = new GenericApplicationContext();
+						XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(
+								ctx);
+						byte[] bytes = baos.toByteArray();
+						System.out.println(new String(bytes));
+						xbdr.loadBeanDefinitions(new ByteArrayResource(bytes));
+						ctx.setClassLoader(cl);
+						ctx.refresh();
+
+						r.setSpringBeanFactory(ctx);
+						continue;
+					}
+				}
+
 				this.add(r);
 			}
-			
-			
+
 		} catch (Exception e) {
-			
+
 			e.printStackTrace();
 		}
-		
-		
+
 	}
 
 	public void setName(String name) {
@@ -102,19 +158,19 @@
 	public String getName() {
 		return name;
 	}
-	
+
 	private boolean isTrue(String att) {
 		char c = att.toLowerCase().charAt(0);
-		return c=='t' || c=='y';
+		return c == 't' || c == 'y';
 	}
-	
+
 	public String toString() {
 		StringBuffer sb = new StringBuffer();
-		sb.append("[rulelist('"+name+"')]\n");
-		int i=1;
+		sb.append("[rulelist('" + name + "')]\n");
+		int i = 1;
 		Iterator it = this.iterator();
 		while (it.hasNext()) {
-			Rule r = (Rule)it.next();
+			Rule r = (Rule) it.next();
 			sb.append(i++);
 			sb.append('.');
 			sb.append(' ');
@@ -123,7 +179,5 @@
 		}
 		return sb.toString();
 	}
-	
-}
-
 
+}

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/MediatorExecutor.class
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/MediatorExecutor.class?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/MediatorExecutor.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/MediatorExecutor.java?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/MediatorExecutor.java (original)
+++ incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/MediatorExecutor.java Thu Nov  3 16:13:31 2005
@@ -26,49 +26,84 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.util.Utils;
+import org.apache.synapse.Rule;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.mediator.MediatorMessageReceiver;
 
 public class MediatorExecutor {
-		
+
 	// exexute mediators by calling them as services
 
-	public static boolean execute(String mediatorName, MessageContext messageContext) {
-		
-		ConfigurationContext cc = messageContext.getSystemContext(); 
+	public static boolean execute(Rule r, MessageContext messageContext) {
+
+		ConfigurationContext cc = messageContext.getSystemContext();
 		AxisConfiguration ac = cc.getAxisConfiguration();
 		AxisEngine ae = new AxisEngine(cc);
-			
+
 		AxisService as = null;
 		AxisOperation ao = null;
 		try {
-			
-			as = ac.getService(mediatorName);
-			if (as!=null) {
+			if (r.getSpringBeanFactory() != null) {
+				as = ac.getService("springmediator");
+				messageContext.setProperty(
+						"synapse.mediator.spring.beanFactory", r
+								.getSpringBeanFactory());
+				messageContext.setProperty("synapse.spring.mediatorName", r
+						.getMediatorName());
+
+			}
+			if (as == null) {
+
+				as = ac.getService(r.getMediatorName());
+			}
+			if (as == null) {
+				Class c = null;
+				try {
+					c = messageContext.getSystemContext()
+							.getAxisConfiguration().getService("classmediator")
+							.getClassLoader().loadClass(r.getMediatorName());
+
+				} catch (ClassNotFoundException ce) {
+
+				}
+
+				if (c != null) {
+					messageContext.setProperty("synapse.mediator.class", c);
+					as = ac.getService("classmediator");
+
+				}
+			}
+			if (as == null) {
+				throw new SynapseException(
+						"Mediator "
+								+ r.getMediatorName()
+								+ " is not registered as a service in the current Axis Configuration");
+			}
+
 			ao = as.getOperation("mediate");
-			messageContext.setAxisService(as);
-			messageContext.setAxisOperation(ao);
-			
-			 OperationContext oc = OperationContextFactory.createOperationContext(ao
-		                .getAxisSpecifMEPConstant(), ao);
-		        ao.registerOperationContext(messageContext, oc);
-
-		        ServiceContext sc = Utils.fillContextInformation(ao, as, cc);//messageContext.getSystemContext());
-		        oc.setParent(sc);
-		        messageContext.setOperationContext(oc);
-		        messageContext.setServiceContext(sc);
+			OperationContext oc = OperationContextFactory
+					.createOperationContext(ao.getAxisSpecifMEPConstant(), ao);
+			ao.registerOperationContext(messageContext, oc);
+
+			ServiceContext sc = Utils.fillContextInformation(ao, as, cc);
+			oc.setParent(sc);
+			messageContext.setOperationContext(oc);
+			messageContext.setServiceContext(sc);
+
+			System.out.println(r.getMediatorName() + ":" + as.getName());
 
-			
+			messageContext.setAxisOperation(ao);
+			messageContext.setAxisService(as);
 			ae.receive(messageContext);
-			} else throw new SynapseException("Mediator "+mediatorName+" is not registered as a service in the current Axis Configuration");
+
 		} catch (AxisFault e) {
 			throw new SynapseException(e);
+
 		}
-		
-		return ((Boolean)messageContext.getProperty(MediatorMessageReceiver.RESPONSE_PROPERTY)).booleanValue();
 
-		
-		
-	}
+		return ((Boolean) messageContext
+				.getProperty(MediatorMessageReceiver.RESPONSE_PROPERTY))
+				.booleanValue();
 
+	}
 }

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/Sender.class
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/Sender.class?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/Sender.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/Sender.java?rev=330666&r1=330665&r2=330666&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/Sender.java (original)
+++ incubator/synapse/trunk/scratch/paul2/synapsejoint/org/apache/synapse/axis2/Sender.java Thu Nov  3 16:13:31 2005
@@ -80,6 +80,11 @@
 				ae.receive(outMsgContext);
 
 			} else {
+				if (messageContext.getEnvelope().getHeader() == null)
+					messageContext.getEnvelope().getBody().insertSiblingBefore(
+							OMAbstractFactory.getSOAP11Factory()
+									.getDefaultEnvelope().getHeader());
+
 				ae.send(messageContext);
 			}
 		} catch (AxisFault e) {



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