[overlord-commits] Overlord SVN: r532 - in cdl/trunk: runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful and 5 other directories.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Mon Mar 2 10:41:38 EST 2009


Author: jeff.yuchang
Date: 2009-03-02 10:41:38 -0500 (Mon, 02 Mar 2009)
New Revision: 532

Added:
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/LogicalCourier.java
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/StringUtils.java
Removed:
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/LogicalCourier.java
Modified:
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/SendMessageAction.java
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/Decision.java
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/IfAction.java
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/ReceiveMessageAction.java
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SendMessageAction.java
   cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SwitchAction.java
   cdl/trunk/samples/jbossesb/brokerage/supplier/stateful/pom.xml
   cdl/trunk/samples/pom.xml
Log:
[SOAG-91] Update the sendMessageAction.


Added: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/LogicalCourier.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/LogicalCourier.java	                        (rev 0)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/LogicalCourier.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2008,
+ */
+package org.jboss.soa.overlord.jbossesb;
+
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.addressing.eprs.*;
+import org.jboss.soa.esb.client.ServiceInvoker;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+
+/**
+ * This class providers the courier implementation associated
+ * with a LogicalEPR.
+ * 
+ * @author <a href="mailto:gary.brown at hattricksoftware.com">Gary Brown</a>
+ */
+public class LogicalCourier implements org.jboss.soa.esb.couriers.Courier {
+	
+	private ServiceInvoker serviceInvoker=null;
+	
+	/**
+	 * The constructor, supplied the logical EPR represented
+	 * by the courier.
+	 * 
+	 * @param epr The logical EPR
+	 * @throws MessageDeliverException
+	 */
+	public LogicalCourier(LogicalEPR epr)
+						throws MessageDeliverException {
+		serviceInvoker = epr.getServiceInvoker();
+	}
+	
+	/**
+	 * This method delivers the supplied message to the EPR
+	 * associated with the logical courier.
+	 * 
+	 * @param mesg The message
+	 */
+	public boolean deliver(Message mesg) throws CourierException,
+			MalformedEPRException {
+		
+		try {
+			serviceInvoker.deliverAsync(mesg);
+		} catch(MessageDeliverException e) {
+			throw new CourierException("Failed to deliver message", e);
+		}
+		
+		return(true);
+	}
+
+	/**
+	 * This method cleans up after the courier implementation
+	 * is no longer required.
+	 */
+	public void cleanup() {
+		serviceInvoker = null;
+	}
+
+}

Added: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/StringUtils.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/StringUtils.java	                        (rev 0)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/StringUtils.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2008,
+ */
+package org.jboss.soa.overlord.jbossesb;
+
+/**
+ * This utility class for keeping some common used methods to deal with String.
+ * 
+ * @author <a href="mailto:cyu at redhat.com">Jeff Yu</a>
+ *
+ */
+public class StringUtils {
+	
+	public static final boolean isNull(String string) {
+		if (string == null || "".equals(string.trim())) {
+			return true;
+		}
+		return false;
+	}
+	
+	public static final boolean isNotNull(String string) {
+		return !isNull(string);
+	}
+	
+
+}

Deleted: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/LogicalCourier.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/LogicalCourier.java	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/LogicalCourier.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -1,77 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and others contributors as indicated 
- * by the @authors tag. All rights reserved. 
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
- * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
- * MA  02110-1301, USA.
- * 
- * (C) 2008,
- */
-package org.jboss.soa.overlord.jbossesb.stateful;
-
-import org.jboss.soa.esb.addressing.MalformedEPRException;
-import org.jboss.soa.esb.couriers.CourierException;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.addressing.eprs.*;
-import org.jboss.soa.esb.client.ServiceInvoker;
-import org.jboss.soa.esb.listeners.message.MessageDeliverException;
-
-/**
- * This class providers the courier implementation associated
- * with a LogicalEPR.
- * 
- * @author <a href="mailto:gary.brown at hattricksoftware.com">Gary Brown</a>
- */
-public class LogicalCourier implements org.jboss.soa.esb.couriers.Courier {
-	
-	private ServiceInvoker serviceInvoker=null;
-	
-	/**
-	 * The constructor, supplied the logical EPR represented
-	 * by the courier.
-	 * 
-	 * @param epr The logical EPR
-	 * @throws MessageDeliverException
-	 */
-	public LogicalCourier(LogicalEPR epr)
-						throws MessageDeliverException {
-		serviceInvoker = epr.getServiceInvoker();
-	}
-	
-	/**
-	 * This method delivers the supplied message to the EPR
-	 * associated with the logical courier.
-	 * 
-	 * @param mesg The message
-	 */
-	public boolean deliver(Message mesg) throws CourierException,
-			MalformedEPRException {
-		
-		try {
-			serviceInvoker.deliverAsync(mesg);
-		} catch(MessageDeliverException e) {
-			throw new CourierException("Failed to deliver message", e);
-		}
-		
-		return(true);
-	}
-
-	/**
-	 * This method cleans up after the courier implementation
-	 * is no longer required.
-	 */
-	public void cleanup() {
-		serviceInvoker = null;
-	}
-
-}

