Author: jeff.yuchang
Date: 2009-02-28 05:53:16 -0500 (Sat, 28 Feb 2009)
New Revision: 524
Added:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/ClassLoaderUtil.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/MessageUtil.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/NameSpaceUtil.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/XMLUtils.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/
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/
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
Removed:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/ClassLoaderUtil.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/MessageUtil.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/NameSpaceUtil.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/XMLUtils.java
Modified:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/SessionManager.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/ConversationAction.java
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/SetStateAction.java
cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/stateful/util/XMLUtilsTest.java
Log:
[SOAG-91] Add stateless actions.
Added:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/ClassLoaderUtil.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/ClassLoaderUtil.java
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/ClassLoaderUtil.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ *
+ * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
+ *
+ */
+public class ClassLoaderUtil {
+
+ public static Class<?> loadClass(String className) throws ClassNotFoundException
{
+ return Thread.currentThread().getContextClassLoader().loadClass(className);
+ }
+
+}
Added:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/MessageUtil.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/MessageUtil.java
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/MessageUtil.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2005-6 Pi4 Technologies Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * Change History:
+ * Mar 21, 2006 : Initial version created by gary
+ */
+package org.jboss.soa.overlord.jbossesb;
+
+import java.util.logging.Logger;
+
+import org.w3c.dom.Node;
+
+
+/**
+ * This class represents utility functions for processing
+ * messages.
+ *
+ * @author <a href="mailto:gary.brown@hattricksoftware.com">Gary
Brown</a>
+ * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
+ */
+public class MessageUtil {
+
+ private static Logger logger = Logger.getLogger(MessageUtil.class.getName());
+
+ /**
+ * This method returns the message type associated with the
+ * supplied value.
+ *
+ * @param value The value
+ * @return The message type
+ */
+ public static String getMessageType(Object value) {
+ String ret=null;
+
+ if (value instanceof org.w3c.dom.Node) {
+ String namespace=((org.w3c.dom.Node)value).getNamespaceURI();
+ String localpart=((org.w3c.dom.Node)value).getLocalName();
+
+ if (value instanceof org.w3c.dom.Element &&
+ ((org.w3c.dom.Element)value).hasAttributeNS(
+ "http://www.w3.org/2001/XMLSchema-instance", "type")) {
+ String type=((org.w3c.dom.Element)value).getAttributeNS(
+ "http://www.w3.org/2001/XMLSchema-instance", "type");
+
+ String prefix= XMLUtils.getPrefix(type);
+
+ localpart = XMLUtils.getLocalname(type);
+
+ if (prefix == null) {
+ namespace = null;
+ } else {
+ namespace = ((org.w3c.dom.Element)value).
+ getAttribute("xmlns:"+prefix);
+ if (!NameSpaceUtil.isNotNull(namespace)) {
+ namespace = null;
+ }
+ }
+ }
+
+ if (namespace == null) {
+ ret = localpart;
+ } else {
+ ret = NameSpaceUtil.getFullyQualifiedName(namespace,
+ localpart);
+ }
+ } else if (value instanceof String) {
+ ret = String.class.getName();
+
+ try {
+ Node node=XMLUtils.getNode((String)value);
+ ret = getMessageType(node);
+ } catch(Exception e) {
+ logger.warning("Failed to obtain message type from value: "+value);
+ }
+
+ } else {
+ ret = value.getClass().getName();
+ }
+
+ return(ret);
+ }
+
+}
Added:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/NameSpaceUtil.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/NameSpaceUtil.java
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/NameSpaceUtil.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2005 Pi4 Technologies Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * Change History:
+ * Jul 28, 2005 : Initial version created by gary
+ */
+package org.jboss.soa.overlord.jbossesb;
+
+/**
+ * This class provides helper functiions for manipulating fully
+ * qualified names (with local parts and namespaces).
+ *
+ * @author <a href="mailto:gary.brown@hattricksoftware.com">Gary
Brown</a>
+ * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
+ */
+public class NameSpaceUtil {
+
+ public static final String NAMESPACE_PREFIX="{";
+ public static final String NAMESPACE_SUFFIX="}";
+
+ /**
+ * This method checks whether the supplied name is a
+ * fully qualified name, with the name space contained
+ * in braces, followed by a localpart.
+ *
+ * @param name The name
+ * @return Whether the name is a fully qualified name
+ */
+ public static boolean isFullyQualifiedName(String name) {
+ boolean ret=false;
+ int pos=0;
+
+ if (name != null && name.startsWith("{") &&
+ (pos=name.indexOf('}')) != -1 &&
+ name.length() != pos+1) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the fully qualified name associated
+ * with the supplied namespace and local part. If the namespace
+ * is null, or an empty string, then only the local part
+ * will be returned.
+ *
+ * @param namespace The namespace
+ * @param localpart The local part
+ * @return The fully qualified name
+ */
+ public static String getFullyQualifiedName(String namespace,
+ String localpart) {
+ String ret=null;
+
+ if (namespace != null && namespace.trim().length() > 0) {
+ ret = NAMESPACE_PREFIX+namespace+NAMESPACE_SUFFIX;
+ }
+
+ if (localpart != null) {
+ if (ret == null) {
+ ret = localpart;
+ } else {
+ ret += localpart;
+ }
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the namespace component of a fully
+ * qualified name. If the supplied name does not have the
+ * namespace prefix, then a null will be returned. If the
+ * supplied name does not have the suffix, then the contents
+ * following the prefix, to the end of the name, will be
+ * returned.
+ *
+ * @param qname The fully qualified name
+ * @return The namespace
+ */
+ public static String getNamespace(String qname) {
+ String ret=null;
+ int index=0;
+
+ if (qname != null &&
+ (index=qname.indexOf(NAMESPACE_PREFIX)) != -1) {
+ int endindex=qname.indexOf(NAMESPACE_SUFFIX);
+
+ if (endindex == -1) {
+ endindex = qname.length();
+ }
+
+ ret = qname.substring(index+1, endindex);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method extracts the local part from the supplied
+ * fully qualified name. If the namespace suffix cannot
+ * be found, then the fully supplied name will be
+ * returned.
+ *
+ * @param qname The fully qualified name
+ * @return The local part
+ */
+ public static String getLocalPart(String qname) {
+ String ret=null;
+ int index=0;
+
+ if (qname != null &&
+ (index=qname.indexOf(NAMESPACE_SUFFIX)) != -1) {
+ ret = qname.substring(index+1);
+ } else {
+ ret = qname;
+ }
+
+ return(ret);
+ }
+
+ public static boolean isNotNull(String value) {
+ return(value != null && value.trim().length() > 0);
+ }
+
+}
Added:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/XMLUtils.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/XMLUtils.java
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/XMLUtils.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,130 @@
+/*
+ * 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 java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @author <a href="mailto:gary.brown@hattricksoftware.com">Gary
Brown</a>
+ * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
+ */
+
+public class XMLUtils {
+
+ /**
+ * This method converts the supplied text representation
+ * of an XML document into a DOM Node.
+ *
+ * @param text The text
+ * @return The node
+ * @throws XMLException Failed to convert the text
+ */
+ public static Node getNode(String text) throws Exception {
+ Node ret=null;
+
+ try {
+ // Transform the text representation to DOM
+ DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+ fact.setNamespaceAware(true);
+
+ InputStream xmlstr= new ByteArrayInputStream(text.getBytes());
+
+ DocumentBuilder builder=fact.newDocumentBuilder();
+ org.w3c.dom.Document doc=builder.parse(xmlstr);
+
+ ret = doc.getDocumentElement();
+
+ } catch(Exception e) {
+ throw new Exception("Failed to transform text " +
+ "into DOM representation", e);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the prefix part of the supplied
+ * qualified name.
+ *
+ * @param qname The qualified name
+ * @return The prefix
+ */
+ public static String getPrefix(String qname) {
+ String ret=null;
+ int pos=0;
+
+ if (qname != null && ((pos=qname.indexOf(':')) != -1)) {
+ ret = qname.substring(0, pos);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the localname part of the supplied
+ * qualified name.
+ *
+ * @param qname The qualified name
+ * @return The localname part
+ */
+ public static String getLocalname(String qname) {
+ String ret=qname;
+ int pos=0;
+
+ if (qname != null && ((pos=qname.indexOf(':')) != -1)) {
+ ret = qname.substring(pos+1);
+ }
+
+ return(ret);
+ }
+
+ /**
+ *
+ * @param object
+ * @param expression: xpath expression
+ * @return
+ * @throws Exception
+ */
+ public static String executeXpath(Object object, String expression) throws Exception {
+ XPathFactory factory = XPathFactory.newInstance();
+ XPath theXpath = factory.newXPath();
+
+ if (object instanceof String) {
+ String xmlMessage = (String)object;
+ Node node = getNode(xmlMessage);
+ return theXpath.evaluate(expression, node);
+ } else if (object instanceof Element) {
+ return theXpath.evaluate(expression, object);
+ }
+
+ return null;
+ }
+
+}
\ No newline at end of file
Modified:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/SessionManager.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/SessionManager.java 2009-02-26
08:08:52 UTC (rev 523)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/SessionManager.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -26,9 +26,9 @@
import org.apache.log4j.Logger;
import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.overlord.jbossesb.ClassLoaderUtil;
import org.jboss.soa.overlord.jbossesb.stateful.actions.MessageProperties;
import org.jboss.soa.overlord.jbossesb.stateful.actions.Service;
-import org.jboss.soa.overlord.jbossesb.stateful.util.ClassLoaderUtil;
import org.jboss.soa.overlord.jbossesb.stateful.util.HibernateUtil;
import org.mvel.MVEL;
Modified:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/ConversationAction.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/ConversationAction.java 2009-02-26
08:08:52 UTC (rev 523)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/ConversationAction.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -31,16 +31,16 @@
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.MessageUtil;
+import org.jboss.soa.overlord.jbossesb.XMLUtils;
import org.jboss.soa.overlord.jbossesb.stateful.Identity;
import org.jboss.soa.overlord.jbossesb.stateful.IdentityType;
import org.jboss.soa.overlord.jbossesb.stateful.ScheduleItem;
import org.jboss.soa.overlord.jbossesb.stateful.Session;
import org.jboss.soa.overlord.jbossesb.stateful.SessionManager;
import org.jboss.soa.overlord.jbossesb.stateful.SessionStatus;
-import org.jboss.soa.overlord.jbossesb.stateful.util.ClassLoaderUtil;
import org.jboss.soa.overlord.jbossesb.stateful.util.HibernateUtil;
-import org.jboss.soa.overlord.jbossesb.stateful.util.MessageUtil;
-import org.jboss.soa.overlord.jbossesb.stateful.util.XMLUtils;
import org.mvel.MVEL;
/**
Modified:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/SetStateAction.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/SetStateAction.java 2009-02-26
08:08:52 UTC (rev 523)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/actions/SetStateAction.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -22,7 +22,7 @@
import org.apache.log4j.Logger;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.overlord.jbossesb.stateful.util.XMLUtils;
+import org.jboss.soa.overlord.jbossesb.XMLUtils;
import org.mvel.MVEL;
import org.w3c.dom.Element;
Deleted:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/ClassLoaderUtil.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/ClassLoaderUtil.java 2009-02-26
08:08:52 UTC (rev 523)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/ClassLoaderUtil.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -1,33 +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.util;
-
-/**
- *
- * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
- *
- */
-public class ClassLoaderUtil {
-
- public static Class<?> loadClass(String className) throws ClassNotFoundException
{
- return Thread.currentThread().getContextClassLoader().loadClass(className);
- }
-
-}
Deleted:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/MessageUtil.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/MessageUtil.java 2009-02-26
08:08:52 UTC (rev 523)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/MessageUtil.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -1,96 +0,0 @@
-/*
- * Copyright 2005-6 Pi4 Technologies Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *
- * Change History:
- * Mar 21, 2006 : Initial version created by gary
- */
-package org.jboss.soa.overlord.jbossesb.stateful.util;
-
-import java.util.logging.Logger;
-
-import org.w3c.dom.Node;
-
-
-/**
- * This class represents utility functions for processing
- * messages.
- *
- * @author <a href="mailto:gary.brown@hattricksoftware.com">Gary
Brown</a>
- * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
- */
-public class MessageUtil {
-
- private static Logger logger = Logger.getLogger(MessageUtil.class.getName());
-
- /**
- * This method returns the message type associated with the
- * supplied value.
- *
- * @param value The value
- * @return The message type
- */
- public static String getMessageType(Object value) {
- String ret=null;
-
- if (value instanceof org.w3c.dom.Node) {
- String namespace=((org.w3c.dom.Node)value).getNamespaceURI();
- String localpart=((org.w3c.dom.Node)value).getLocalName();
-
- if (value instanceof org.w3c.dom.Element &&
- ((org.w3c.dom.Element)value).hasAttributeNS(
- "http://www.w3.org/2001/XMLSchema-instance", "type")) {
- String type=((org.w3c.dom.Element)value).getAttributeNS(
- "http://www.w3.org/2001/XMLSchema-instance", "type");
-
- String prefix= XMLUtils.getPrefix(type);
-
- localpart = XMLUtils.getLocalname(type);
-
- if (prefix == null) {
- namespace = null;
- } else {
- namespace = ((org.w3c.dom.Element)value).
- getAttribute("xmlns:"+prefix);
- if (!NameSpaceUtil.isNotNull(namespace)) {
- namespace = null;
- }
- }
- }
-
- if (namespace == null) {
- ret = localpart;
- } else {
- ret = NameSpaceUtil.getFullyQualifiedName(namespace,
- localpart);
- }
- } else if (value instanceof String) {
- ret = String.class.getName();
-
- try {
- Node node=XMLUtils.getNode((String)value);
- ret = getMessageType(node);
- } catch(Exception e) {
- logger.warning("Failed to obtain message type from value: "+value);
- }
-
- } else {
- ret = value.getClass().getName();
- }
-
- return(ret);
- }
-
-}
Deleted:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/NameSpaceUtil.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/NameSpaceUtil.java 2009-02-26
08:08:52 UTC (rev 523)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/NameSpaceUtil.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -1,140 +0,0 @@
-/*
- * Copyright 2005 Pi4 Technologies Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *
- * Change History:
- * Jul 28, 2005 : Initial version created by gary
- */
-package org.jboss.soa.overlord.jbossesb.stateful.util;
-
-/**
- * This class provides helper functiions for manipulating fully
- * qualified names (with local parts and namespaces).
- *
- * @author <a href="mailto:gary.brown@hattricksoftware.com">Gary
Brown</a>
- * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
- */
-public class NameSpaceUtil {
-
- public static final String NAMESPACE_PREFIX="{";
- public static final String NAMESPACE_SUFFIX="}";
-
- /**
- * This method checks whether the supplied name is a
- * fully qualified name, with the name space contained
- * in braces, followed by a localpart.
- *
- * @param name The name
- * @return Whether the name is a fully qualified name
- */
- public static boolean isFullyQualifiedName(String name) {
- boolean ret=false;
- int pos=0;
-
- if (name != null && name.startsWith("{") &&
- (pos=name.indexOf('}')) != -1 &&
- name.length() != pos+1) {
- ret = true;
- }
-
- return(ret);
- }
-
- /**
- * This method returns the fully qualified name associated
- * with the supplied namespace and local part. If the namespace
- * is null, or an empty string, then only the local part
- * will be returned.
- *
- * @param namespace The namespace
- * @param localpart The local part
- * @return The fully qualified name
- */
- public static String getFullyQualifiedName(String namespace,
- String localpart) {
- String ret=null;
-
- if (namespace != null && namespace.trim().length() > 0) {
- ret = NAMESPACE_PREFIX+namespace+NAMESPACE_SUFFIX;
- }
-
- if (localpart != null) {
- if (ret == null) {
- ret = localpart;
- } else {
- ret += localpart;
- }
- }
-
- return(ret);
- }
-
- /**
- * This method returns the namespace component of a fully
- * qualified name. If the supplied name does not have the
- * namespace prefix, then a null will be returned. If the
- * supplied name does not have the suffix, then the contents
- * following the prefix, to the end of the name, will be
- * returned.
- *
- * @param qname The fully qualified name
- * @return The namespace
- */
- public static String getNamespace(String qname) {
- String ret=null;
- int index=0;
-
- if (qname != null &&
- (index=qname.indexOf(NAMESPACE_PREFIX)) != -1) {
- int endindex=qname.indexOf(NAMESPACE_SUFFIX);
-
- if (endindex == -1) {
- endindex = qname.length();
- }
-
- ret = qname.substring(index+1, endindex);
- }
-
- return(ret);
- }
-
- /**
- * This method extracts the local part from the supplied
- * fully qualified name. If the namespace suffix cannot
- * be found, then the fully supplied name will be
- * returned.
- *
- * @param qname The fully qualified name
- * @return The local part
- */
- public static String getLocalPart(String qname) {
- String ret=null;
- int index=0;
-
- if (qname != null &&
- (index=qname.indexOf(NAMESPACE_SUFFIX)) != -1) {
- ret = qname.substring(index+1);
- } else {
- ret = qname;
- }
-
- return(ret);
- }
-
- public static boolean isNotNull(String value) {
- return(value != null && value.trim().length() > 0);
- }
-
-}
Deleted:
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/XMLUtils.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/XMLUtils.java 2009-02-26
08:08:52 UTC (rev 523)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateful/util/XMLUtils.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -1,130 +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.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathFactory;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- *
- * @author <a href="mailto:gary.brown@hattricksoftware.com">Gary
Brown</a>
- * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
- */
-
-public class XMLUtils {
-
- /**
- * This method converts the supplied text representation
- * of an XML document into a DOM Node.
- *
- * @param text The text
- * @return The node
- * @throws XMLException Failed to convert the text
- */
- public static Node getNode(String text) throws Exception {
- Node ret=null;
-
- try {
- // Transform the text representation to DOM
- DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
- fact.setNamespaceAware(true);
-
- InputStream xmlstr= new ByteArrayInputStream(text.getBytes());
-
- DocumentBuilder builder=fact.newDocumentBuilder();
- org.w3c.dom.Document doc=builder.parse(xmlstr);
-
- ret = doc.getDocumentElement();
-
- } catch(Exception e) {
- throw new Exception("Failed to transform text " +
- "into DOM representation", e);
- }
-
- return(ret);
- }
-
- /**
- * This method returns the prefix part of the supplied
- * qualified name.
- *
- * @param qname The qualified name
- * @return The prefix
- */
- public static String getPrefix(String qname) {
- String ret=null;
- int pos=0;
-
- if (qname != null && ((pos=qname.indexOf(':')) != -1)) {
- ret = qname.substring(0, pos);
- }
-
- return(ret);
- }
-
- /**
- * This method returns the localname part of the supplied
- * qualified name.
- *
- * @param qname The qualified name
- * @return The localname part
- */
- public static String getLocalname(String qname) {
- String ret=qname;
- int pos=0;
-
- if (qname != null && ((pos=qname.indexOf(':')) != -1)) {
- ret = qname.substring(pos+1);
- }
-
- return(ret);
- }
-
- /**
- *
- * @param object
- * @param expression: xpath expression
- * @return
- * @throws Exception
- */
- public static String executeXpath(Object object, String expression) throws Exception {
- XPathFactory factory = XPathFactory.newInstance();
- XPath theXpath = factory.newXPath();
-
- if (object instanceof String) {
- String xmlMessage = (String)object;
- Node node = getNode(xmlMessage);
- return theXpath.evaluate(expression, node);
- } else if (object instanceof Element) {
- return theXpath.evaluate(expression, object);
- }
-
- return null;
- }
-
-}
\ No newline at end of file
Added:
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
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/Decision.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,32 @@
+/*
+ * 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.stateless;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * @author <a href="mailto:cyu@redhat.com">Jeff Yu</a>
+ *
+ */
+public interface Decision {
+
+ boolean executeDecision(Message message);
+
+}
Added:
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
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/IfAction.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,148 @@
+/*
+ * 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.stateless.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.stateless.Decision;
+
+
+/**
+ * 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.stateless.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@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 (decisionClzString == null || "".equals(decisionClzString.trim())){
+ 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/stateless/actions/ReceiveMessageAction.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/ReceiveMessageAction.java
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/ReceiveMessageAction.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,82 @@
+/*
+ * 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.stateless.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.MessageUtil;
+
+/**
+ * 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.stateless.actions.ReceiveMessageAction"
name="c2" process="process">
+ <property name="messageType" value="CreditCheckRequest"/>
+ </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@redhat.com">Jeff Yu</a>
+ *
+ */
+public class ReceiveMessageAction extends AbstractActionLifecycle{
+
+ public static final String OPERATION = "operation";
+
+ public static final String MESSAGE_TYPE = "messageType";
+
+ 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 (expected == null || "".equals(expected.trim())) {
+ 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);
+ }
+
+ return message;
+ }
+
+}
Added:
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
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SendMessageAction.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,137 @@
+/*
+ * 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.stateless.actions;
+
+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;
+
+/**
+ * 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.stateless.actions.SendMessageAction"
+ process="process" name="s4-3">
+ <property name="messageType" value="quoteList" />
+ <property name="clientEPR" value="buyer" />
+ </action>
+ * }
+ * </pre>
+ * OR:
+ * <pre>
+ * {@literal
+ <action
class="org.jboss.soa.overlord.jbossesb.stateless.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>clientEPR</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>
+ * </ul>
+ *
+ *
+ * @author <a href="mailto:cyu@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";
+
+ private ConfigTree config;
+
+ public SendMessageAction(ConfigTree config) {
+ this.config = config;
+ }
+
+ public Message process(Message message) throws Exception {
+ String expected = config.getAttribute(MESSAGE_TYPE);
+ if (expected == null || "".equals(expected.trim())) {
+ 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);
+ }
+
+ String category = config.getAttribute(SERVICE_CATEGORY);
+ String serviceName = config.getAttribute(SERVICE_NAME);
+
+ ServiceInvoker invoker = new ServiceInvoker(category, serviceName);
+ invoker.deliverAsync(message);
+
+ //TODO: add logic for dealing with responseServiceCategory and responseServiceName
+
+ return message;
+ }
+
+}
Added:
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
(rev 0)
+++
cdl/trunk/runtime/jbossesb/src/main/java/org/jboss/soa/overlord/jbossesb/stateless/actions/SwitchAction.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -0,0 +1,121 @@
+/*
+ * 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.stateless.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.stateless.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@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";
+
+ private ConfigTree config;
+
+ private List<ConfigTree> caseBranchs = new LinkedList<ConfigTree>();
+
+ 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() {
+ ConfigTree[] children = config.getAllChildren();
+ for (ConfigTree ct : children) {
+ if (CASE_STATEMENT.equals(ct.getName())) {
+ caseBranchs.add(ct);
+ }
+ }
+ }
+
+}
Modified:
cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/stateful/util/XMLUtilsTest.java
===================================================================
---
cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/stateful/util/XMLUtilsTest.java 2009-02-26
08:08:52 UTC (rev 523)
+++
cdl/trunk/runtime/jbossesb/src/test/java/org/jboss/soa/overlord/jbossesb/stateful/util/XMLUtilsTest.java 2009-02-28
10:53:16 UTC (rev 524)
@@ -20,7 +20,7 @@
package org.jboss.soa.overlord.jbossesb.stateful.util;
import org.w3c.dom.Element;
-import org.jboss.soa.overlord.jbossesb.stateful.util.XMLUtils;
+import org.jboss.soa.overlord.jbossesb.XMLUtils;
import org.junit.Test;
import junit.framework.Assert;