[overlord-commits] Overlord SVN: r671 - in cdl/trunk/runtime/jbossesb/src: main/java/org/jboss/soa/overlord/jbossesb/actions and 2 other directories.
overlord-commits at lists.jboss.org
overlord-commits at lists.jboss.org
Fri Jul 17 04:57:47 EDT 2009
Author: jeff.yuchang
Date: 2009-07-17 04:57:47 -0400 (Fri, 17 Jul 2009)
New Revision: 671
Added:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/IfAction.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/ReceiveMessageAction.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/SendMessageAction.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/SwitchAction.java
cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/
cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/MVELUsageTest.java
cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/XMLUtilsTest.java
Removed:
cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/stateful/
Log:
[SOAG-110]
Added: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/IfAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/IfAction.java (rev 0)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/IfAction.java 2009-07-17 08:57:47 UTC (rev 671)
@@ -0,0 +1,149 @@
+/*
+ * 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.actions;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.client.ServiceInvoker;
+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.Decision;
+import org.jboss.soa.overlord.jbossesb.StringUtils;
+
+
+/**
+ * This action represents a choice between a set of specified paths
+ * based on the message that has occurred.
+ *
+ * <h4>Usage:</h4>
+ * <pre>
+ * {@literal
+ <action class="org.jboss.soa.overlord.jbossesb.actions.IfAction" name="c3" process="process">
+ <property name="paths">
+ <if service-category="PurchaseGoods.CreditAgency" service-name="CreditAgency.decision1" decision-class="org.jboss.soa.overlord.jbossesb.TestDecision"/>
+ <elseif service-category="PurchaseGoods.CreditAgency" service-name="CreditAgency.decision2" decision-class="org.jboss.soa.overlord.jbossesb.Test2ndDecision"/>
+ <else service-category="PurchaseGoods.CreditAgency" service-name="CreditAgency.decision3"/>
+ </property>
+ </action>
+ * }
+ * </pre>
+ *
+ * <h4>Description of configuration properties:</h4>
+ * <ul>
+ * <li><i>serivce-category</i> - mapped to JBoss ESB service-category.</li>
+ * <li><i>service-name</i> - mapped to JBossESB service-name.<li>
+ * <li><i>decision-class</i> - the class that implements {Decision} interface.</li>
+ * </ul>
+ *
+ *
+ * @author <a href="mailto:cyu at redhat.com">Jeff Yu</a>
+ *
+ */
+public class IfAction extends AbstractActionLifecycle{
+
+ public static final String SERVICE_CATEGORY = "service-category";
+ public static final String SERVICE_NAME = "service-name";
+ public static final String DECISION_CLASS = "decision-class";
+
+ private static final String IF_STATEMENT = "if";
+ private static final String ELSE_STATEMENT = "else";
+ private static final String ELSEIF_STATEMENT = "elseif";
+
+ private static Logger logger = Logger.getLogger(IfAction.class);
+
+ private ConfigTree config;
+
+ private ConfigTree ifBranch;
+
+ private List<ConfigTree> elseifBranchs = new LinkedList<ConfigTree>();
+
+ private ConfigTree elseBranch;
+
+ public IfAction(ConfigTree config) {
+ this.config = config;
+ }
+
+ public Message process(Message message) throws Exception {
+ parseConfiguration();
+
+ if (!executeConditionBranch(message, ifBranch)) {
+ boolean successFlag = false;
+ for (ConfigTree elseifBranch : elseifBranchs) {
+ if (executeConditionBranch(message, elseifBranch)) {
+ successFlag = true;
+ break;
+ }
+ }
+
+ if (!successFlag){
+ String category = elseBranch.getAttribute(SERVICE_CATEGORY);
+ String name = elseBranch.getAttribute(SERVICE_NAME);
+ ServiceInvoker invoker= new ServiceInvoker(category, name);
+ invoker.deliverAsync(message);
+ }
+ }
+
+ return message;
+ }
+
+ private boolean executeConditionBranch(Message message, ConfigTree branch) throws Exception {
+ String decisionClzString = branch.getAttribute(DECISION_CLASS);
+ String category = branch.getAttribute(SERVICE_CATEGORY);
+ String name = branch.getAttribute(SERVICE_NAME);
+
+ if (StringUtils.isNull(decisionClzString)){
+ throw new Exception("The decision-class attribute can not be null or empty string");
+ }
+ Class<?> decisionClz = ClassLoaderUtil.loadClass(decisionClzString);
+ if (!Decision.class.isAssignableFrom(decisionClz)){
+ throw new Exception("The decision-class of " + decisionClzString + " doesn't implement the Decision Interface.");
+ }
+
+ Decision decision = (Decision) decisionClz.newInstance();
+ if (decision.executeDecision(message)){
+ ServiceInvoker invoker= new ServiceInvoker(category, name);
+ invoker.deliverAsync(message);
+ logger.debug("The message has been delivered to service of [category=" + category + "/name=" + name + "]");
+ return true;
+ }
+
+ return false;
+ }
+
+
+ private void parseConfiguration() throws Exception {
+ ConfigTree[] children=config.getAllChildren();
+ for (ConfigTree ct : children) {
+ if (IF_STATEMENT.equals(ct.getName())) {
+ ifBranch = ct;
+ } else if (ELSEIF_STATEMENT.equals(ct.getName())) {
+ elseifBranchs.add(ct);
+ } else if (ELSE_STATEMENT.equals(ct.getName())){
+ elseBranch= ct;
+ } else {
+ throw new Exception("Unrecognized configuration Node in IfAction.");
+ }
+ }
+ }
+}
Added: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/ReceiveMessageAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/ReceiveMessageAction.java (rev 0)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/ReceiveMessageAction.java 2009-07-17 08:57:47 UTC (rev 671)
@@ -0,0 +1,107 @@
+/*
+ * 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.actions;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+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.EPRStore;
+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.
+ *
+ * <h4>Usage:</h4>
+ * <pre>
+ * {@literal
+ <action class="org.jboss.soa.overlord.jbossesb.actions.ReceiveMessageAction" name="c2" process="process">
+ <property name="messageType" value="CreditCheckRequest"/>
+ <property name="clientRole" value="Buyer" />
+ </action>
+ * }
+ * </pre>
+ *
+ * <h4>Description of configuration properties:</h4>
+ * <ul>
+ * <li><i>messageType </i> - Define the message type that should be received.</li>
+ * </ul>
+ *
+ * @author <a href="mailto:cyu at redhat.com">Jeff Yu</a>
+ *
+ */
+public class ReceiveMessageAction extends AbstractActionLifecycle{
+
+ public static final String OPERATION = "operation";
+
+ public static final String MESSAGE_TYPE = "messageType";
+
+ public static final String CLIENT_ROLE = "clientRole";
+
+ public static final String STORAGE_CLASS = "eprStore";
+
+ private static Logger logger = Logger.getLogger(ReceiveMessageAction.class);
+
+ private ConfigTree config;
+
+ public ReceiveMessageAction(ConfigTree config) {
+ this.config = config;
+ }
+
+ public Message process(Message message) throws Exception {
+ String expected = config.getAttribute(MESSAGE_TYPE);
+ if (StringUtils.isNull(expected)) {
+ throw new Exception("The messageType is not defined.");
+ }
+
+ Object value=message.getBody().get();
+ if (value instanceof byte[]) {
+ value = new String((byte[])value);
+ }
+ String receivedMessageType = MessageUtil.getMessageType(value);
+ logger.info("Received [ " + receivedMessageType + "] Message Type");
+
+ if (!expected.equals(receivedMessageType)) {
+ throw new Exception ("Unexpected message type= "+ receivedMessageType + ", but expecting type="+ expected);
+ }
+
+ String roleName = config.getAttribute(CLIENT_ROLE);
+ String store = config.getAttribute(STORAGE_CLASS);
+
+ if (StringUtils.isNotNull(roleName) && StringUtils.isNotNull(store)) {
+ registerEPRwithRoleName(roleName, store, message);
+ }
+
+ return message;
+ }
+
+ private void registerEPRwithRoleName(String roleName, String storageClass, Message message) throws Exception {
+ Class<?> storageClz = ClassLoaderUtil.loadClass(storageClass);
+ if (!EPRStore.class.isAssignableFrom(storageClz)){
+ throw new Exception("The storageClass of " + storageClass + " doesn't implement the EPRStorage Interface.");
+ }
+
+ EPRStore storage = (EPRStore)storageClz.newInstance();
+ storage.registerRole(roleName, message);
+ }
+
+}
Added: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/SendMessageAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/SendMessageAction.java (rev 0)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/SendMessageAction.java 2009-07-17 08:57:47 UTC (rev 671)
@@ -0,0 +1,209 @@
+/*
+ * 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.actions;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.addressing.helpers.EPRHelper;
+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.ClassLoaderUtil;
+import org.jboss.soa.overlord.jbossesb.EPRStore;
+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.
+ *
+ * <p>
+ * This action enables a message, being processed by the action pipeline, to be sent to a nominated destination.
+ * The destination for the message being sent can be identified in two ways:
+ * </p>
+ *
+ * <ul>
+ * <li>
+ * <i>Explicitly</i><br/>
+ * A service category and name can be specified, to indicate the destination of the message to be sent.
+ * When this approach is used, it will be possible to optionally specify a 'reply to' service category and name,
+ * to which any subsequent response can be sent. In this case, the 'reply to' service category and name will be placed on the schedule for the session.
+ * </li>
+ * <li>
+ * <i>Implicitly</i>(Based on JBossESB EPR)<br/>
+ * If a previously received message had a 'reply to EPR', which was then associated with a label,
+ * then the message can be sent back to the originator of that previous message by specifying the label associated with the EPR.
+ * </li>
+ * </ul>
+ *
+ * <h4>Usage:</h4>
+ * <pre>
+ * {@literal
+ <action class="org.jboss.soa.overlord.jbossesb.actions.SendMessageAction"
+ process="process" name="s4-3">
+ <property name="messageType" value="quoteList" />
+ <property name="clientRole" value="buyer" />
+ <property name="eprStore" value="orgization.your.impl.EPRStorageImpl" />
+ </action>
+ * }
+ * </pre>
+ * OR:
+ * <pre>
+ * {@literal
+ <action class="org.jboss.soa.overlord.jbossesb.actions.SendMessageAction"
+ process="process" name="s8-4">
+ <property name="messageType" value="requestForQuote" />
+ <property name="serviceName" value="supplier.serviceName" />
+ <property name="serviceCategory" value="supplier.serviceCategory" />
+ <property name="responseServiceName" value="RequestForQuote.main.1" />
+ <property name="responseServiceCategory" value="ESBBroker.BrokerParticipant" />
+ </action>
+ * }
+ * </pre>
+ *
+ * <h4>Description of configuration properties:</h4>
+ * <ul>
+ * <li><i>messageType </i> - Define the message type that is prepared to sent 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>
+ * <li><i>responseServiceCategory</i> - The service-category of the responded message.</li>
+ * <li><i>eprStore</i> - The class that is responsible for registering, getting EPR from roleName. </li>
+ * </ul>
+ *
+ *
+ * @author <a href="mailto:cyu at redhat.com">Jeff Yu</a>
+ *
+ */
+public class SendMessageAction extends AbstractActionLifecycle{
+
+ public static final String SERVICE_CATEGORY = "serviceCategory";
+
+ public static final String SERVICE_NAME = "serviceName";
+
+ public static final String MESSAGE_TYPE = "messageType";
+
+ public static final String OPERATION = "operation";
+
+ public static final String RESPONSE_SERVICE_CATEGORY = "responseServiceCategory";
+
+ public static final String RESPONSE_SERVICE_NAME = "responseServiceName";
+
+ public static final String CLIENT_ROLE = "clientRole";
+
+ public static final String STORAGE_CLASS = "eprStore";
+
+ private ConfigTree config;
+
+ private Logger logger = Logger.getLogger(SendMessageAction.class);
+
+ public SendMessageAction(ConfigTree config) {
+ this.config = config;
+ }
+
+ public Message process(Message message) throws Exception {
+ String expected = config.getAttribute(MESSAGE_TYPE);
+ if (StringUtils.isNull(expected)) {
+ throw new Exception("The messageType is not defined.");
+ }
+
+ Object value=message.getBody().get();
+ if (value instanceof byte[]) {
+ value = new String((byte[])value);
+ }
+ String receivedMessageType = MessageUtil.getMessageType(value);
+
+ if (!expected.equals(receivedMessageType)) {
+ 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);
+ String storageClass = config.getAttribute(STORAGE_CLASS);
+
+ if (StringUtils.isNotNull(category) && StringUtils.isNotNull(serviceName)
+ && StringUtils.isNotNull(clientRole)) {
+ throw new Exception ("[serviceCategory/serviceName] and [clientRole] can NOT co-exist.");
+ }
+
+ if (StringUtils.isNotNull(category) && StringUtils.isNotNull(serviceName)){
+ ServiceInvoker invoker = new ServiceInvoker(category, serviceName);
+ invoker.deliverAsync(deliverMessage);
+ logger.info("Send Message to [" + category + "/" + serviceName + "]" );
+ } else if (StringUtils.isNotNull(clientRole) && StringUtils.isNotNull(storageClass)) {
+
+ deliverMessageToRole(clientRole, storageClass, deliverMessage, message);
+ logger.info("Send Message to [" + clientRole + "]" );
+ } 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 deliverMessageToRole(String roleName, String storageClass,
+ Message deliverMessage, Message message) throws Exception {
+ Class<?> storageClz = ClassLoaderUtil.loadClass(storageClass);
+ if (!EPRStore.class.isAssignableFrom(storageClz)){
+ throw new Exception("The storageClass of " + storageClass + " doesn't implement the EPRStorage Interface.");
+ }
+
+ EPRStore storage = (EPRStore)storageClz.newInstance();
+ EPR epr = storage.getEPRByRole(roleName, message);
+ logger.debug("The reply EPR is: " + EPRHelper.toXMLString(epr));
+
+ 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);
+ }
+
+}
Added: cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/SwitchAction.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/SwitchAction.java (rev 0)
+++ cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/actions/SwitchAction.java 2009-07-17 08:57:47 UTC (rev 671)
@@ -0,0 +1,140 @@
+/*
+ * 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.actions;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.soa.esb.actions.AbstractActionLifecycle;
+import org.jboss.soa.esb.client.ServiceInvoker;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.overlord.jbossesb.MessageUtil;
+
+/**
+ * SwitchAction provides a means to select the relevant path based on the type of a message being processed by the action.
+ *
+ * <h4>Usage:</h4>
+ * <pre>
+ * {@literal
+ <action class="org.jboss.soa.overlord.jbossesb.actions.SwitchAction"
+ process="process" name="s11-2">
+ <property name="paths">
+ <case service-category="ESBBroker.BrokerParticipant"
+ service-name="CompleteTransaction.main.2" >
+ <message type="CreditCheckOk" />
+ </case>
+ <case service-category="ESBBroker.BrokerParticipant"
+ service-name="CompleteTransaction.main.4" >
+ <message type="CreditCheckInvalid" />
+ </case>
+ </property>
+ </action>
+ * }
+ * </pre>
+ *
+ * <h4>Description of configuration properties:</h4>
+ * <ul>
+ * <li><i>serivce-category</i> - mapped to JBoss ESB service-category.</li>
+ * <li><i>service-name</i> - mapped to JBossESB service-name.<li>
+ * <li><i>type</i> - The message type that should be received.</li>
+ * </ul>
+ *
+ * @author <a href="mailto:cyu at redhat.com">Jeff Yu</a>
+ *
+ */
+public class SwitchAction extends AbstractActionLifecycle{
+
+ public static final String CASE_STATEMENT = "case";
+
+ public static final String SERVICE_NAME = "service-name";
+
+ public static final String SERVICE_CATEGORY = "service-category";
+
+ 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;
+ }
+
+ public Message process(Message message) throws Exception {
+ parseConfiguration();
+
+ Object value=message.getBody().get();
+ if (value instanceof byte[]) {
+ value = new String((byte[])value);
+ }
+ String messageType = MessageUtil.getMessageType(value);
+
+ //TODO: Need to deal with the messageType null scenario.
+
+ for (ConfigTree caseBranch : caseBranchs) {
+ ConfigTree[] msgs = caseBranch.getAllChildren();
+ for (ConfigTree msg : msgs) {
+ if (msg.getName().equals("message")) {
+ String type = msg.getAttribute("type");
+ if (messageType.equals(type)) {
+ String category = caseBranch.getAttribute(SERVICE_CATEGORY);
+ String svcName = caseBranch.getAttribute(SERVICE_NAME);
+ ServiceInvoker invoker = new ServiceInvoker(category, svcName);
+ invoker.deliverAsync(message);
+ return message;
+ }
+ }
+ }
+ }
+
+ return message;
+ }
+
+
+ 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())) {
+ caseBranchs.add(ct);
+ }
+ }
+ }
+
+ public String getServiceDescName() {
+ return serviceDescName;
+ }
+
+ public String getConversationType() {
+ return conversationType;
+ }
+
+}
Added: cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/MVELUsageTest.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/MVELUsageTest.java (rev 0)
+++ cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/MVELUsageTest.java 2009-07-17 08:57:47 UTC (rev 671)
@@ -0,0 +1,142 @@
+/*
+ * 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.util;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mvel.MVEL;
+
+import junit.framework.Assert;
+
+/**
+ *
+ * @author <a href="mailto:cyu at redhat.com">Jeff Yu</a>
+ *
+ */
+public class MVELUsageTest extends Assert {
+
+ private Example example;
+
+ @Before
+ public void setUp() {
+ example = new Example();
+ example.setProperty("exampleProperty");
+ }
+
+ @Test
+ public void testPropertyAssessor() throws Exception {
+ String expression = "property";
+ String value = (String)MVEL.eval(expression, example);
+
+ assertEquals("exampleProperty", value);
+ }
+
+ @Test
+ public void testInvokeMethod() throws Exception {
+ String expression = "isInvoked()";
+ boolean result = (Boolean)MVEL.eval(expression, example);
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void testPropertyInjection() throws Exception {
+ String expression="property";
+ MVEL.setProperty(example, expression, "AnotherValue");
+ assertEquals("AnotherValue", MVEL.eval(expression, example));
+ }
+
+ @Test
+ public void testIntegerInjection() throws Exception {
+ Integer i = new Integer(5);
+ MVEL.setProperty(example, "counter", i);
+ assertEquals(5, example.getCounter());
+ }
+
+ @Test
+ public void testGetProperty() throws Exception {
+ String property = "property";
+ assertEquals("exampleProperty", MVEL.getProperty(property, example));
+ }
+
+
+ @Test
+ public void testSetObject() throws Exception {
+ String property = "quote.value";
+ MVEL.setProperty(example, property, new Integer(5));
+ assertEquals(5, MVEL.getProperty(property, example));
+ }
+
+ public class Example {
+
+ private String property;
+
+ private int counter;
+
+ private Quote quote = new Quote();
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+ public boolean isInvoked() {
+ return true;
+ }
+
+ public int getCounter() {
+ return counter;
+ }
+
+ public void setCounter(int counter) {
+ this.counter = counter;
+ }
+
+ public Quote getQuote() {
+ return quote;
+ }
+
+ public void setQuote(Quote quote) {
+ this.quote = quote;
+ }
+
+ }
+
+ public class Quote {
+ private String name;
+ private int value;
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public int getValue() {
+ return value;
+ }
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+ }
+
+}
Added: cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/XMLUtilsTest.java
===================================================================
--- cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/XMLUtilsTest.java (rev 0)
+++ cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/util/XMLUtilsTest.java 2009-07-17 08:57:47 UTC (rev 671)
@@ -0,0 +1,67 @@
+/*
+ * 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.util;
+
+import org.w3c.dom.Element;
+import org.jboss.soa.overlord.jbossesb.XMLUtils;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+/**
+ *
+ * @author <a href="mailto:cyu at redhat.com">Jeff Yu</a>
+ *
+ */
+public class XMLUtilsTest extends Assert{
+
+ @Test
+ public void testExecuteXpath() throws Exception {
+ String val="<order><orderId id=\""+3+"\" /></order>";
+ String expr="/order/orderId/@id";
+
+ String value = XMLUtils.executeXpath(val, expr);
+ assertEquals("3",value);
+
+ Element element = (Element) XMLUtils.getNode(val);
+ assertEquals("3", XMLUtils.executeXpath(element, expr));
+ }
+
+ @Test
+ public void testXpathAttribute() throws Exception {
+ String val = "<requestForQuote id=\"20\" supplierDesc=\"{http://www.jboss.org/overlord/loanBroker}Supplier1\" ></requestForQuote>";
+ String expr = "//@id";
+
+ Element element = (Element) XMLUtils.getNode(val);
+ assertEquals("20", XMLUtils.executeXpath(element, expr));
+ assertEquals("{http://www.jboss.org/overlord/loanBroker}Supplier1", XMLUtils.executeXpath(element, "//@supplierDesc"));
+
+ }
+
+ @Test
+ public void testXpathNode() throws Exception {
+ String val = "<quote id=\"20\" supplierDesc = \"{http://www.jboss.org/overlord/loanBroker}Supplier1\">10</quote>";
+ String expr = "/quote";
+
+ Element element = (Element) XMLUtils.getNode(val);
+ assertEquals("10", XMLUtils.executeXpath(element, expr));
+ }
+
+}
More information about the overlord-commits
mailing list