Modified: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/SendMessageAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/SendMessageAction.java	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/SendMessageAction.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -31,8 +31,8 @@
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.format.MessageFactory;
 import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.overlord.jbossesb.LogicalCourier;
 import org.jboss.soa.overlord.jbossesb.stateful.Identity;
-import org.jboss.soa.overlord.jbossesb.stateful.LogicalCourier;
 import org.mvel.MVEL;
 
 

Modified: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/Decision.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/Decision.java	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/Decision.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -22,11 +22,20 @@
 import org.jboss.soa.esb.message.Message;
 
 /**
+ * This is the interface for {@link IfAction} decision-class attribute.
+ * That class has to implement this interface.
+ * 
  * @author <a href="mailto:cyu at redhat.com">Jeff Yu</a>
  *
  */
 public interface Decision {
 	
+	/**
+	 * Execute the decision business logic.
+	 * 
+	 * @param message Message that is on the ESB pipeline.
+	 * @return
+	 */
 	boolean executeDecision(Message message);
 	
 }

Modified: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/IfAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/IfAction.java	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/IfAction.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -28,6 +28,7 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.overlord.jbossesb.ClassLoaderUtil;
+import org.jboss.soa.overlord.jbossesb.StringUtils;
 import org.jboss.soa.overlord.jbossesb.stateless.Decision;
 
 
@@ -111,7 +112,7 @@
 		String category = branch.getAttribute(SERVICE_CATEGORY);
 		String name = branch.getAttribute(SERVICE_NAME);
 		
-		if (decisionClzString == null || "".equals(decisionClzString.trim())){
+		if (StringUtils.isNull(decisionClzString)){
 			throw new Exception("The decision-class attribute can not be null or empty string");
 		}
 		Class<?> decisionClz = ClassLoaderUtil.loadClass(decisionClzString);

Modified: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/ReceiveMessageAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/ReceiveMessageAction.java	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/ReceiveMessageAction.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -24,6 +24,7 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.overlord.jbossesb.MessageUtil;
+import org.jboss.soa.overlord.jbossesb.StringUtils;
 
 /**
  * The ReceiveMessageAction is used to explicitly define the message type that should be received.
@@ -61,7 +62,7 @@
 	
 	public Message process(Message message) throws Exception {
 		String expected = config.getAttribute(MESSAGE_TYPE);		
-		if (expected == null || "".equals(expected.trim())) {
+		if (StringUtils.isNull(expected)) {
 			throw new Exception("The messageType is not defined.");
 		}
 		

Modified: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SendMessageAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SendMessageAction.java	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SendMessageAction.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -20,10 +20,18 @@
 package org.jboss.soa.overlord.jbossesb.stateless.actions;
 
 import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.LogicalEPR;
 import org.jboss.soa.esb.client.ServiceInvoker;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierFactory;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.overlord.jbossesb.LogicalCourier;
 import org.jboss.soa.overlord.jbossesb.MessageUtil;
+import org.jboss.soa.overlord.jbossesb.StringUtils;
 
 /**
  * Deliver message to the target service.
@@ -53,7 +61,7 @@
 	<action class="org.jboss.soa.overlord.jbossesb.stateless.actions.SendMessageAction"
 				process="process" name="s4-3">
 		<property name="messageType" value="quoteList" />
-		<property name="clientEPR" value="buyer" />
+		<property name="clientRole" value="buyer" />
 	 </action>
  * }
  * </pre>
@@ -74,7 +82,7 @@
  * <h4>Description of configuration properties:</h4>
  *  <ul>
  *  <li><i>messageType </i> - Define the message type that is prepared to sent to.</li>
- *  <li><i>clientEPR</i> - This is JBossESB EPR Label, represents a JBossESB EPR that can be used to send a message to.</li>
+ *  <li><i>clientRole</i> - This is JBossESB EPR Label, represents a JBossESB EPR that can be used to send a message to.</li>
  *  <li><i>serviceName</i> - Mapped to JBossESB service-name.</li>
  *  <li><i>serviceCategory</i> - Mapped to JBossESB service-category.</li>
  *  <li><i>responseServiceName</i> - The service-name of the responded message.</li>
@@ -109,7 +117,7 @@
 	
 	public Message process(Message message) throws Exception {
 		String expected = config.getAttribute(MESSAGE_TYPE);		
-		if (expected == null || "".equals(expected.trim())) {
+		if (StringUtils.isNull(expected)) {
 			throw new Exception("The messageType is not defined.");
 		}
 		
@@ -123,15 +131,56 @@
 			throw new Exception ("Unexpected message type= "+ receivedMessageType + ", but expecting type="+ expected);
 		}
 		
+		Message deliverMessage = constructDeliverMessage(message);
+		
 		String category = config.getAttribute(SERVICE_CATEGORY);
 		String serviceName = config.getAttribute(SERVICE_NAME);
+		String clientRole = config.getAttribute(CLIENT_ROLE);
 		
-		ServiceInvoker invoker = new ServiceInvoker(category, serviceName);
-		invoker.deliverAsync(message);
+		if (StringUtils.isNotNull(category) && StringUtils.isNotNull(serviceName) 
+				&& StringUtils.isNotNull(clientRole)) {
+			throw new Exception ("[serviceCategory/serviceName] and [clientRole] can NOT co-exist.");
+		}
 		
-		//TODO: add logic for dealing with responseServiceCategory and responseServiceName
+		if (StringUtils.isNotNull(category) && StringUtils.isNotNull(serviceName)){
+			ServiceInvoker invoker = new ServiceInvoker(category, serviceName);
+			invoker.deliverAsync(deliverMessage);
+		} else if (StringUtils.isNotNull(clientRole)) {
+			deliverMessageFromEPR(message, deliverMessage);
+		} else {
+			throw new Exception ("Failed to send message, because can't find [serivceCategory/serviceName]," +
+					"nor clientRole.");
+		}
 		
 		return message;
+
 	}
+
 	
+	private Message constructDeliverMessage(Message message) {
+		Message deliverMessage = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+		deliverMessage.getBody().add(message.getBody().get());
+		
+		String respCategory = config.getAttribute(RESPONSE_SERVICE_CATEGORY);
+		String respName = config.getAttribute(RESPONSE_SERVICE_NAME);
+		
+		if (StringUtils.isNotNull(respCategory) && StringUtils.isNotNull(respName)) {
+			LogicalEPR lepr= new LogicalEPR(respCategory, respName);		        	
+        	deliverMessage.getHeader().getCall().setReplyTo(lepr);
+		}
+		return deliverMessage;
+	}
+
+	private void deliverMessageFromEPR(Message message, Message deliverMessage) throws  Exception {
+		EPR epr = message.getHeader().getCall().getReplyTo();
+		Courier courier = null;
+		// Workaround, as CourierFactory currently does not support logical EPRs.
+		if (epr instanceof LogicalEPR) {
+			courier = new LogicalCourier((LogicalEPR) epr);
+		} else {
+			courier = CourierFactory.getCourier(epr);
+		}
+		courier.deliver(deliverMessage);
+	}
+	
 }

Modified: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SwitchAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SwitchAction.java	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SwitchAction.java	2009-03-02 15:41:38 UTC (rev 532)
@@ -70,10 +70,18 @@
 	
 	public static final String MESSAGE_TYPE = "type";
 	
+	public static final String SERVICE_DESC_NAME = "serviceDescriptionName";
+	
+	public static final String CONVERSATION_TYPE = "conversationType";
+	
 	private ConfigTree config;
 	
 	private List<ConfigTree> caseBranchs = new LinkedList<ConfigTree>();
 	
+	private String serviceDescName;
+	
+	private String conversationType;
+	
 	public SwitchAction(ConfigTree config){
 		this.config = config;
 	}
@@ -110,6 +118,9 @@
 	
 	
 	private void parseConfiguration() {
+		serviceDescName = config.getAttribute(SERVICE_DESC_NAME);
+		conversationType = config.getAttribute(CONVERSATION_TYPE);
+		
 		ConfigTree[] children = config.getAllChildren();
 		for (ConfigTree ct : children) {
 			if (CASE_STATEMENT.equals(ct.getName())) {
@@ -117,5 +128,13 @@
 			}
 		}
 	}
+
+	public String getServiceDescName() {
+		return serviceDescName;
+	}
+
+	public String getConversationType() {
+		return conversationType;
+	}
 	
 }

Modified: cdl/trunk/samples/jbossesb/brokerage/supplier/stateful/pom.xml
===================================================================
--- cdl/trunk/samples/jbossesb/brokerage/supplier/stateful/pom.xml	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/samples/jbossesb/brokerage/supplier/stateful/pom.xml	2009-03-02 15:41:38 UTC (rev 532)
@@ -3,10 +3,10 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>org.jboss.soa.overlord.cdl.samples</groupId>
-	<artifactId>jbossesb-supplier</artifactId>
+	<artifactId>jbossesb-stateful-supplier</artifactId>
 	<version>1.0-SNAPSHOT</version>
 	<packaging>jboss-esb</packaging>
-	<name>Overlord::CDL::Samples::Supplier</name>
+	<name>Overlord::CDL::Samples::Stateful::Supplier</name>
 	<url>http://www.jboss.org/overlord</url>
 	
 	<parent>

Modified: cdl/trunk/samples/pom.xml
===================================================================
--- cdl/trunk/samples/pom.xml	2009-03-02 14:05:59 UTC (rev 531)
+++ cdl/trunk/samples/pom.xml	2009-03-02 15:41:38 UTC (rev 532)
@@ -21,10 +21,10 @@
 
 
 	<modules>
-		<module>jbossesb/purchasing/store</module>
-		<module>jbossesb/common/creditAgency</module>
-		<module>jbossesb/brokerage/broker</module>
-		<module>jbossesb/brokerage/supplier</module>
+		<module>jbossesb/purchasing/store/stateful</module>
+		<module>jbossesb/common/creditAgency/stateful</module>
+		<module>jbossesb/brokerage/broker/stateful</module>
+		<module>jbossesb/brokerage/supplier/stateful</module>
 	</modules>
 
    <build>




More information about the overlord-commits mailing list