[jboss-svn-commits] JBL Code SVN: r7573 - in labs/jbossesb/workspace/b_georges: nbproject product product/core/listeners/src/org/jboss/soa/esb/actions product/core/listeners/src/org/jboss/soa/esb/actions/converters product/core/listeners/src/org/jboss/soa/esb/actions/routing product/core/listeners/src/org/jboss/soa/esb/listeners product/core/listeners/src/org/jboss/soa/esb/listeners/gateway product/core/listeners/src/org/jboss/soa/esb/listeners/message product/core/listeners/src/org/jboss/soa/esb/listeners/old product/core/listeners/tests/src product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old product/core/rosetta product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml product/core/rosetta/src/org/jboss/soa/esb/addressing/util product/core/rosetta/src/org/jboss/soa/esb/common product/core/rosetta/src/org/jboss/soa/esb/helpers product/core/rosetta/src/org/jboss/soa/esb/services/persistence! product/core/rosetta/src/org/jboss/soa/esb/util product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests product/core/services product/core/services/src/org/jboss/soa/esb/services/persistence product/core/services/src/org/jboss/soa/esb/services/registry product/core/services/tests product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests product/core/services/tests/src/org/jboss/soa/esb/services/registry
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Nov 13 16:43:29 EST 2006
Author: b_georges
Date: 2006-11-13 16:42:31 -0500 (Mon, 13 Nov 2006)
New Revision: 7573
Added:
labs/jbossesb/workspace/b_georges/product/build/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/EchoRouter.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/HttpRouter.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerInitializationException.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/AbstractListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/AbstractPassiveListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/HttpListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractPassiveListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/HttpListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/smooks-test.cdrl
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Factory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRHelperUnitTest.java
Modified:
labs/jbossesb/workspace/b_georges/nbproject/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionUtils.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/DirectoryPoller.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/RemoteDirectoryPoller.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListenerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/DirectoryPollerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListenerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/smooks-cdr.lst
labs/jbossesb/workspace/b_georges/product/core/rosetta/build.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreFactory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/build.xml
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreType.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryFactory.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/build.xml
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
Log:
Updating workspace with trunk
Property changes on: labs/jbossesb/workspace/b_georges/nbproject
___________________________________________________________________
Name: svn:ignore
+ private
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionUtils.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionUtils.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionUtils.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -36,7 +36,6 @@
{
public static final String BEFORE_ACTION="org.jboss.soa.esb.actions.current.before";
private static final String CURRENT_OBJECT="org.jboss.soa.esb.actions.current.after";
- private static final String CONFIG_TREE ="org.jboss.soa.esb.helpers.ConfigTree";
/**
* Obtain the current object from standard spot within message
@@ -64,7 +63,9 @@
{
Body body = message.getBody();
body.remove(BEFORE_ACTION);
- body.add(BEFORE_ACTION,body.get(CURRENT_OBJECT));
+ Object obj = body.get(CURRENT_OBJECT);
+ if (null != obj)
+ body.add(BEFORE_ACTION,obj);
}
/**
* Put current object in standard spot within message
@@ -81,33 +82,6 @@
return oRet;
}
- /**
- * Put a Config tree in predefined spot for it in 'this'
- * <br/>NULL values are not stored
- * @param message - to operate on
- * @param tree - ConfigTree to store - Won't be stored if <null>
- * @return ConfigTree previously stored
- */
- public static ConfigTree setConfigTree(Message message, ConfigTree tree)
- {
- ConfigTree oRet = (ConfigTree)message.getBody().remove(CONFIG_TREE);
- if (null!=tree)
- message.getBody().add(CONFIG_TREE,tree);
- return oRet;
- }
- /**
- * Put a Config tree in predefined spot for it in 'this'
- * <br/>NULL values are not stored
- * @param message - to operate on
- * @param tree - ConfigTree to store - Won't be stored if <null>
- * @return ConfigTree previously stored
- */
- public static ConfigTree getConfigTree(Message message)
- {
- ConfigTree oRet = (ConfigTree)message.getBody().get(CONFIG_TREE);
- return (null==oRet)?new ConfigTree("mock"):oRet;
- }
-
public static NotificationList getNotifyList(ConfigTree tree, String type)
{
ConfigTree[] array = tree.getChildren("NotificationList");
@@ -121,5 +95,4 @@
}
return null;
}
-
}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,258 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions;
+
+import java.io.Serializable;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
+import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.notification.NotificationList;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
+import org.jboss.soa.esb.services.routing.MessageRouter;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+
+
+/**
+ * Action proxy to call the Content Based Router.
+ *
+ * @author kstam at redhat.com
+ *
+ */
+public class CbrProxyAction implements ActionProcessor
+{
+ private static Logger _logger = Logger.getLogger(CbrProxyAction.class);
+ /** Collection of EPRS for the Content Based Router */
+ protected Collection<EPR> _eprs;
+ /** Configuration Tree */
+ protected ConfigTree _config;
+ /** Default 1 minute Listener Timeout in millis */
+ final private static long DEFAULT_REPLY_LISTENER_TIMEOUT = 60000;
+ /** replyListenerTimout */
+ private long _replyListenerTimeout = DEFAULT_REPLY_LISTENER_TIMEOUT;
+
+ /**
+ * Constructor of the Content Based Router Proxy. This constructor obtains
+ * the EPRs of the Content Based Router.
+ *
+ * @param config
+ * @throws Exception
+ */
+ public CbrProxyAction(ConfigTree config) throws RegistryException
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ String serviceCategoryName = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+ String serviceName = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ _eprs = registry.findEPRs(serviceCategoryName, serviceName);
+ _config = config;
+ if (config.getAttribute(ListenerTagNames.REPLY_LISTENER_TIMEOUT_TAG)!=null) {
+ try {
+ _replyListenerTimeout = Long.parseLong(config.getAttribute(ListenerTagNames.REPLY_LISTENER_TIMEOUT_TAG));
+ } catch (NumberFormatException nfe) {
+ _logger.error("Could not parse " + config.getAttribute(ListenerTagNames.REPLY_LISTENER_TIMEOUT_TAG) + " to long.", nfe);
+ }
+ }
+ }
+ /**
+ * No-Op method. This is here for notification purposes.
+ *
+ * @param message
+ * @return the same message as passed in.
+ */
+ public Message noOperation(Message message) { return message; }
+
+ /** By default this process method forwards this request to routeAndDeliver.
+ * @see routeAndDeliver(Message message).
+ *
+ * @param message - the message to be routed.
+ * @return - the same message as was passed in.
+ */
+ public Message process(Message message)
+ {
+ _logger.info("Process was called, using the default routeAndDeliver.");
+ return routeAndDeliver(message);
+ }
+ /**
+ * Just route. The routing returns the message with a Collection of destinationService names.
+ *
+ * @param message
+ * @return message, a collection of service destinations is added to the message.
+ */
+ public Message route(Message message) throws MessageRouterException
+ {
+ message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
+ Message replyMessage=null;
+ try {
+
+ for (Iterator<EPR> eprIterator=_eprs.iterator();eprIterator.hasNext();){
+ try {
+ //Just use the first EPR in the list.
+ EPR epr = eprIterator.next();
+ Courier courier = CourierFactory.getCourier(epr);
+ EPR replyEpr = getReplyToEpr(epr);
+ if (message.getHeader().getCall()==null) {
+ Call call = new Call();
+ message.getHeader().setCall(call);
+ }
+ message.getHeader().getCall().setReplyTo(replyEpr);
+ //If not successful try the next EPR
+ if (courier.deliver(message))
+ {
+ courier.setReplyToEpr(replyEpr);
+ try {
+ //wait for the reply.
+ replyMessage = courier.pickup(_replyListenerTimeout);
+ } catch (CourierTimeoutException e) {
+ throw new MessageRouterException(e.getLocalizedMessage(),e);
+ }
+ //if we get here we were successful so we can break from the loop and reply.
+ break;
+ } else {
+ _logger.warn("Could not deliver the message, maybe there is another JMS-EPR we can use.");
+ }
+ } catch (URISyntaxException e) {
+ _logger.error(e.getLocalizedMessage(), e);
+ //Let's be optimistic and try to see if there is another epr.
+ continue;
+ }
+ }
+ } catch (CourierException ce) {
+ _logger.error("Could not send to the CBR. " + ce.getLocalizedMessage(), ce);
+ }
+ return replyMessage;
+ }
+ /**
+ * Builds a temporary EPR to which we can reply to.
+ *
+ * @param epr - the toEPR
+ * @return
+ * @throws URISyntaxException
+ */
+ private EPR getReplyToEpr(EPR toEpr) throws URISyntaxException, CourierException
+ {
+// At a later date we may support replying to a service defined in the configuration. For
+// now we leave this out. However this is a rough example of what that code would look like.
+//
+// ConfigTree replyArgs = _config.getFirstChild("replyToService");
+// if (null!=replyArgs)
+// {
+// String category = replyArgs.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+// String name = replyArgs.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+// Collection<EPR> coll = null;
+// try
+// {
+// coll = RegistryFactory.getRegistry().findEPRs(category, name);
+// if (coll.size()>0)
+// return coll.iterator().next();
+// }
+// catch (RegistryException e) { }
+// }
+//
+ EPR replyToEpr = CourierUtil.getTemporaryReplyToEpr(toEpr);
+ return replyToEpr;
+ }
+
+ /**
+ * Do *not* route, just deliver. Pulls the destinationServices from the message and deliver the message to the destination(s).
+ * @param message
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public Message deliver(Message message)
+ {
+ Collection<String> destinationServices = (Collection) message.getProperties().getProperty(MessageRouter.ROUTING_DESTINATION_SERVICE_LIST);
+ if (destinationServices!=null) {
+ //TODO Remove the property from the message?
+ MessageRouter.deliverMessages(destinationServices, message);
+ } else {
+ _logger.error("No destination services were found, the message was not delivered");
+ }
+ return message;
+ }
+ /**
+ * Route and Deliver to the destination Services.
+ *
+ * @param message - to be routed and delivered
+ * @return message - same message is returned
+ */
+ public Message routeAndDeliver(Message message)
+ {
+ try {
+ for (Iterator<EPR> eprIterator=_eprs.iterator();eprIterator.hasNext();){
+ //Just use the first EPR in the list.
+ EPR epr = eprIterator.next();
+ Courier courier = CourierFactory.getCourier(epr);
+ //If not successful try the next EPR
+ if (courier.deliver(message)) {
+ break; //we were successful so we are done
+ }
+ }
+ } catch (CourierException ce) {
+ _logger.error("Could not send to the CBR. " + ce.getLocalizedMessage(), ce);
+ }
+ return message;
+ }
+
+ public void exceptionCallback(Message message, Throwable t)
+ {
+ String sMsg = new StringBuilder(" ExceptionTrower.exceptionCallback CALLED ")
+ .append(message)
+ .toString();
+ _logger.fatal(sMsg,t);
+ @SuppressWarnings("unused")
+ NotificationList nl = ActionUtils.getNotifyList(_config,"err");
+ // Here you can send notifications to everybody
+ }
+
+ public void okMethod(Message message)
+ {
+ Collection destinationServices
+ = (Collection) message.getProperties().getProperty(MessageRouter.ROUTING_DESTINATION_SERVICE_LIST);
+ //Do something with the callBack info
+ _logger.log(Priority.INFO, destinationServices);
+
+ }
+
+ public Serializable getErrorNotification(Message message) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public Serializable getOkNotification(Message message) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -27,7 +27,8 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.apache.log4j.Logger;
@@ -35,11 +36,16 @@
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.actions.ActionProcessor;
import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Header;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.transform.TransformationException;
import org.jboss.soa.esb.services.transform.TransformationService;
import org.milyn.SmooksStandalone;
+import org.milyn.device.ident.UnknownDeviceException;
/**
* Smooks Transformer.
@@ -47,18 +53,6 @@
* This processor hooks the <a href="http://milyn.codehaus.org/Smooks">Milyn Smooks</a>
* XML Transformation/Processing Engine into a message processing pipeline to support
* XML message transformations.
- * <p/>
- * Sample Action Configuration:
- * <pre>
- * <Action name="Order_Xml-FROM_Acme-TO_AcmePartner" processor="SmooksTransformer">
- * <property name="message-type" value="Order" /> <!-- REQUIRED. -->
- * <property name="message-from" value="Acme" /> <!-- REQUIRED. -->
- * <property name="message-to" value="AcmePartner" /> <!-- REQUIRED. -->
- * <property name="message-encoding" value="UTF-8" /> <!-- OPTIONAL. Default "UTF-8" -->
- * </Action>
- * </pre>
- * Eventually, all the message properties defined on the action will come from the message metadata. This will
- * happen once we have a proper "normalized" message format with message headers etc.
*
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
* @since Version 4.0
@@ -66,62 +60,59 @@
public class SmooksTransformer implements TransformationService, ActionProcessor {
+ public static final String FROM_EPR = "from-epr";
+ public static final String FROM_TYPE = "from-type";
+ public static final String TO_EPR = "to-epr";
+ public static final String TO_TYPE = "to-type";
+
private static Logger logger = Logger.getLogger(SmooksTransformer.class);
private static final String SMOOKS_CDR_LST = "smooks-cdr.lst";
private static SmooksStandalone smooks;
- private String messageType;
- private String messageFrom;
- private String messageTo;
- private String messageEnc;
- private String messageUseragent;
- private String cpPrefix;
+ private String defaultMessageFromType;
+ private String defaultMessageFromEPR;
+ private String defaultMessageToType;
+ private String defaultMessageToEPR;
/**
* Public constructor.
* @param actionName Action name.
- * @param properties Action Properties.
+ * @param propertiesTree Action Properties.
* @throws ConfigurationException
* @throws ConfigurationException Action not properly configured.
*/
- public SmooksTransformer(String name, List<KeyValuePair> properties) throws ConfigurationException {
- messageType = KeyValuePair.getValue("message-type", properties);
- if(messageType == null || messageType.equals("")) {
- throw new ConfigurationException("Action configuration 'message-type' not specified.");
- }
- messageFrom = KeyValuePair.getValue("message-from", properties);
- if(messageFrom == null || messageFrom.equals("")) {
- throw new ConfigurationException("Action configuration 'message-from' not specified.");
- }
- messageTo = KeyValuePair.getValue("message-to", properties);
- if(messageTo == null || messageTo.equals("")) {
- throw new ConfigurationException("Action configuration 'message-to' not specified.");
- }
- messageEnc = KeyValuePair.getValue("message-encoding", properties, "UTF-8");
- // Test the configured encoding
- try {
- "astring".getBytes(messageEnc);
- } catch (UnsupportedEncodingException e) {
- throw new ConfigurationException("Invalid character encoding [" + messageEnc + "] on action configuration [" + name + "].", e);
- }
+ public SmooksTransformer(String name, ConfigTree propertiesTree) throws ConfigurationException {
+ this(propertiesTree);
+ }
+
+ /**
+ * Public constructor.
+ * @param propertiesTree Action Properties.
+ * @throws ConfigurationException
+ * @throws ConfigurationException Action not properly configured.
+ */
+ public SmooksTransformer(ConfigTree propertiesTree) throws ConfigurationException {
+ List<KeyValuePair> properties = propertiesTree.attributesAsList();
- // The "cpPrefix" property is "private" and only here in order to make unit testing easier.
- // It allows us to force a "bad" config location for the smooks-cdr.lst file....
- cpPrefix = KeyValuePair.getValue("smooks-cdr.list-classpath-prefix", properties, "/");
- if(!cpPrefix.startsWith("/")) {
- cpPrefix = "/" + cpPrefix;
+ defaultMessageFromType = KeyValuePair.getValue(FROM_TYPE, properties);
+ if(defaultMessageFromType != null && defaultMessageFromType.trim().equals("")) {
+ throw new ConfigurationException("Empty '" + FROM_TYPE + "' config attribute supplied.");
+ }
+ defaultMessageToType = KeyValuePair.getValue(TO_TYPE, properties);
+ if(defaultMessageToType != null && defaultMessageToType.trim().equals("")) {
+ throw new ConfigurationException("Empty '" + TO_TYPE + "' config attribute supplied.");
+ }
+ defaultMessageFromEPR = KeyValuePair.getValue(FROM_EPR, properties);
+ if(defaultMessageFromEPR != null && defaultMessageFromEPR.trim().equals("")) {
+ throw new ConfigurationException("Empty '" + FROM_EPR + "' config attribute supplied.");
+ }
+ defaultMessageToEPR = KeyValuePair.getValue(TO_EPR, properties);
+ if(defaultMessageToEPR != null && defaultMessageToEPR.trim().equals("")) {
+ throw new ConfigurationException("Empty '" + TO_EPR + "' config attribute supplied.");
+ }
+
+ if(smooks == null) {
+ initSmooks(properties);
}
-
- initSmooks();
-
- // In the context of the ESB, the Smooks useragent will be defined by the message "type", where it's
- // coming "from" and where it's going "to"...
- messageUseragent = messageType + "-" + messageFrom + "-" + messageTo;
- // Register the message metadata as "profiles" within the Smooks context. These profiles ("type",
- // "from" and "to") should expand out inside Smooks based on subprofiles that are
- // statically configured against these profiles in the device-profiles.xml file. This is a bit
- // of a hack but is fine for now just to get the ball rolling...
- smooks.registerUseragent(messageUseragent, new String[] {"type:" + messageType, "from:" + messageFrom, "to:" + messageTo});
- // TODO: Recurcively expand out the profiles supplied here using smooks.getContext().getProfileStore(). Do this inside SmooksStandalone
}
/* (non-Javadoc)
@@ -139,41 +130,220 @@
* @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
*/
public Message process(Message message) throws ActionProcessingException {
- Object oCurr = ActionUtils.getTaskObject(message);
+ Object payload = ActionUtils.getTaskObject(message);
+
try {
- if(oCurr instanceof String) {
+ if(payload instanceof String) {
byte[] messageBytes = null;
String transformedMessage;
+ String messageUseragent;
- try {
- messageBytes = ((String)oCurr).getBytes(messageEnc);
- } catch (UnsupportedEncodingException e) {
- // Can't happen - encoding was already tested in the constructor.
- }
+ // Register the message useragent with Smooks (if not already registered)...
+ messageUseragent = registerMessageUseragent(message);
- // TODO: Cater for more message input types e.g. InputStream, DOM Document...
- // TODO: Cater for more message output types e.g. InputStream, DOM Document...
+ messageBytes = ((String)payload).getBytes("UTF-8");
long start = System.currentTimeMillis();
transformedMessage = smooks.filterAndSerialize(messageUseragent, new ByteArrayInputStream(messageBytes));
if(logger.isDebugEnabled()) {
long timeTaken = System.currentTimeMillis() - start;
logger.debug("Transformed message for useragent [" + messageUseragent + "]. Time taken: "
- + timeTaken + ". Message in:\n[" + oCurr.toString()+ "]. \nMessage out:\n[" + transformedMessage + "].");
+ + timeTaken + ". Message in:\n[" + payload.toString()+ "]. \nMessage out:\n[" + transformedMessage + "].");
}
ActionUtils.setTaskObject(message,transformedMessage);
} else {
- String sClass = (null==oCurr) ? "<null>" : oCurr.getClass().getName();
+ String sClass = (null==payload) ? "<null>" : payload.getClass().getName();
logger.warn("String message types only supported. Input message was ["
+ sClass + "]. Returning message untransformed.");
}
} catch(Throwable thrown) {
throw new ActionProcessingException("Message transformation failed.", thrown);
}
+
+ // TODO: Cater for more message input types e.g. InputStream, DOM Document...
+ // TODO: Cater for more message output types e.g. InputStream, DOM Document...
+
return message;
}
- /* (non-Javadoc)
+ /**
+ * Register the Message Flow as a useragent within Smooks.
+ * @param message The message.
+ * @return The Smooks "usragent" string that uniquely identifies the message flow associated
+ * with the message.
+ * @throws ActionProcessingException Failed to register the message flow for the message.
+ */
+ private String registerMessageUseragent(Message message) throws ActionProcessingException {
+ String messageUseragent;
+ String messageFromType;
+ String messageFrom;
+ String messageToType;
+ String messageTo;
+
+ // Get the routing info from the message/configuration (mandatory)...
+ messageFrom = getFromEPR(message);
+ if(messageFrom == null) {
+ throw new ActionProcessingException("'from-epr' address not set on message/configuration.");
+ }
+ messageTo = getToEPR(message);
+ if(messageTo == null) {
+ throw new ActionProcessingException("'to-epr' address not set on message/configuration.");
+ }
+
+ // Get the message typing info from the message/configuration (optional)...
+ messageFromType = (String)message.getProperties().getProperty(FROM_TYPE, defaultMessageFromType);
+ messageToType = (String)message.getProperties().getProperty(TO_TYPE, defaultMessageToType);
+
+ // Construct the message useragent string for use with Smooks. This is basically the
+ // name of the Message Flow on which transformations are to be performed...
+ messageUseragent = getMessageUseragentString(messageFromType, messageFrom, messageToType, messageTo);
+
+ // Register this message flow if it isn't already registered...
+ try {
+ smooks.getSession(messageUseragent);
+ } catch(UnknownDeviceException e) {
+ String[] profiles = getMessageUseragentProfiles(messageFromType, messageFrom, messageToType, messageTo);
+
+ // Register the message flow within the Smooks context....
+ logger.info("Registering message-flow useragent: [" + messageUseragent + "]. Profiles: [" + Arrays.asList(profiles) + "]");
+ smooks.registerUseragent(messageUseragent, profiles);
+ }
+
+ return messageUseragent;
+ }
+
+ /**
+ * Get the "From" EPR address from the message.
+ * <p/>
+ * Returns the default "from-epr" (from the action configurations) if not set on the message.
+ * @param message The message.
+ * @throws ActionProcessingException
+ */
+ private String getFromEPR(Message message) throws ActionProcessingException {
+ try {
+ Header header = message.getHeader();
+ if(header == null) {
+ return defaultMessageFromEPR;
+ }
+ Call call = header.getCall();
+ if(call == null) {
+ return defaultMessageFromEPR;
+ }
+ EPR from = call.getFrom();
+ if(from == null) {
+ return defaultMessageFromEPR;
+ }
+ if(from.getAddr() == null) {
+ return defaultMessageFromEPR;
+ }
+ String eprAddress = from.getAddr().getAddress();
+ if(eprAddress == null || eprAddress.trim().equals("")) {
+ return defaultMessageFromEPR;
+ }
+
+ return eprAddress;
+ } catch (Throwable thrown) {
+ throw new ActionProcessingException("Message validation failure.", thrown);
+ }
+ }
+
+ /**
+ * Get the "To" EPR address from the message.
+ * <p/>
+ * Returns the default "to-epr" (from the action configurations) if not set on the message.
+ * @param message The message.
+ * @throws ActionProcessingException
+ */
+ private String getToEPR(Message message) throws ActionProcessingException {
+ try {
+ Header header = message.getHeader();
+ if(header == null) {
+ return defaultMessageToEPR;
+ }
+ Call call = header.getCall();
+ if(call == null) {
+ return defaultMessageToEPR;
+ }
+ EPR to = call.getTo();
+ if(to == null) {
+ return defaultMessageToEPR;
+ }
+ if(to.getAddr() == null) {
+ return defaultMessageToEPR;
+ }
+ String eprAddress = to.getAddr().getAddress();
+ if(eprAddress == null || eprAddress.trim().equals("")) {
+ return defaultMessageToEPR;
+ }
+
+ return eprAddress;
+ } catch (Throwable thrown) {
+ throw new ActionProcessingException("Message validation failure.", thrown);
+ }
+ }
+
+ /**
+ * Get the profile list based on the supplied message flow properties.
+ * @param messageFromType The type string for the message source.
+ * @param messageFrom The EPR string for the message source.
+ * @param messageToType The type string for the message target.
+ * @param messageTo The EPR srting for the message target.
+ * @return The list of profiles.
+ */
+ protected static String[] getMessageUseragentProfiles(String messageFromType, String messageFrom, String messageToType, String messageTo) {
+ List<String> profiles = new ArrayList<String>();
+ String[] profileArray;
+
+ if(messageFromType != null) {
+ profiles.add(FROM_TYPE + ":" + messageFromType);
+ }
+ if(messageFrom != null) {
+ profiles.add(FROM_EPR + ":" + messageFrom);
+ }
+ if(messageToType != null) {
+ profiles.add(TO_TYPE + ":" + messageToType);
+ }
+ if(messageTo != null) {
+ profiles.add(TO_EPR + ":" + messageTo);
+ }
+
+ profileArray = new String[profiles.size()];
+ profiles.toArray(profileArray);
+
+ return profileArray;
+ }
+
+ /**
+ * Construct the Smooks useragent string based on the supplied message flow properties.
+ * @param messageFromType The type string for the message source.
+ * @param messageFrom The EPR string for the message source.
+ * @param messageToType The type string for the message target.
+ * @param messageTo The EPR srting for the message target.
+ * @return Smooks useragent string for the message flow.
+ */
+ protected static String getMessageUseragentString(String messageFromType, String messageFrom, String messageToType, String messageTo) {
+ StringBuffer string = new StringBuffer();
+
+ if(messageFromType != null) {
+ string.append(FROM_TYPE + ":" + messageFromType);
+ string.append((messageFrom!=null || messageToType!=null || messageTo!=null?":":""));
+ }
+ if(messageFrom != null) {
+ string.append(FROM_EPR + ":" + messageFrom);
+ string.append((messageToType!=null || messageTo!=null?":":""));
+ }
+ if(messageToType != null) {
+ string.append(TO_TYPE + ":" + messageToType);
+ string.append((messageTo!=null?":":""));
+ }
+ if(messageTo != null) {
+ string.append(TO_EPR + ":" + messageTo);
+ }
+
+ return string.toString();
+ }
+
+ /* (non-Javadoc)
* @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
*/
public Serializable getOkNotification(Message message) {
@@ -192,21 +362,28 @@
* <p/>
* We may need to write a Smooks Container implementation specifically for JBossESB's needs. SmooksStandalone is
* fine for a start though.
+ * @param properties Action configuration properties.
* @throws ConfigurationException Failed to load Smooks configurations.
*/
- protected void initSmooks() throws ConfigurationException {
+ protected void initSmooks(List<KeyValuePair> properties) throws ConfigurationException {
synchronized (SmooksTransformer.class) {
if(smooks == null) {
- InputStream configListStream = getClass().getResourceAsStream(cpPrefix + SMOOKS_CDR_LST);
+ String cpPrefix;
+
+ // The "cpPrefix" property is "private" and only here in order to make unit testing easier.
+ // It allows us to force a "bad" config location for the smooks-cdr.lst file....
+ cpPrefix = KeyValuePair.getValue("smooks-cdr.list-classpath-prefix", properties, "/");
+ if(!cpPrefix.startsWith("/")) {
+ cpPrefix = "/" + cpPrefix;
+ }
+
+ InputStream configListStream = getClass().getResourceAsStream(cpPrefix + SMOOKS_CDR_LST);
if(configListStream == null) {
throw new ConfigurationException("Failed to locate Smooks configuration list file [" + SMOOKS_CDR_LST + "]. The folder containing this file must be located at " + cpPrefix + " relative to the root of the classpath.");
}
- // TODO: There's a potential issue here if two SmooksTransformer action configs specify and require
- // different encodings. This is because they're all sharing the same static SmooksStandalone instance!!
- // This should eventually be solveable by creating a proper Smooks container impl for the ESB.
- smooks = new SmooksStandalone(messageEnc);
+ smooks = new SmooksStandalone("UTF-8");
try {
BufferedReader configReader = new BufferedReader(new InputStreamReader(configListStream));
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/EchoRouter.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/EchoRouter.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/EchoRouter.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions.routing;
+
+import java.io.Serializable;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Echo Action Processor.
+ *
+ * <p/> Sample Action Configuration:
+ *
+ * <pre>
+ * <Action class="org.jboss.soa.esb.actions.routing.EchoRouter"></Action>
+ * </pre>
+ *
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ */
+public class EchoRouter implements ActionProcessor {
+
+ /* The logger for this class */
+ private static Logger logger = Logger.getLogger(EchoRouter.class);
+
+ public EchoRouter (ConfigTree configTree){
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public org.jboss.soa.esb.message.Message process(
+ org.jboss.soa.esb.message.Message message)
+ throws ActionProcessingException {
+
+ if (logger.isInfoEnabled()) {
+ logger.info("EchoRouter currently routing message " + message + " with payload <<" + ActionUtils.getTaskObject(message) + ">>");
+ }
+
+ return message;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(
+ org.jboss.soa.esb.message.Message message) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(
+ org.jboss.soa.esb.message.Message message) {
+ return null;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/HttpRouter.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/HttpRouter.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/HttpRouter.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions.routing;
+
+import java.io.Serializable;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+
+/**
+ * HttpRouter Action Processor. This ActionProcessor will forward the message to an url for further processing.
+ * If the routeUrl property is not set a default url will be used.
+ *
+ * <p/> Sample Action Configuration:
+ *
+ * <pre>
+ * <Action class="org.jboss.soa.esb.actions.routing.HttpRouter">
+ * <property name="routeUrl" value="http://localhost:8888"</property>
+ * </Action>
+ * </pre>
+ *
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ */
+public class HttpRouter implements ActionProcessor {
+
+ /* The logger for this class */
+ private static Logger logger = Logger.getLogger(HttpRouter.class);
+
+ /* The configuration for this ActionProcessor */
+ private ConfigTree configTree = null;
+
+ /* The url to route the message to */
+ private String urlToRouteTo = null;
+
+ /*
+ * The url to route the message to if the url was not set in the
+ * configuration
+ */
+ private static final String DEFAULT_URL_TO_ROUTE_TO = "http://localhost:5400";
+
+ /**
+ * Constructing a HttpRouter instance
+ *
+ * @param configTree
+ * the configuration to use in this HttpRouter instance
+ */
+ public HttpRouter(ConfigTree configTree) {
+ this.configTree = configTree;
+ this.urlToRouteTo = this
+ .obtainAttribute(ListenerTagNames.HTTP_ROUTER_ROUTE_URL,
+ DEFAULT_URL_TO_ROUTE_TO);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public org.jboss.soa.esb.message.Message process(
+ org.jboss.soa.esb.message.Message message)
+ throws ActionProcessingException {
+
+ Object oCurr = ActionUtils.getTaskObject(message);
+
+ if (logger.isInfoEnabled()) {
+ logger
+ .info("HttpRouter currently routing message " + message
+ + " with payload <<" + oCurr + ">> to "
+ + this.urlToRouteTo);
+ }
+
+ try {
+ InvokerLocator locator = new InvokerLocator(this.urlToRouteTo);
+
+ Client remotingClient = new Client(locator);
+ remotingClient.connect();
+
+ remotingClient.invoke(oCurr, null);
+ return message;
+ } catch (Throwable e) {
+ String errorMessage = "Exception while sending message [" + oCurr
+ + "] to destination [" + this.urlToRouteTo + "].";
+ logger.error(errorMessage, e);
+ throw new ActionProcessingException(errorMessage, e);
+ }
+ }
+
+ /**
+ * Method obtaining an attribute from the configuration tree
+ *
+ * @param tree
+ * the configuration to use
+ * @param p_sAtt
+ * the name of the attribute to get
+ * @param p_sDefault
+ * the default value for the attribute if not set
+ * @return the value of the attribute or the default one is not set in
+ * configuration tree
+ */
+ private String obtainAttribute(String p_sAtt, String p_sDefault) {
+ String sVal = this.configTree.getAttribute(p_sAtt);
+ return (null != sVal) ? sVal : p_sDefault;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(
+ org.jboss.soa.esb.message.Message message) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(
+ org.jboss.soa.esb.message.Message message) {
+ return null;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerInitializationException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerInitializationException.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerInitializationException.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,47 @@
+package org.jboss.soa.esb.listeners;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ */
+public class ListenerInitializationException extends BaseException{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6872003497155955428L;
+
+ /**
+ * Public Default Constructor.
+ */
+ public ListenerInitializationException() {
+ super();
+ }
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ */
+ public ListenerInitializationException(String message) {
+ super(message);
+ }
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public ListenerInitializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Public Constructor.
+ * @param cause Exception cause.
+ */
+ public ListenerInitializationException(Throwable cause) {
+ super(cause);
+ }
+
+}
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -1,3 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+/**
+ * Contains tag names as they can be used in the configuration.
+ *
+ */
package org.jboss.soa.esb.listeners;
public class ListenerTagNames
@@ -2,10 +27,56 @@
{
- public static final String SERVICE_NAME_TAG = "service-name";
- public static final String TARGET_SERVICE_NAME_TAG = "target-service-name";
+ /** Registry */
+ public static final String SERVICE_CATEGORY_NAME_TAG = "service-category";
+ public static final String SERVICE_NAME_TAG = "service-name";
+ public static final String SERVICE_DESCRIPTION_TAG = "service-description";
+ public static final String EPR_DESCRIPTION_TAG = "epr-description";
+
+ /** Gateways */
+ public static final String TARGET_SERVICE_CATEGORY_TAG = "target-service-category";
+ public static final String TARGET_SERVICE_NAME_TAG = "target-service-name";
- public static final String ACTION_ELEMENT_TAG = "action";
- public static final String ACTION_CLASS_TAG = "class";
- public static final String PROCESS_METHOD_TAG = "process";
+ /** ActionProcessingPipeline */
+ public static final String ACTION_ELEMENT_TAG = "action";
+ public static final String ACTION_CLASS_TAG = "class";
+ public static final String PROCESS_METHOD_TAG = "process";
+ public static final String ACTION_PROPERTY_TAG = "property";
public static final String NORMAL_COMPLETION_METHOD_TAG = "okMethod";
- public static final String EXCEPTION_METHOD_TAG = "exceptionMethod";
+ public static final String EXCEPTION_METHOD_TAG = "exceptionMethod";
+ public static final String HTTP_ROUTER_ROUTE_URL = "routeUrl";
+
+
+ /** Content Based Routing */
+ public static final String CBR_TAG = "cbr";
+
+ /** RuleSet reference (Filename) */
+ public static final String RULE_SET_TAG = "ruleSet";
+ public static final String RULE_LANGUAGE_TAG = "ruleLanguage";
+
+ /** Poller tagnames */
+ public static final String POLL_LATENCY_SECS_TAG = "pollLatencySeconds";
+
+ /** File Actions */
+ public static final String FILE_INPUT_DIR_TAG = "inputDir";
+ public static final String FILE_INPUT_SFX_TAG = "inputSuffix";
+ public static final String FILE_WORK_SFX_TAG = "workSuffix";
+ public static final String FILE_ERROR_DIR_TAG = "errorDir";
+ public static final String FILE_ERROR_SFX_TAG = "errorSuffix";
+ public static final String FILE_POST_DIR_TAG = "postDir";
+ public static final String FILE_POST_SFX_TAG = "postSuffix";
+ public static final String FILE_POST_DEL_TAG = "postDelete";
+
+ /** SQL related */
+ public static final String SQL_ROW_DATA_TAG = "sqlRowData";
+
+ public static final String SQL_TABLE_NAME_TAG = "tableName";
+ public static final String SQL_SELECT_FIELDS_TAG = "selectFields";
+ public static final String SQL_KEY_FIELDS_TAG = "keyFields";
+ public static final String SQL_IN_PROCESS_FIELD_TAG = "inProcessField";
+ public static final String SQL_IN_PROCESS_VALUES_TAG = "inProcessValues";
+ public static final String SQL_WHERE_CONDITION_TAG = "whereCondition";
+ public static final String SQL_ORDER_BY_TAG = "orderBy";
+ public static final String SQL_POST_DEL_TAG = "postDelete";
+
+ /** Reply Listener */
+ public static final String REPLY_LISTENER_TIMEOUT_TAG = "replyListenerTimeout";
}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,355 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners.gateway;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.Util;
+import org.jboss.soa.esb.ConfigurationException;
+
+/**
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ *
+ */
+public class FileGatewayListener implements Runnable
+{
+
+ public FileGatewayListener(GatewayListenerController commandListener, ConfigTree config)
+ throws Exception
+ {
+ _config = config;
+ _controller = commandListener;
+ _sleepBetweenPolls = 10000; // milliseconds
+ checkMyParms();
+ } // __________________________________
+
+ public void run()
+ {
+ if (null!=_serviceName)
+ try { _controller.register(_config,_myEpr); }
+ catch (RegistryException e1)
+ { _logger.warn("unable to register service",e1); }
+
+ boolean bSleep = false;
+ while (_controller.continueLooping())
+ {
+ // only sleep in between - not the first time
+ if (bSleep)
+ { long lUntil = System.currentTimeMillis()+_sleepBetweenPolls;
+ while (System.currentTimeMillis() < lUntil)
+ {
+ try { Thread.sleep(1000); }
+ catch (InterruptedException e) { lUntil = 0; }
+ if (! _controller.continueLooping())
+ break;
+ }
+ }
+ else
+ bSleep = true;
+ if (! _controller.continueLooping())
+ break;
+
+ for (File fileIn : _inputDirectory.listFiles(_fileFilter))
+ {
+ // Try to rename - if unsuccessful, somebody else got it first
+ File fileWork = new File(fileIn.getParent(),fileIn.getName()+_workingSuffix);
+ if (! fileIn.renameTo(fileWork))
+ continue;
+
+ Throwable thrown = null;
+ String text = null;
+ try
+ {
+ Object obj = _processMethod.invoke(_composer,new Object[] {fileWork} );
+ if (null==obj)
+ {
+ _logger.warn("Action class method <"+_processMethod.getName()+"> returned a null object");
+ continue;
+ }
+ _courier.deliver((org.jboss.soa.esb.message.Message)obj);
+ }
+
+ catch (InvocationTargetException e)
+ {
+ thrown = e;
+ text = "Problems invoking method <"+_processMethod.getName()+">";
+
+ }
+ catch (IllegalAccessException e)
+ {
+ thrown = e;
+ text = "Problems invoking method <"+_processMethod.getName()+">";
+ }
+ catch (ClassCastException e)
+ {
+ thrown = e;
+ text = "Action class method <"+_processMethod.getName()+"> returned a non Message object";
+ }
+ catch (CourierException e)
+ {
+ thrown = e;
+ text = "Courier <"+_courier.getClass().getName()+".deliver(Message) FAILED";
+ }
+
+ if (null==thrown)
+ {
+ File fileOK = new File(_postProcessDirectory,fileIn.getName()+_postProcessSuffix);
+ if (_deleteAfterOK)
+ fileWork.delete();
+ else
+ {
+ fileOK.delete();
+ fileWork.renameTo(fileOK);
+ }
+ }
+ else
+ {
+ thrown.printStackTrace();
+ _logger.error(text,thrown);
+ File fileError = new File(_errorDirectory,fileIn.getName()+_errorSuffix);
+ fileWork.renameTo(fileError);
+ }
+ }
+ }
+
+ if (null!=_serviceName)
+ try { _controller.unRegister(_serviceCategory, _serviceName,_myEpr); }
+ catch (RegistryException e1){ _logger.warn("unable to unRegister service",e1); }
+
+ } // ________________________________
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ *
+ * @throws Exception -
+ * if mandatory atts are not right or actionClass not in
+ * classpath
+ */
+ protected void checkMyParms() throws Exception
+ {
+ // Third arg is null - Exception will be thrown if attribute is not found
+ _targetServiceCategory = _controller.obtainAtt(_config, ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
+ _targetServiceName = _controller.obtainAtt(_config, ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
+ _targetEpr = _controller.getEprByName(_targetServiceName);
+ if (null==_targetEpr)
+ throw new ConfigurationException("EPR <"+_targetServiceName+"> not found in registry");
+ _courier = CourierFactory.getCourier(_targetEpr);
+
+ // Polling interval
+ String sAux = _config.getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
+ if (! Util.isNullString(sAux))
+ try { _sleepBetweenPolls = 1000 * Long.parseLong(sAux); }
+ catch (NumberFormatException e)
+ { _logger.warn("Invalid poll latency - keeping default of "+(_sleepBetweenPolls/1000)); }
+
+ resolveComposerClass();
+
+ // INPUT directory and suffix (used for FileFilter)
+ String sInpDir = _controller.obtainAtt(_config,ListenerTagNames.FILE_INPUT_DIR_TAG,null);
+ _inputDirectory = fileFromString(sInpDir);
+ seeIfOkToWorkOnDir(_inputDirectory);
+
+ _inputSuffix = _controller.obtainAtt(_config,ListenerTagNames.FILE_INPUT_SFX_TAG,null);
+ _inputSuffix = _inputSuffix.trim();
+ if (_inputSuffix.length()<1)
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_INPUT_SFX_TAG+" attribute");
+ _fileFilter = new FileEndsWith(_inputSuffix);
+
+ // WORK suffix (will rename in input directory)
+ _workingSuffix = _controller.obtainAtt(_config,ListenerTagNames.FILE_WORK_SFX_TAG,".esbWork").trim();
+ if (_workingSuffix.length()<1)
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_WORK_SFX_TAG+" attribute");
+ if (_inputSuffix.equals(_workingSuffix))
+ throw new Exception("Work suffix must differ from input suffix <"+_workingSuffix+">");
+
+ // ERROR directory and suffix (defaults to input dir and ".esbError" suffix)
+ String sErrDir = _controller.obtainAtt(_config,ListenerTagNames.FILE_ERROR_DIR_TAG,sInpDir);
+ _errorDirectory = fileFromString(sErrDir);
+ seeIfOkToWorkOnDir(_errorDirectory);
+
+ _errorSuffix = _controller.obtainAtt(_config,ListenerTagNames.FILE_ERROR_SFX_TAG,".esbError").trim();
+ if (_errorSuffix.length()<1)
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_ERROR_SFX_TAG+" attribute");
+ if (_errorDirectory.equals(_inputDirectory) && _inputSuffix.equals(_errorSuffix))
+ throw new Exception("Error suffix must differ from input suffix <"+_errorSuffix+">");
+
+
+ // Do users wish to delete files that were processed OK ?
+ String sPostDel = _controller.obtainAtt(_config,ListenerTagNames.FILE_POST_DEL_TAG,"false").trim();
+ _deleteAfterOK = Boolean.parseBoolean(sPostDel);
+ if (_deleteAfterOK)
+ return;
+
+ // POST (done) directory and suffix (defaults to input dir and ".esbDone" suffix)
+ String sPostDir = _controller.obtainAtt(_config,ListenerTagNames.FILE_POST_DIR_TAG,sInpDir);
+ _postProcessDirectory = fileFromString(sPostDir);
+ seeIfOkToWorkOnDir(_postProcessDirectory);
+ _postProcessSuffix = _controller.obtainAtt(_config,ListenerTagNames.FILE_POST_SFX_TAG,".esbDone").trim();
+ if (_postProcessDirectory.equals(_inputDirectory))
+ { if (_postProcessSuffix.length()<1)
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_POST_SFX_TAG+" attribute");
+ if (_postProcessSuffix.equals(_inputSuffix))
+ throw new Exception("Post process suffix must differ from input suffix <"+_postProcessSuffix+">");
+ }
+ } //________________________________
+
+ protected void resolveComposerClass() throws Exception
+ {
+ // Look for first "action" element - only first one will be used
+ String tagName = ListenerTagNames.ACTION_ELEMENT_TAG;
+ ConfigTree actionElement = _config.getFirstChild(tagName);
+ String sProcessMethod = null;
+ if (null!=actionElement)
+ { // class attribute
+ _composerName = _controller.obtainAtt(actionElement,ListenerTagNames.ACTION_CLASS_TAG,null);
+ _composerClass = Class.forName(_composerName);
+ Constructor oConst = _composerClass.getConstructor(new Class[] {ConfigTree.class});
+ _composer= oConst.newInstance(_config);
+ tagName = ListenerTagNames.PROCESS_METHOD_TAG;
+ sProcessMethod = _controller.obtainAtt(_config,tagName,tagName);
+ }
+ else
+ {
+ _composerName = PackageFileContents.class.getName();
+ _composerClass= PackageFileContents.class;
+ _composer = new PackageFileContents();
+ sProcessMethod = "process";
+ }
+
+ _processMethod = _composerClass.getMethod(sProcessMethod,new Class[] {Object.class});
+ } //________________________________
+
+ protected void seeIfOkToWorkOnDir (File p_oDir) throws Exception
+ {
+ if (! p_oDir.exists())
+ throw new Exception ("Directory "+p_oDir.toString()+" not found");
+ if (!p_oDir.isDirectory())
+ throw new Exception(p_oDir.toString()+" is not a directory");
+ if (!p_oDir.canRead())
+ throw new Exception("Can't read directory "+p_oDir.toString());
+ if (! p_oDir.canWrite())
+ throw new Exception ("Can't write/rename in directory "+p_oDir.toString());
+ } //________________________________
+
+ private File fileFromString(String file)
+ {
+ try { return new File(new URI(file)); }
+ catch(Exception e) { return new File(file); }
+ } //________________________________
+
+ private class FileEndsWith implements FileFilter
+ {
+ String m_sSuffix;
+ FileEndsWith(String p_sEnd) throws Exception
+ {
+ m_sSuffix = p_sEnd;
+ if (Util.isNullString(m_sSuffix))
+ throw new Exception("Must specify file extension");
+ } //______________________________
+
+ public boolean accept(File p_f)
+ { return (p_f.isFile())
+ ? p_f.toString().endsWith(m_sSuffix)
+ : false;
+ } //______________________________
+ } //____________________________________________________
+
+/**
+ * Default gateway action for files
+ * <p/>It will just drop the file contents into a Message
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ *
+ */
+ private static class PackageFileContents
+ {
+ public Message process (Object obj) throws Exception
+ {
+ if (! (obj instanceof File))
+ throw new Exception ("Object must be instance of File");
+
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().setContents(getFileContent((File)obj));
+ return message;
+ }
+
+ private byte[] getFileContent(File file) throws Exception
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] ba = new byte[1000];
+ int iQread;
+
+ FileInputStream inp = new FileInputStream(file);
+ while (-1!= (iQread=inp.read(ba)))
+ if (iQread > 0)
+ out.write(ba,0,iQread);
+ inp.close();
+
+ out.close();
+ return out.toByteArray();
+ }
+ } //____________________________________________________
+
+ protected final static Logger _logger = Logger.getLogger(FileGatewayListener.class);
+
+ protected ConfigTree _config;
+ protected GatewayListenerController _controller;
+ protected long _sleepBetweenPolls; // milliseconds
+
+ protected String _serviceCategory, _serviceName;
+ protected String _targetServiceCategory ,_targetServiceName;
+ protected EPR _myEpr ,_targetEpr;
+
+ protected String _composerName;
+ protected Class _composerClass;
+ protected Object _composer;
+ protected Method _processMethod;
+
+ protected Courier _courier;
+
+ protected boolean _deleteAfterOK;
+ protected File _inputDirectory ,_errorDirectory ,_postProcessDirectory;
+ protected String _inputSuffix ,_postProcessSuffix
+ ,_workingSuffix ,_errorSuffix
+ ;
+ protected FileFilter _fileFilter;
+} //____________________________________________________________________________
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -33,14 +33,17 @@
import org.jboss.internal.soa.esb.command.CommandQueue;
import org.jboss.internal.soa.esb.command.CommandQueueException;
import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.actions.ActionDefinitionFactory;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.util.EPRManager;
import org.jboss.soa.esb.common.Environment;
import org.jboss.soa.esb.common.ModulePropertyManager;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.parameters.ParamRepositoryException;
import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
import org.jboss.soa.esb.util.Util;
import org.xml.sax.SAXException;
@@ -104,11 +107,8 @@
return m_oException;
}
};
-
- private ActionDefinitionFactory actionDefinitionFactory;
-
/**
- * Package pivate default constructor.
+ * Package private default constructor.
*/
protected GatewayListenerController() { }
@@ -213,13 +213,6 @@
_endTime = (null == sEndT) ? Long.MAX_VALUE : _dateFormat.parse(
sEndT).getTime();
- // Read and initialise the action definitions...
- ConfigTree actionConfig = p_oP.getFirstChild("Actions");
- if(actionConfig == null) {
- throw new ConfigurationException("No 'Actions' configuration.");
- }
- actionDefinitionFactory = new ActionDefinitionFactory(actionConfig);
-
} // ________________________________
/**
@@ -265,12 +258,8 @@
while (endNotRequested())
{
_status = State.Running;
- for (ConfigTree oCurr : _config.getAllChildren()) {
- String sClass = oCurr.getAttribute(GATEWAY_CLASS_TAG);
- if (Util.isNullString(sClass))
- continue;
- tryToLaunchGateway(oCurr, sClass);
- }
+ for (ConfigTree oCurr : _config.getAllChildren())
+ tryToLaunchGateway(oCurr);
waitForCmdOrSleep();
@@ -301,24 +290,30 @@
.info("Finishing_____________________________________________________");
// Close the command queue...
- try {
- _commandQueue.close();
+ try
+ {
+ if (null!=_commandQueue)
+ _commandQueue.close();
} catch (CommandQueueException e) {
_logger.error("Error closing Command Queue.", e);
}
} // ________________________________
- private void tryToLaunchGateway(ConfigTree p_oP, String p_sClassName)
+ private void tryToLaunchGateway(ConfigTree p_oP)
{
+ String sClass = p_oP.getAttribute(GATEWAY_CLASS_TAG);
+ if (Util.isNullString(sClass))
+ return;
+
try {
- Class oListener = Class.forName(p_sClassName);
- Constructor oConst = oListener.getConstructor(new Class[] {
- this.getClass(), ConfigTree.class, ActionDefinitionFactory.class });
- Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this,
- p_oP, actionDefinitionFactory });
+ Class oListener = Class.forName(sClass);
+ Constructor oConst = oListener.getConstructor(new Class[]
+ {this.getClass(), ConfigTree.class});
+ Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this, p_oP});
new Thread(oRun).start();
} catch (Exception e) {
- _logger.error("Cannot launch <" + p_sClassName + ">\n", e);
+ _logger.error("Cannot launch <" + sClass + ">\n", e);
+ e.printStackTrace();
}
} // ________________________________
@@ -327,6 +322,7 @@
} // ________________________________
private void waitForCmdOrSleep() {
+
long lToGo = millisToWait();
if (null == _commandQueue) {
@@ -334,14 +330,13 @@
// No command queue nor topic - Just sleep until time
// exhausted, or thread interrupted
try {
- if (lToGo > 0)
- Thread.sleep(lToGo);
+ while ((lToGo=millisToWait()) > 0)
+ Thread.sleep(500);
} catch (InterruptedException e) {
_endTime = 0; // mark as end requested and return
}
return;
}
-
// Wait for commands until time exhausted or command received
// Note that received commands might change time variables (reload/end)
// that's why time to go is recalculated on each cycle
@@ -436,6 +431,10 @@
return _endRequested || System.currentTimeMillis() >= _endTime;
}
+ public void requestEnd() {
+ _endRequested=true;
+ _endTime = 0;
+ }
/**
* Accessor to determine if execution time is not expired, and no shutdown
* request received
@@ -507,23 +506,72 @@
return getEprManager().loadEPR(serviceName);
} // ________________________________
- public void register (String serviceName, EPR address)
+
+ /**
+ * @deprecated use register (ConfigTree config, EPR address) instead.
+ * @param name
+ * @param address
+ */
+ public void register (String name, EPR address)
{
- try { getEprManager().saveEPR(serviceName,address); }
+ try { getEprManager().saveEPR(name,address); }
catch (IOException e)
{
_logger.fatal("Cannot register service",e);
}
} // ________________________________
-
- public void unRegister (String serviceName, EPR address)
+ /**
+ * @deprecated use unRegister (String serviceCategoryName, String serviceName, EPR epr) instead.
+ * @param name
+ */
+ public void unRegister (String name)
{
- try { getEprManager().removeEPR(serviceName); }
+ try { getEprManager().removeEPR(name); }
catch (IOException e)
{
_logger.fatal("Cannot un-register service",e);
}
} // ________________________________
+ /**
+ * Register an EPR in the registry.
+ *
+ * @param config - a config tree containing the deployment-configuration of the service.
+ * @param epr - the epr (EndPoint Reference) of the service.
+ *
+ * @throws RegistryException
+ */
+ public void register(ConfigTree config , EPR epr) throws RegistryException
+ {
+ String serviceCategoryName = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+ String serviceName = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ if ("eprManager".equalsIgnoreCase(serviceCategoryName))
+ {
+ register(serviceName,epr);
+ return;
+ }
+ String serviceDescription = config.getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
+ String eprDescription = config.getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG);
+ Registry registry = RegistryFactory.getRegistry();
+ registry.registerEPR(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription);
+ }
+ /**
+ * Unregister the EPR from the registry.
+ *
+ * @param serviceCategoryName - name of the category of the service ('Content Based Routing')
+ * @param serviceName - name of the service ("
+ * @param epr
+ * @throws RegistryException
+ */
+ public void unRegister(String serviceCategoryName, String serviceName , EPR epr) throws RegistryException
+ {
+ if ("eprManager".equalsIgnoreCase(serviceCategoryName))
+ {
+ unRegister(serviceName);
+ return;
+ }
+ Registry registry = RegistryFactory.getRegistry();
+ registry.unRegisterEPR(serviceCategoryName, serviceName, epr);
+ }
private CommandQueue _commandQueue;
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -22,22 +22,26 @@
package org.jboss.soa.esb.listeners.gateway;
+import java.io.ByteArrayOutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
+import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
+import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
+import javax.jms.TextMessage;
import javax.naming.Context;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.couriers.Courier;
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
@@ -45,6 +49,8 @@
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.registry.RegistryException;
public class JmsGatewayListener implements Runnable
{
@@ -61,7 +67,9 @@
public void run()
{
if (null!=_serviceName)
- _controller.register(_serviceName,_myEpr);
+ try { _controller.register(_config,_myEpr); }
+ catch (RegistryException e1)
+ { _logger.warn("unable to register service",e1); }
while (_controller.continueLooping())
{
@@ -108,8 +116,13 @@
}
if (null!=_serviceName)
- _controller.unRegister(_serviceName,_myEpr);
+ try { _controller.unRegister(_serviceCategory, _serviceName,_myEpr); }
+ catch (RegistryException e1){ _logger.warn("unable to unRegister service",e1); }
+
+ if (null != _messageReceiver)
+ try { _messageReceiver.close(); }
+ catch (Exception e1) {/* Tried my best - Just continue */ }
if (null != _queueSession)
try { _queueSession.close(); }
catch (Exception e1) {/* Tried my best - Just continue */ }
@@ -128,30 +141,16 @@
protected void checkMyParms() throws Exception
{
// Third arg is null - Exception will be thrown if attribute is not found
+ _targetServiceCategory = _controller.obtainAtt(_config, ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
_targetServiceName = _controller.obtainAtt(_config, ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
_targetEpr = _controller.getEprByName(_targetServiceName);
if (null==_targetEpr)
throw new ConfigurationException("EPR <"+_targetServiceName+"> not found in registry");
_queueName = _controller.obtainAtt(_config, JMSEpr.DESTINATION_NAME_TAG, null);
+
+ resolveComposerClass();
- // Look for first "action" element - only first one will be used
- String tagName = ListenerTagNames.ACTION_ELEMENT_TAG;
- ConfigTree actionElement = _config.getFirstChild(tagName);
- if (null==actionElement)
- throw new ConfigurationException("Missing <"+tagName+"> element");
- // class attribute
- _composerName = _controller.obtainAtt(actionElement,ListenerTagNames.ACTION_CLASS_TAG,null);
- _composerClass = Class.forName(_composerName);
- Constructor oConst = _composerClass.getConstructor(new Class[] {ConfigTree.class});
- _composer= oConst.newInstance(_config);
-
- // From here onwards, all attributes have a default value
- // process attribute
- tagName = ListenerTagNames.PROCESS_METHOD_TAG;
- String sProcessMethod = _controller.obtainAtt(_config,tagName,tagName);
- _processMethod = _composerClass.getMethod(sProcessMethod,new Class[] {Message.class});
-
// No problem if selector is null - everything in queue will be returned
_messageSelector = _config.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG);
@@ -160,6 +159,32 @@
prepareMessageReceiver();
} // ________________________________
+ protected void resolveComposerClass() throws Exception
+ {
+ // Look for first "action" element - only first one will be used
+ String tagName = ListenerTagNames.ACTION_ELEMENT_TAG;
+ ConfigTree actionElement = _config.getFirstChild(tagName);
+ String sProcessMethod = null;
+ if (null!=actionElement)
+ { // class attribute
+ _composerName = _controller.obtainAtt(actionElement,ListenerTagNames.ACTION_CLASS_TAG,null);
+ _composerClass = Class.forName(_composerName);
+ Constructor oConst = _composerClass.getConstructor(new Class[] {ConfigTree.class});
+ _composer= oConst.newInstance(_config);
+ tagName = ListenerTagNames.PROCESS_METHOD_TAG;
+ sProcessMethod = _controller.obtainAtt(_config,tagName,tagName);
+ }
+ else
+ {
+ _composerName = PackageJmsMessageContents.class.getName();
+ _composerClass= PackageJmsMessageContents.class;
+ _composer = new PackageJmsMessageContents();
+ sProcessMethod = "process";
+ }
+
+ _processMethod = _composerClass.getMethod(sProcessMethod,new Class[] {Object.class});
+ } //________________________________
+
private void prepareMessageReceiver() throws Exception
{
_queueConnection = null;
@@ -217,6 +242,54 @@
return null;
} //________________________________
+/**
+ * Default gateway action for plain jms messages
+ * <p/>It will just drop the jms message contents into a esb Message
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ *
+ */
+ private static class PackageJmsMessageContents
+ {
+ public Message process (Object obj) throws Exception
+ {
+ if (! (obj instanceof javax.jms.Message))
+ throw new Exception ("Object must be instance of javax.jms.Message");
+ byte[] bytes = getMessageContent((javax.jms.Message)obj);
+ if (null==bytes)
+ return null;
+
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().setContents(getMessageContent((javax.jms.Message)obj));
+ return message;
+ }
+
+ private byte[] getMessageContent(javax.jms.Message jMess) throws Exception
+ {
+ if (jMess instanceof TextMessage)
+ return ((TextMessage)jMess).getText().getBytes();
+
+ if (jMess instanceof BytesMessage)
+ {
+ BytesMessage jBytes =(BytesMessage)jMess;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] ba = new byte[1000];
+ int iQread;
+ while (-1!= (iQread=jBytes.readBytes(ba)))
+ if (iQread > 0)
+ out.write(ba,0,iQread);
+ out.close();
+ return out.toByteArray();
+ }
+
+ if (jMess instanceof ObjectMessage)
+ return ((ObjectMessage)jMess).getObject().toString().getBytes();
+ _logger.warn("Message type "+jMess.getClass().getSimpleName()
+ +" not supported - Message is ignored");
+ return null;
+ }
+ } //____________________________________________________
+
protected final static Logger _logger = Logger.getLogger(JmsGatewayListener.class);
protected String _queueName;
@@ -229,7 +302,8 @@
protected GatewayListenerController _controller;
protected final long _sleepForRetries; // milliseconds
- protected String _serviceName,_targetServiceName;
+ protected String _serviceCategory ,_serviceName;
+ protected String _targetServiceCategory ,_targetServiceName;
protected EPR _myEpr ,_targetEpr;
protected String _composerName;
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,625 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners.gateway;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.sql.DataSource;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.helpers.persist.SimpleDataSource;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ *
+ * Polls an SQL table for rows that satisfy conditions defined in the xml runtime configuration
+ *
+ * <p/>When a row that matches conditions is retrieved, it's contents are packed into an ESB Message
+ * and
+ *
+ * <p/> The following fields are mandatory (see checkMyParms()):
+ * <br/>
+ * <br/>SQL table name
+ * <br/>list of fields to retrieve
+ * <br/>list of key fields to use in the update statement
+ * <br/>a field that will be used to mark a row as 'pending(p)', 'in process(w)', 'done(d)' or 'in error(e)'
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ *
+ */
+public class SqlTableGatewayListener implements Runnable
+{
+
+ public SqlTableGatewayListener(GatewayListenerController commandListener, ConfigTree config)
+ throws Exception
+ {
+ _config = config;
+ _controller = commandListener;
+ _sleepBetweenPolls = 10000; // milliseconds
+ checkMyParms();
+ } // __________________________________
+
+ public void run()
+ {
+ if (null!=_serviceName)
+ try { _controller.register(_config,_myEpr); }
+ catch (RegistryException e1)
+ { _logger.warn("unable to register service",e1); }
+
+ boolean bSleep = false;
+ while (_controller.continueLooping())
+ {
+ // only sleep in between - not the first time
+ if (bSleep)
+ { long lUntil = System.currentTimeMillis()+_sleepBetweenPolls;
+ while (System.currentTimeMillis() < lUntil)
+ {
+ try { Thread.sleep(1000); }
+ catch (InterruptedException e) { lUntil = 0; }
+ if (! _controller.continueLooping())
+ break;
+ }
+ }
+ else
+ bSleep = true;
+ if (! _controller.continueLooping())
+ break;
+
+ for (Map<String,Object> row : pollForCandidates())
+ {
+ _currentRow = row;
+ // Try to mark as 'in process' - if unsuccessful, somebody else got it first
+ if (! changeStatusToWorking())
+ continue;
+
+ Throwable thrown = null;
+ String text = null;
+ try
+ {
+ Object obj = _processMethod.invoke(_composer,new Object[] {_currentRow} );
+ if (null==obj)
+ {
+ _logger.warn("Action class method <"+_processMethod.getName()+"> returned a null object");
+ continue;
+ }
+ Message message = (Message)obj;
+ if(_composerClass.equals(PackageRowContents.class))
+ {
+ Properties props = message.getProperties();
+ props.setProperty(JDBCEpr.DRIVER_TAG ,_driver);
+ props.setProperty(JDBCEpr.URL_TAG ,_url);
+ props.setProperty(JDBCEpr.USERNAME_TAG ,_user);
+ props.setProperty(JDBCEpr.PASSWORD_TAG , _password);
+
+ }
+ _courier.deliver(message);
+ }
+
+ catch (InvocationTargetException e)
+ {
+ thrown = e;
+ text = "Problems invoking method <"+_processMethod.getName()+">";
+
+ }
+ catch (IllegalAccessException e)
+ {
+ thrown = e;
+ text = "Problems invoking method <"+_processMethod.getName()+">";
+ }
+ catch (ClassCastException e)
+ {
+ thrown = e;
+ text = "Action class method <"+_processMethod.getName()+"> returned a non Message object";
+ }
+ catch (CourierException e)
+ {
+ thrown = e;
+ text = "Courier <"+_courier.getClass().getName()+".deliver(Message) FAILED";
+ }
+
+ if (null==thrown)
+ {
+ if (_deleteAfterOK)
+ deleteCurrentRow();
+ else
+ changeStatusToDone();
+ }
+ else
+ {
+ thrown.printStackTrace();
+ _logger.error(text,thrown);
+ changeStatusToError();
+ }
+ }
+ }
+
+ if (null!=_serviceName)
+ try { _controller.unRegister(_serviceCategory, _serviceName,_myEpr); }
+ catch (RegistryException e1){ _logger.warn("unable to unRegister service",e1); }
+
+ if (null!=_dbConn)
+ _dbConn.release();
+ } // ________________________________
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ *
+ * @throws Exception -
+ * if mandatory atts are not right or actionClass not in
+ * classpath
+ */
+ protected void checkMyParms() throws Exception
+ {
+ // Third arg is null - Exception will be thrown if attribute is not found
+ _targetServiceCategory = _controller.obtainAtt(_config, ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
+ _targetServiceName = _controller.obtainAtt(_config, ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
+ _targetEpr = _controller.getEprByName(_targetServiceName);
+ if (null==_targetEpr)
+ throw new ConfigurationException("EPR <"+_targetServiceName+"> not found in registry");
+ _courier = CourierFactory.getCourier(_targetEpr);
+
+ // Polling interval
+ String sAux = _config.getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
+ if (! Util.isNullString(sAux))
+ try { _sleepBetweenPolls = 1000 * Long.parseLong(sAux); }
+ catch (NumberFormatException e)
+ { _logger.warn("Invalid poll latency - keeping default of "+(_sleepBetweenPolls/1000)); }
+
+ resolveComposerClass();
+
+ _driver = _controller.obtainAtt(_config, JDBCEpr.DRIVER_TAG , null);
+ _url = _controller.obtainAtt(_config, JDBCEpr.URL_TAG , null);
+ _user = _controller.obtainAtt(_config, JDBCEpr.USERNAME_TAG , null);
+ _password = _controller.obtainAtt(_config, JDBCEpr.PASSWORD_TAG , "");
+
+ _tableName = _controller.obtainAtt(_config, ListenerTagNames.SQL_TABLE_NAME_TAG,null);
+ if (Util.isNullString(_tableName))
+ throw new ConfigurationException("Empty or invalid table name");
+ _selectFields = _controller.obtainAtt(_config, ListenerTagNames.SQL_SELECT_FIELDS_TAG,null);
+ if (Util.isNullString(_selectFields))
+ throw new ConfigurationException("Empty or invalid list of select fields");
+ _keyFields = _controller.obtainAtt(_config, ListenerTagNames.SQL_KEY_FIELDS_TAG,null);
+ if (Util.isNullString(_keyFields))
+ throw new ConfigurationException("Empty or invalid list of key fields");
+ _inProcessField = _controller.obtainAtt(_config, ListenerTagNames.SQL_IN_PROCESS_FIELD_TAG,null);
+ if (Util.isNullString(_inProcessField))
+ throw new ConfigurationException("A valid inProcessField attribute must be specified");
+
+ _where = _controller.obtainAtt(_config, ListenerTagNames.SQL_WHERE_CONDITION_TAG,"");
+ _orderBy = _controller.obtainAtt(_config, ListenerTagNames.SQL_ORDER_BY_TAG,"");
+ _inProcessVals = _controller.obtainAtt(_config, ListenerTagNames.SQL_IN_PROCESS_VALUES_TAG,DEFAULT_IN_PROCESS_STATES);
+
+ _deleteAfterOK = Boolean.parseBoolean
+ (_controller.obtainAtt(_config,ListenerTagNames.SQL_POST_DEL_TAG,"false"));
+
+ if (_inProcessVals.length()<4)
+ throw new Exception("Parameter <"+ListenerTagNames.SQL_IN_PROCESS_VALUES_TAG
+ +"> must be at least 4 characters long (PWED)");
+
+ _columns = _selectFields.split(",");
+ if (_columns.length < 1)
+ throw new Exception("Empty list of select fields");
+
+ Set<String>colSet = new HashSet<String>(Arrays.asList(_columns));
+ _keys = _keyFields.split(",");
+ if (_keys.length < 1)
+ throw new Exception("Empty list of keyFields");
+ for(String currKey : _keys)
+ {
+ if (colSet.contains(currKey))
+ continue;
+ else
+ { StringBuilder sb = new StringBuilder()
+ .append("All key field names in the <").append(ListenerTagNames.SQL_KEY_FIELDS_TAG)
+ .append("> attribute must be in the ").append(ListenerTagNames.SQL_SELECT_FIELDS_TAG)
+ .append("list - '").append(currKey).append("' is not there");
+ ;
+ throw new ConfigurationException(sb.toString());
+ }
+ }
+ prepareStatements();
+ } //________________________________
+
+ protected void prepareStatements() throws ConfigurationException
+ {
+ try
+ {
+ _PSscan = getDbConn().prepareStatement(scanStatement());
+ _PSsel4U = getDbConn().prepareStatement(selectForUpdStatement());
+ _PSupdate = getDbConn().prepareStatement(updateStatement());
+ _PSdeleteRow= getDbConn().prepareStatement(deleteStatement());
+ return;
+ }
+ catch (Exception e)
+ {throw new ConfigurationException(e); }
+ } //________________________________
+
+
+ protected void resolveComposerClass() throws Exception
+ {
+ // Look for first "action" element - only first one will be used
+ String tagName = ListenerTagNames.ACTION_ELEMENT_TAG;
+ ConfigTree actionElement = _config.getFirstChild(tagName);
+ String sProcessMethod = null;
+ if (null!=actionElement)
+ { // class attribute
+ _composerName = _controller.obtainAtt(actionElement,ListenerTagNames.ACTION_CLASS_TAG,null);
+ _composerClass = Class.forName(_composerName);
+ Constructor oConst = _composerClass.getConstructor(new Class[] {ConfigTree.class});
+ _composer= oConst.newInstance(_config);
+ tagName = ListenerTagNames.PROCESS_METHOD_TAG;
+ sProcessMethod = _controller.obtainAtt(_config,tagName,tagName);
+ }
+ else
+ {
+ _composerName = PackageRowContents.class.getName();
+ _composerClass= PackageRowContents.class;
+ _composer = new PackageRowContents();
+ sProcessMethod = "process";
+ }
+
+ _processMethod = _composerClass.getMethod(sProcessMethod,new Class[] {Object.class});
+ } //________________________________
+
+ protected List<Map<String,Object>> pollForCandidates()
+ {
+ JdbcCleanConn oConn = null;
+ List<Map<String,Object>> oResults = new ArrayList<Map<String,Object>>();
+ try
+ {
+ oConn = getDbConn();
+ String sScan = scanStatement();
+
+ PreparedStatement PS = oConn.prepareStatement(sScan);
+ ResultSet RS = oConn.execQueryWait(PS,1);
+ while (RS.next())
+ {
+ Map<String,Object> row = new HashMap<String,Object>();
+ int iCurr = 0;
+
+ for (String sColName : _columns)
+ row.put(sColName,RS.getObject(++iCurr));
+
+ oResults.add(row);
+ }
+ }
+ catch (Exception e)
+ {
+ _logger.warn("Some triggers might not have been returned",e);
+ }
+ _logger.info("Returning " + oResults.size() + " rows.");
+ return oResults;
+ } //________________________________
+
+ /**
+ * Obtain a new database connection with parameter info
+ * @return A new connection
+ * @throws Exception - if problems are encountered
+ */
+ protected JdbcCleanConn getDbConn() throws Exception
+ {
+ if (null==_dbConn)
+ {
+ DataSource oDS = new SimpleDataSource (_driver,_url,_user, _password);
+ _dbConn = new JdbcCleanConn(oDS);
+ }
+ return _dbConn;
+ } //________________________________
+
+ /**
+ * Assemble the SQL statement to scan (poll) the table
+ * @return - The resulting SQL statement
+ */
+ protected String scanStatement()
+ {
+ StringBuilder sb = new StringBuilder ()
+ .append("select ").append(_selectFields)
+ .append(" from ") .append(_tableName);
+
+ boolean bWhere = ! Util.isNullString(_where);
+ if (bWhere)
+ sb.append(" where ").append(_where);
+ sb.append((bWhere) ? " and " : " where ");
+
+ String sLike = _inProcessVals.substring(0,1).toUpperCase();
+ sb.append(" upper(").append(_inProcessField)
+ .append(") like '").append(sLike).append("%'");
+
+ if (! Util.isNullString(_orderBy))
+ sb.append(" order by ").append(_orderBy);
+ return sb.toString();
+ } //________________________________
+
+ /**
+ * Assemble the SQL statement to update the field
+ * in the "inProcessField" parameter
+ *
+ * in the table row uniquely identified by the list of fields
+ * in the "keyFields" parameter
+ *
+ * @return - The resulting SQL statement
+ */
+ protected String updateStatement()
+ {
+ StringBuilder sb = new StringBuilder ()
+ .append("update ").append(_tableName)
+ .append(" set ") .append(_inProcessField).append(" = ? where ")
+ ;
+ int iCurr = 0;
+ for(String sCurr : _keys)
+ { if (iCurr++ > 0)
+ sb.append(" and ");
+ sb.append(sCurr).append(" = ?");
+ }
+ return sb.toString();
+ } //________________________________
+
+ /**
+ * Assemble the SQL "select for update" statement
+ * for the "inProcessField" parameter
+ *
+ * in the table row uniquely identified by the list of fields
+ * in the "keyFields" parameter
+ *
+ * @return - The resulting SQL statement
+ */
+ protected String selectForUpdStatement()
+ {
+ StringBuilder sb = new StringBuilder ()
+ .append("select ").append(_inProcessField)
+ .append(" from ") .append(_tableName)
+ .append(" where ")
+ ;
+ int iCurr = 0;
+ for(String sCurr : _keys)
+ { if (iCurr++ > 0)
+ sb.append(" and ");
+ sb.append(sCurr).append(" = ?");
+ }
+ return sb.append(" for update").toString();
+ } //________________________________
+
+ /**
+ * Assemble the SQL statement to delete the current row
+ * in the table row uniquely identified by the list of fields
+ * in the "keyFields" parameter
+ *
+ * @return - The resulting SQL statement
+ */
+ protected String deleteStatement()
+ {
+ StringBuilder sb = new StringBuilder ()
+ .append("delete from ").append(_tableName).append(" where ")
+ ;
+ int iCurr = 0;
+ for(String sCurr : _keys)
+ { if (iCurr++ > 0)
+ sb.append(" and ");
+ sb.append(sCurr).append(" = ?");
+ }
+ return sb.toString();
+ } //________________________________
+
+ /**
+ * Try to delete 'current row' from polled table
+ * @return true if row deletion was successful - false otherwise
+ */
+ protected boolean deleteCurrentRow()
+ {
+ try { getDbConn().rollback(); }
+ catch (Exception e)
+ {
+ _logger.error("Unable to get DB connection.", e);
+ throw new IllegalStateException("Unable to get DB connection.", e);
+ }
+
+ try
+ {
+ int iParm=1;
+ for (String sColName : _keys)
+ _PSdeleteRow.setObject (iParm++,_currentRow.get(sColName));
+
+ try
+ {
+ getDbConn().execUpdWait(_PSdeleteRow, 5);
+ getDbConn().commit();
+ return true;
+ }
+ catch(Exception e)
+ {
+ _logger.error("Delete row has failed. Rolling back!!", e);
+ }
+
+ try { getDbConn().rollback(); }
+ catch (Exception e)
+ {
+ _logger.error("Unable to rollback delete row", e);
+ }
+ }
+ catch (Exception e) { _logger.error("Unexpected exception.", e); }
+ return false;
+ } //________________________________
+
+ protected String getStatus(ROW_STATE p_oState)
+ {
+ int iPos = p_oState.ordinal();
+ return _inProcessVals.substring(iPos, ++iPos);
+ } //________________________________
+
+ protected boolean changeStatusToWorking()
+ {
+ return changeStatus(ROW_STATE.Pending, ROW_STATE.Working);
+ } //________________________________
+
+ protected boolean changeStatusToDone()
+ {
+ return changeStatus(ROW_STATE.Working, ROW_STATE.Done);
+ } //________________________________
+
+ protected boolean changeStatusToError()
+ {
+ return changeStatus(ROW_STATE.Working, ROW_STATE.Error);
+ } //________________________________
+
+ protected boolean changeStatus(ROW_STATE fromState, ROW_STATE toState)
+ {
+ try { getDbConn(); }
+ catch (Exception e)
+ {
+ _logger.error("Unable to get DB connection.", e);
+ throw new IllegalStateException("Unable to get DB connection.", e);
+ }
+
+ try
+ {
+ int iParm=1;
+ for (String sColName : _keys)
+ {
+ Object oVal = _currentRow.get(sColName);
+ _PSsel4U.setObject (iParm ,oVal);
+ // parameters are +1 in update statement
+ _PSupdate.setObject (++iParm,oVal);
+ }
+
+ try
+ {
+ ResultSet resultSet = getDbConn().execQueryWait(_PSsel4U, 5);
+
+ if (resultSet.next())
+ {
+ String sOldStatus = resultSet.getString(1).substring(0, 1);
+
+ if (sOldStatus.equalsIgnoreCase(getStatus(fromState)))
+ {
+ _PSupdate.setString(1, getStatus(toState));
+ getDbConn().execUpdWait(_PSupdate, 5);
+ getDbConn().commit();
+
+ if(_logger.isDebugEnabled())
+ _logger.debug("Successfully changed row state from " + fromState + " to " + toState + ".");
+
+ return true;
+ }
+ else
+ {
+ _logger.warn("Cannot change row state from " + fromState + " to " + toState + ". Row not in state " + fromState);
+ return false;
+ }
+ }
+ _logger.error("Row status change to " + toState + " has failed. Rolling back!!");
+ }
+ catch(Exception e)
+ {
+ _logger.error("Row status change to " + toState + " has failed. Rolling back!!", e);
+ }
+
+ try { getDbConn().rollback(); }
+ catch (Exception e)
+ {
+ _logger.error("Unable to rollback row status change to " + fromState.name(), e);
+ }
+ }
+ catch (Exception e) { _logger.error("Unexpected exception.", e); }
+
+ return false;
+ } //________________________________
+
+/**
+ * Default gateway action for SQL table rows
+ * <p/>It will just drop the result set contents into a Message
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ *
+ */
+ public static class PackageRowContents
+ {
+ public Message process (Object obj) throws Exception
+ {
+ if (! (obj instanceof Map))
+ throw new Exception ("Object must be instance of Map");
+
+ Message message = MessageFactory.getInstance().getMessage();
+ org.jboss.soa.esb.message.Properties props = message.getProperties();
+
+ props.setProperty(ListenerTagNames.SQL_ROW_DATA_TAG, obj);
+
+ return message;
+ }
+ } //____________________________________________________
+
+ protected final static Logger _logger = Logger.getLogger(SqlTableGatewayListener.class);
+
+ protected ConfigTree _config;
+ protected GatewayListenerController _controller;
+ protected long _sleepBetweenPolls; // milliseconds
+
+ protected String _serviceCategory, _serviceName;
+ protected String _targetServiceCategory ,_targetServiceName;
+ protected EPR _myEpr ,_targetEpr;
+
+ protected String _composerName;
+ protected Class _composerClass;
+ protected Object _composer;
+ protected Method _processMethod;
+
+ protected Courier _courier;
+
+ protected String _driver ,_url ,_user ,_password;
+ protected String _tableName ,_selectFields, _keyFields;
+ protected String _where ,_orderBy;
+ protected String _inProcessField ,_inProcessVals;
+ protected boolean _deleteAfterOK;
+
+ protected String[] _columns ,_keys;
+ protected PreparedStatement _PSscan ,_PSsel4U ,_PSupdate ,_PSdeleteRow;
+ protected JdbcCleanConn _dbConn;
+ protected Map<String,Object>_currentRow;
+
+ public static enum ROW_STATE {Pending ,Working ,Error ,Done };
+ public static final String DEFAULT_IN_PROCESS_STATES = "PWED";
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/AbstractListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/AbstractListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/AbstractListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,64 @@
+package org.jboss.soa.esb.listeners.message;
+
+import java.util.concurrent.ExecutorService;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Base class for listener implementations which will be responsible for implementing some sort of
+ * blocking receive whithin the run() method.
+ *
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ *
+ */
+public abstract class AbstractListener implements Runnable {
+
+ /* The logger for this class */
+ protected Logger logger = Logger.getLogger(AbstractListener.class);
+
+ /* The configuration to be used by this listener*/
+ protected ConfigTree _config = null;
+
+ /* The listener controller*/
+ protected EsbListenerController _controller = null;
+
+ /* The default number of thread in the action pipeline execution thread pool */
+ protected int m_iMaxThr = 1;
+
+ /* The maximum number of threads in the action processing thread pool */
+ protected int m_iUpperThreadLimit = 10; // just in case - override if you
+
+ /* The name of the attribute in the configuration containing the number of threads in the pool*/
+ public static final String PARM_MAX_THREADS = "maxThreads";
+
+ /* The thread pool executing the action processing pipeline*/
+ protected ExecutorService pipelineExecutorPool = null;
+
+ /**
+ * Constructor configuring this listener instance and thread pool executing the
+ * action processing pipeline.
+ *
+ * @param controller the EsbListenerController instance controlling this listener
+ * @param configTree the configuration for this listener instance
+ */
+ protected AbstractListener(EsbListenerController controller,
+ ConfigTree configTree) {
+ this._controller = controller;
+ this._config = configTree;
+
+ // The number of threads configured
+ String maxThreads = this._config.getAttribute(PARM_MAX_THREADS);
+ if (maxThreads != null) {
+ int iMax = Integer.parseInt(maxThreads);
+ this.m_iMaxThr = Math.min(iMax, m_iUpperThreadLimit);
+ if (this.logger.isInfoEnabled()){
+ this.logger.info("Action processing pipeline will be handled by " + m_iMaxThr + " threads.");
+ }
+ } else {
+ this.logger.warn("Attribute maxThreads has not been set. Action pipeline will be processed by only one thread");
+ }
+// this.pipelineExecutorPool = Executors.newFixedThreadPool(m_iMaxThr);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/AbstractPassiveListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/AbstractPassiveListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/AbstractPassiveListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,23 @@
+package org.jboss.soa.esb.listeners.message;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Base class to be implmented by listener implementations which use a channel implementation
+ * doing the listening stuff like periodically receiving on a queue.
+ *
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ *
+ */
+public abstract class AbstractPassiveListener extends AbstractListener{
+
+ protected AbstractPassiveListener(EsbListenerController controller, ConfigTree configTree) {
+ super(controller, configTree);
+ }
+
+ public void run() {
+ //nothing to be done here because channel implementation is taking care of
+ // blocking receive stuff
+ }
+
+}
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -1,14 +1,14 @@
package org.jboss.soa.esb.listeners.message;
-import java.lang.reflect.*;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import org.apache.log4j.Logger;
-
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.actions.ActionUtils;
-import org.jboss.soa.esb.helpers.ConfigTree;
/**
@@ -19,21 +19,22 @@
* @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
* @since Version 4.0
*/
-class ActionProcessingPipeline implements Runnable
+public class ActionProcessingPipeline implements Runnable
{
+ private boolean processingComplete = false;
/**
* public constructor
* @param message Message - The initial message to be run through the whole action
* class chain
*/
- public ActionProcessingPipeline(Message message)
+ public ActionProcessingPipeline(Message message, ConfigTree config)
throws ConfigurationException
{
- if (null==_message)
+ if (null==message)
throw new IllegalArgumentException("Message must be not null");
_message = message;
- _config = ActionUtils.getConfigTree(_message);
+ _config = config;
if (null==_config)
throw new IllegalArgumentException("Configuration needed for action classes");
_actionList = _config.getChildren(ListenerTagNames.ACTION_ELEMENT_TAG);
@@ -70,41 +71,42 @@
_currentIndex++;
String attrName = ListenerTagNames.ACTION_CLASS_TAG;
_currentAction = oCurr.getAttribute(attrName);
-
+ _currentClass = Class.forName(_currentAction);
+ Constructor oConst = _currentClass.getConstructor(new Class[] {ConfigTree.class});
+ _currentProcessor = oConst.newInstance(oCurr);
+
attrName = ListenerTagNames.PROCESS_METHOD_TAG;
- String sProcessMethod = obtainAttribute(oCurr,attrName,attrName);
+ String[] saMethodList = obtainAttribute(oCurr,attrName,attrName).split(",");
- _currentClass = Class.forName(_currentAction);
- Constructor oConst = _currentClass.getConstructor(new Class[] {ConfigTree.class});
- _currentProcessor = oConst.newInstance(_config);
- Method method = _currentClass.getMethod(sProcessMethod,new Class[] {Message.class});
-
- // The processing result of each action feeds into the processing of the next action...
- try
- {
- // copy currentObject in Message body to 'previous' currentObject
- ActionUtils.copyCurrentToPrevious(_message);
- Message next = (Message)method.invoke(_currentProcessor,new Object[] {_message} );
-
- actionClassFinishedOk(oCurr);
- if(next==null)
- {
- _logger.error(prematureTermination("returned <null> - Cannot continue"));
- return;
- }
- }
- catch (ClassCastException eCast)
- {
- // If action class returns non Message, log and abort chain
- _logger.error(prematureTermination("returned a non Message Object)"));
- return;
- }
- catch (Exception e)
- {
- // If action class threw exception, log and abort chain
- actionClassException(oCurr,e);
- return;
- }
+ for (String currMethod : saMethodList)
+ {
+ Method method = _currentClass.getMethod(currMethod,new Class[] {Message.class});
+
+ // The processing result of each action feeds into the processing of the next action...
+ try
+ {
+ Message next = (Message)method.invoke(_currentProcessor,new Object[] {_message} );
+ if(next==null)
+ {
+ _logger.warn(prematureTermination("returned <null> - Cannot continue"));
+ return;
+ }
+ _message = next;
+ }
+ catch (ClassCastException eCast)
+ {
+ // If action class returns non Message, log and abort chain
+ _logger.error(prematureTermination("returned a non Message Object)"));
+ return;
+ }
+ catch (InvocationTargetException e)
+ {
+ // If action class threw exception, log and abort chain
+ actionClassException(oCurr,_message,e.getCause());
+ return;
+ }
+ }
+ actionClassFinishedOk(oCurr,_message);
}
// notification of action chain end can be done with a no-operation action class
// with a proper ListenerPropertyNames.ACTION_NORMAL_COMPLETION_CALLBACK method
@@ -120,7 +122,10 @@
{ _logger.error(prematureTermination("method not found"),e); }
catch(IllegalAccessException e)
{ _logger.error(prematureTermination("unable to access method"),e); }
- catch (IllegalArgumentException e) {}
+ catch (IllegalArgumentException e) {
+ } finally {
+ processingComplete = true;
+ }
}
protected String prematureTermination(String s)
@@ -137,17 +142,17 @@
* If 'current' action step was configured with a 'exceptionMethod' attribute
* that method will be called with a single argument of type Exception
* @param tree ConfigTree - where to look for the exceptionMetod attribute
- * @param thr Exception - to be used in invocation to method (if found)
+ * @param thrown Exception - to be used in invocation to method (if found)
*/
- protected void actionClassException(ConfigTree tree, Exception thr)
+ protected void actionClassException(ConfigTree tree, Message msg, Throwable thrown)
{
- thr.printStackTrace();
+// thrown.printStackTrace();
String sMethod = obtainAttribute(tree,ListenerTagNames.EXCEPTION_METHOD_TAG,null);
if (null!=sMethod)
try
{
- Method method = _currentClass.getMethod(sMethod,new Class[] {Exception.class});
- method.invoke(_currentProcessor,new Object[] {thr} );
+ Method method = _currentClass.getMethod(sMethod,new Class[] {Message.class, Throwable.class});
+ method.invoke(_currentProcessor,new Object[] {msg, thrown} );
}
catch (NoSuchMethodException e) {_logger.error(e); }
catch (InvocationTargetException e) {_logger.error(e); }
@@ -159,14 +164,14 @@
* that method will be called with no arguments
* @param tree ConfigTree - where to look for the okMetod attribute
*/
- protected void actionClassFinishedOk(ConfigTree tree)
+ protected void actionClassFinishedOk(ConfigTree tree,Message msg)
{
String sMethod = obtainAttribute(tree,ListenerTagNames.NORMAL_COMPLETION_METHOD_TAG,null);
if (null!=sMethod)
try
{
- Method method = _currentClass.getMethod(sMethod,new Class[] {});
- method.invoke(_currentProcessor,new Object[] {} );
+ Method method = _currentClass.getMethod(sMethod,new Class[] {Message.class});
+ method.invoke(_currentProcessor,new Object[] {msg} );
}
catch (NoSuchMethodException e) {_logger.error(e); }
catch (InvocationTargetException e) {_logger.error(e); }
@@ -195,5 +200,12 @@
protected Object _currentProcessor;
protected Message _message;
protected ConfigTree _config;
- protected Logger _logger = Logger.getLogger(this.getClass());
+ protected Logger _logger = Logger.getLogger(this.getClass());
+
+ /**
+ * @return Returns the processingComplete.
+ */
+ public boolean isProcessingComplete() {
+ return processingComplete;
+ }
}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners.message;
+
+import java.net.URISyntaxException;
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerInitializationException;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.routing.MessageRouter;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouter;
+import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouterFactory;
+
+/**
+ * Esb Message aware Content Based Router JMS queue listener.
+ * <p/> Expects an Object message whose getObject() method returns an org.jboss.soa.esb.message.Message
+ * <br/>Clones the 'static' ConfigTree with which this listener was created, and stores the cloned tree
+ * inside the Message (to enable all actions in the chain to use the configuration)
+ * <br/>Instantiates and runs a new ActionProcessingPipeline on the received esb Message (augmented with
+ * ConfigTree) that will in turn instantiate and run all action classes in the chain
+ *
+ * @author <a href="mailto:kurt.stam at redhat.com">Kurt Stam</a>
+ * @since Version 4.0
+ */
+
+public class CbrJmsQueueListener extends JmsQueueListener
+{
+ private static transient Logger _logger = Logger.getLogger(CbrJmsQueueListener.class);
+
+ public CbrJmsQueueListener(EsbListenerController controller, ConfigTree config) throws ConfigurationException {
+ super(controller, config);
+ }
+
+ /**
+ * Loops until controlling process determines
+ * <br/>Waits for JMS Object messages containing ESB messages
+ * <br/>When one is received, instantiates an action processing pipeline to process it
+ * <br/>Pipeline is started in new Thread
+ */
+ public void run()
+ {
+ try {
+ ContentBasedRouter cbr =ContentBasedRouterFactory.getRouter();
+ String ruleSet=null;
+ String ruleLanguage=null;
+ if (_config.getFirstChild(ListenerTagNames.CBR_TAG)==null) {
+ _logger.error("Required child element " + ListenerTagNames.CBR_TAG + " not found in " + _config.getName() + ".");
+ throw new ListenerInitializationException("Required child element " + ListenerTagNames.CBR_TAG + " not found.");
+ } else {
+ ruleSet =_config.getFirstChild(ListenerTagNames.CBR_TAG).getAttribute(ListenerTagNames.RULE_SET_TAG);
+ if (ruleSet==null) {
+ throw new ListenerInitializationException("Required attribute " + ListenerTagNames.RULE_SET_TAG + " not found.");
+ }
+ ruleLanguage =_config.getFirstChild(ListenerTagNames.CBR_TAG).getAttribute(ListenerTagNames.RULE_LANGUAGE_TAG);
+ }
+ _controller.register(_config,_epr);
+ while (_controller.continueLooping()) {
+ long lwait = _controller.millisToWait();
+ Message message = (lwait > 0 ) ? receiveEsbMessage(100) : null;
+ if (null!=message) {
+ _logger.log(Priority.DEBUG, "Sending message to the Content Based Router.");
+ Collection<String> destinationServices = cbr.route(ruleSet, ruleLanguage, message);
+ if (Boolean.FALSE.equals(message.getProperties().getProperty(MessageRouter.DELIVER_MESSAGES))) {
+ message.getProperties().setProperty(MessageRouter.ROUTING_DESTINATION_SERVICE_LIST, destinationServices);
+ try {
+ _logger.debug("Replying to caller");
+ //TODO For now it's ok to assume it's JMS. But going forward this needs to be fixed
+ if (message.getHeader().getCall()!=null && message.getHeader().getCall().getReplyTo()!=null) {
+ JMSEpr replyTo = new JMSEpr(message.getHeader().getCall().getReplyTo());
+ CourierFactory.getCourier(replyTo).deliver(message);
+ } else {
+ _logger.log(Priority.ERROR, "Unable to reply to caller. Could not optain replyTo EPR.");
+ }
+ } catch (URISyntaxException use) {
+ _logger.log(Priority.ERROR, "Unable to reply to caller. "+ use.getLocalizedMessage(), use);
+ } catch (CourierException ce) {
+ _logger.log(Priority.ERROR, "Unable to reply to caller. "+ ce.getLocalizedMessage(), ce);
+ }
+ }
+ }
+ }
+ _controller.unRegister(_eprCategoryName, _eprName, _epr);
+ } catch (ListenerInitializationException lie) {
+ _logger.log(Priority.FATAL, lie.getLocalizedMessage(), lie);
+ } catch (RegistryException re) {
+ _logger.log(Priority.FATAL, re.getLocalizedMessage(), re);
+ } catch (MessageRouterException mre) {
+ _logger.log(Priority.FATAL, mre.getLocalizedMessage(), mre);
+ } finally {
+ cleanup();
+ }
+ }
+}
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -32,14 +32,17 @@
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.command.CommandQueue;
import org.jboss.internal.soa.esb.command.CommandQueueException;
-import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.util.EPRManager;
-import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.common.Environment;
import org.jboss.soa.esb.common.ModulePropertyManager;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.parameters.ParamRepositoryException;
import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
import org.jboss.soa.esb.util.Util;
import org.xml.sax.SAXException;
@@ -165,7 +168,7 @@
* @throws Exception
* Unable to load/use the named configuration.
*/
- public EsbListenerController(String p_sParameterName) throws Exception {
+ public EsbListenerController(String p_sParameterName) throws Exception {
this(EsbListenerController.getListenerConfig(p_sParameterName));
m_sParmsName = p_sParameterName;
}
@@ -213,7 +216,7 @@
* Unable to parse the configuration.
*/
private static ConfigTree getListenerConfig(String reposParam)
- throws IOException, ParamRepositoryException, SAXException {
+ throws IOException, ParamRepositoryException, SAXException {
String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
ConfigTree config = ConfigTree.fromXml(sXml);
@@ -258,12 +261,7 @@
String sEndT = p_oP.getAttribute(PARM_END_TIME);
m_lEndTime = (null == sEndT) ? Long.MAX_VALUE : s_oDateParse.parse(
sEndT).getTime();
-
- // Read and initialise the action definitions...
- ConfigTree actionConfig = p_oP.getFirstChild("Actions");
- if(actionConfig == null) {
- throw new ConfigurationException("No 'Actions' configuration.");
- }
+
} // ________________________________
/**
@@ -342,7 +340,8 @@
// Close the command queue...
try {
- commandQueue.close();
+ if (null != commandQueue)
+ commandQueue.close();
} catch (CommandQueueException e) {
_logger.error("Error closing Command Queue.", e);
}
@@ -374,8 +373,8 @@
// No command queue nor topic - Just sleep until time
// exhausted, or thread interrupted
try {
- if (lToGo > 0)
- Thread.sleep(lToGo);
+ while ((lToGo=millisToWait()) > 0)
+ Thread.sleep(500);
} catch (InterruptedException e) {
m_lEndTime = 0; // mark as end requested and return
}
@@ -466,6 +465,11 @@
}
} // ________________________________
+ public void requestEnd() {
+ m_bEndRequested=true;
+ m_lEndTime = 0;
+ }
+
/**
* Accessor to determine if execution time is expired or shutdown requested
*
@@ -512,13 +516,18 @@
return (endNotRequested() && !timeToReload());
} // ________________________________
- private static EPRManager getEprManager()
+ public static EPRManager getEprManager()
{
PropertyManager manager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE);
String sDir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR,".");
return EPRManager.getInstance(sDir);
}
+ /**
+ * @deprecated use register (ConfigTree config, EPR address) instead.
+ * @param name
+ * @param address
+ */
public void register (String name, EPR address)
{
try { getEprManager().saveEPR(name,address); }
@@ -527,7 +536,10 @@
_logger.fatal("Cannot register service",e);
}
} // ________________________________
-
+ /**
+ * @deprecated use unRegister (String serviceCategoryName, String serviceName, EPR epr) instead.
+ * @param name
+ */
public void unRegister (String name)
{
try { getEprManager().removeEPR(name); }
@@ -536,5 +548,46 @@
_logger.fatal("Cannot un-register service",e);
}
} // ________________________________
+ /**
+ * Register an EPR in the registry.
+ *
+ * @param config - a config tree containing the deployment-configuration of the service.
+ * @param epr - the epr (EndPoint Reference) of the service.
+ *
+ * @throws RegistryException
+ */
+ public void register(ConfigTree config , EPR epr) throws RegistryException
+ {
+ String serviceCategoryName = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+ String serviceName = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ if ("eprManager".equalsIgnoreCase(serviceCategoryName))
+ {
+ register(serviceName,epr);
+ return;
+ }
+ String serviceDescription = config.getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
+ String eprDescription = config.getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG);
+ Registry registry = RegistryFactory.getRegistry();
+ registry.registerEPR(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription);
+ }
+ /**
+ * Unregister the EPR from the registry.
+ *
+ * @param serviceCategoryName - name of the category of the service ('Content Based Routing')
+ * @param serviceName - name of the service ("
+ * @param epr
+ * @throws RegistryException
+ */
+ public void unRegister(String serviceCategoryName, String serviceName , EPR epr) throws RegistryException
+ {
+ if ("eprManager".equalsIgnoreCase(serviceCategoryName))
+ {
+ unRegister(serviceName);
+ return;
+ }
+ Registry registry = RegistryFactory.getRegistry();
+ registry.unRegisterEPR(serviceCategoryName, serviceName, epr);
+ }
+
} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/HttpListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/HttpListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/HttpListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,251 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message;
+
+import java.net.MalformedURLException;
+
+import javax.management.MBeanServer;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerInitializationException;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Http listener implementation using the JBoss Remoting channel.
+ *
+ * The listener will listen to messages on the configured listenHttpUrl. If this
+ * is not set, the default http://localhost:5400 will be used.
+ *
+ * This listener expects an Object message whose type is org.jboss.soa.esb.message.Message
+ *
+ * Sample listener Configuration:
+ *
+ * <HttpListener listenerClass="org.jboss.soa.esb.listeners.message.HttpListener"/>
+ *
+ * <pre>
+ * <HttpListener listenerClass="org.jboss.soa.esb.listeners.message.HttpListener">
+ * <action class=&quotorg.jboss.soa.esb.actions.routing.EchoRouter"/>
+ * </HttpListener>
+ * </pre>
+ *
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ *
+ */
+public class HttpListener extends AbstractPassiveListener implements
+ ServerInvocationHandler {
+
+ /* The logger for this class */
+ protected Logger logger = Logger.getLogger(HttpListener.class);
+
+ /* Boolean indicating whether the info logging level is enabled */
+ protected boolean info = this.logger.isInfoEnabled();
+
+ /* The url this listener will listen on */
+ private static final String LISTEN_HTTP_URL = "listenHttpUrl";
+
+ /* The url to listen on */
+ public String listenHttpUrl = null;
+
+ /* The default transport this listener will listen on */
+ private static final String transport = "http";
+
+ /* The default hostname this listener will listen on */
+ private static final String host = "localhost";
+
+ /* The default port this listener will listen on */
+ private static final int port = 5400;
+
+ /**
+ * Constructor initialising this HttpListener
+ *
+ * @param commandListener
+ * @param listenerConfig
+ * @param actionDefinitionFactory
+ * @throws Exception
+ */
+ public HttpListener(EsbListenerController esbListenerController,
+ ConfigTree configuration) throws ConfigurationException,
+ ListenerInitializationException {
+ super(esbListenerController, configuration);
+
+ this.checkParams();
+ this.initServer();
+
+ }
+
+ /*
+ * Method being invoked when a request comes in.
+ *
+ * (non-Javadoc)
+ *
+ * @see org.jboss.remoting.ServerInvocationHandler#invoke(org.jboss.remoting.InvocationRequest)
+ */
+ @SuppressWarnings("unchecked")
+ public Object invoke(InvocationRequest invocationRequest) throws Throwable {
+ // Retrieving the real payload of this invocationRequest
+ Object payload = invocationRequest.getParameter();
+
+ if (this.logger.isInfoEnabled()) {
+ this.logger
+ .info("HttpInvocationListener is invoked...The given payload is : "
+ + payload);
+ }
+ if (payload instanceof Message){
+ // Start the action processing pipeline
+ ActionProcessingPipeline pipelineRunner = new ActionProcessingPipeline(
+ (Message)payload, this._config);
+ this.pipelineExecutorPool.submit(pipelineRunner);
+ } else {
+ this.logger.error("Unsupported HttpListener message type: " + payload.getClass().getName());
+ }
+
+ return payload;
+ }
+ /**
+ * Adds a callback handler that will listen for callbacks from the server
+ * invoker handler.
+ *
+ * @param callbackHandler
+ */
+ public void addListener(InvokerCallbackHandler callbackHandler) {
+ // NO OP as do not handling callback listeners in this example
+ }
+
+ /**
+ * Removes the callback handler that was listening for callbacks from the
+ * server invoker handler.
+ *
+ * @param callbackHandler
+ */
+ public void removeListener(InvokerCallbackHandler callbackHandler) {
+ // NO OP as do not handling callback listeners in this example
+ }
+
+ /**
+ * set the mbean server that the handler can reference
+ *
+ * @param server
+ */
+ public void setMBeanServer(MBeanServer server) {
+ // NO OP as do not need reference to MBeanServer for this handler
+ }
+
+ /**
+ * set the invoker that owns this handler
+ *
+ * @param invoker
+ */
+ public void setInvoker(ServerInvoker invoker) {
+ // NO OP as do not need reference back to the server invoker
+ }
+
+ /**
+ * Method getting the url this HttpListener instance is listening on
+ *
+ * @return the current listenHttpUrl
+ */
+ public String getListenHttpUrl() {
+ return listenHttpUrl;
+ }
+
+ /**
+ * Method setting the listenHttpUrl property to listen on
+ *
+ * @param listenHttpUrl
+ * the listenHttpUrl to be used by this HttpListener instance
+ */
+ public void setListenHttpUrl(String listenHttpUrl) {
+ this.listenHttpUrl = listenHttpUrl;
+ }
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ */
+ private void checkParams() throws ConfigurationException {
+ // listener url
+ this.listenHttpUrl = this._config.getAttribute(LISTEN_HTTP_URL);
+ if (this.listenHttpUrl == null) {
+ this.listenHttpUrl = this.getDefaultListenHttpUrl();
+ if (this.logger.isInfoEnabled()){
+ this.logger
+ .info("Attribute listenHttpUrl has not been set on the HttpListener. Using default "
+ + this.getDefaultListenHttpUrl());
+ }
+ }
+ }
+
+ /**
+ * Method returning the default listenHttpUrl for this HttpListener instance
+ *
+ * @return the default listen url
+ */
+ private String getDefaultListenHttpUrl() {
+ return HttpListener.transport + "://" + HttpListener.host + ":"
+ + HttpListener.port;
+ }
+
+ /**
+ * Method initialising the remoting deamon
+ *
+ * @throws ListenerInitialisationException
+ *
+ * @throws Exception
+ * when something goes wrong during remoting deamon startup
+ */
+ private void initServer() throws ListenerInitializationException {
+
+ try {
+ InvokerLocator locator = new InvokerLocator(this.listenHttpUrl);
+ if (this.logger.isInfoEnabled()) {
+ this.logger
+ .info("Starting remoting server with locator uri of: "
+ + this.listenHttpUrl);
+ }
+ Connector connector = new Connector(locator);
+ connector.create();
+
+ connector.addInvocationHandler("HttpInvocationHandler", this);
+
+ // Starting the server deamon
+ connector.start();
+
+ if (this.logger.isInfoEnabled()) {
+ this.logger.info("HttpListener deamon started successfully!");
+ }
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception exc) {
+ throw new ListenerInitializationException(exc.getMessage(), exc);
+ }
+
+ }
+
+}
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -22,6 +22,9 @@
package org.jboss.soa.esb.listeners.message;
+import java.io.IOException;
+import java.io.Serializable;
+
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.ObjectMessage;
@@ -31,15 +34,17 @@
import javax.jms.QueueSession;
import javax.jms.TopicSession;
import javax.naming.Context;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
-
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.helpers.AppServerContext;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
-import org.jboss.soa.esb.actions.ActionUtils;
-import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.Util;
+import org.xml.sax.SAXException;
/**
* Esb Message aware JMS queue listener.
@@ -53,7 +58,7 @@
* @since Version 4.0
*/
-public class JmsQueueListener implements Runnable
+public class JmsQueueListener extends AbstractListener
{
/**
* public constructor
@@ -64,8 +69,7 @@
public JmsQueueListener(EsbListenerController controller, ConfigTree config)
throws ConfigurationException
{
- _controller = controller;
- _config = config;
+ super(controller, config);
_iSleepForRetry = 3;
checkMyParms();
} // _______________________________
@@ -78,29 +82,33 @@
*/
public void run()
{
- _controller.register(_eprName,_epr);
-
- while (_controller.continueLooping())
- {
- org.jboss.soa.esb.message.Message message = receiveEsbMessage(_controller.millisToWait());
- if (null!=message)
- {
- ActionUtils.setConfigTree(message,_config);
- ActionProcessingPipeline chain = null;
-
- try { chain = new ActionProcessingPipeline(message); }
- catch (IllegalArgumentException e)
- { _logger.error(e); continue; }
- catch (ConfigurationException e)
- { _logger.error(e); continue; }
-
- // TODO Take care of thread pooling and (eventually) maximum child threads
- new Thread(chain).start();
- }
- }
-
- _controller.unRegister(_eprName);
- cleanup();
+ try {
+ _controller.register(_config,_epr);
+
+ while (_controller.continueLooping())
+ {
+ long lwait = _controller.millisToWait();
+ org.jboss.soa.esb.message.Message message = (lwait > 0 ) ? receiveEsbMessage(100) : null;
+ if (null!=message)
+ {
+ ActionProcessingPipeline chain = null;
+
+ try { chain = new ActionProcessingPipeline(message,_config); }
+ catch (IllegalArgumentException e)
+ { _logger.error(e); continue; }
+ catch (ConfigurationException e)
+ { _logger.error(e); continue; }
+
+// this.pipelineExecutorPool.submit(chain);
+ new Thread(chain).start();
+ }
+ }
+ _controller.unRegister(_eprCategoryName, _eprName, _epr);
+ } catch (RegistryException re) {
+ _logger.fatal("Could not register myself. " + re.getLocalizedMessage(),re);
+ } finally {
+ cleanup();
+ }
} // _______________________________
/**
@@ -113,8 +121,9 @@
protected void checkMyParms() throws ConfigurationException
{
// Default value of obtainAttribute is null - Exception will be thrown
- String sQueue = obtainAttribute(JMSEpr.DESTINATION_NAME_TAG, null);
+ _queueName = obtainAttribute(JMSEpr.DESTINATION_NAME_TAG, null);
+ _eprCategoryName= obtainAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG,null);
_eprName = obtainAttribute(ListenerTagNames.SERVICE_NAME_TAG,null);
// No problem if selector is null - everything in queue will be returned
@@ -124,25 +133,26 @@
_oQsess = null;
_oQueue = null;
- String sJndiType = obtainAttribute (JMSEpr.JNDI_TYPE_TAG ,"jboss");
- String sJndiURL = obtainAttribute (JMSEpr.JNDI_URL_TAG ,"localhost");
- Context oJndiCtx = AppServerContext.getServerContext(sJndiType,sJndiURL);
+ _jndiType = obtainAttribute (JMSEpr.JNDI_TYPE_TAG ,"jboss");
+ _jndiURL = obtainAttribute (JMSEpr.JNDI_URL_TAG ,"localhost");
+ _jndiCtx = AppServerContext.getServerContext(_jndiType,_jndiURL);
- String sFactClass = obtainAttribute(JMSEpr.CONNECTION_FACTORY_TAG, "ConnectionFactory");
- _epr = new JMSEpr(JMSEpr.QUEUE_TYPE,sQueue,sFactClass
- ,sJndiType,sJndiURL,_sSelector);
+ _jmsFactoryClass = obtainAttribute(JMSEpr.CONNECTION_FACTORY_TAG, "ConnectionFactory");
+ _epr = new JMSEpr(JMSEpr.QUEUE_TYPE,_queueName,_jmsFactoryClass
+ ,_jndiType,_jndiURL,_sSelector);
Exception thrown = null;
try
{
- Object tmp = oJndiCtx.lookup(sFactClass);
+ Object tmp = _jndiCtx.lookup(_jmsFactoryClass);
QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
_oQconn = qcf.createQueueConnection();
- _oQueue = (Queue) oJndiCtx.lookup(sQueue);
+ _oQueue = (Queue) _jndiCtx.lookup(_queueName);
_oQsess = _oQconn.createQueueSession(false,TopicSession.AUTO_ACKNOWLEDGE);
_oQconn.start();
_receiver = _oQsess.createReceiver(_oQueue, _sSelector);
+ return;
}
catch (javax.naming.NamingException e) { thrown = e; }
catch (JMSException e) { thrown = e; }
@@ -153,7 +163,10 @@
protected org.jboss.soa.esb.message.Message receiveEsbMessage(long millis)
{
javax.jms.Message jmsMessage = null;
- try { jmsMessage = _receiver.receive(millis); }
+ try
+ {
+ jmsMessage = _receiver.receive(millis);
+ }
catch (JMSException oJ)
{
_logger.error("JMS error on receive. Attempting JMS Destination reconnect.", oJ);
@@ -181,7 +194,8 @@
}
try
{
- return (org.jboss.soa.esb.message.Message)((ObjectMessage)jmsMessage).getObject();
+ Serializable obj = (Serializable)((ObjectMessage)jmsMessage).getObject();
+ return Util.deserialize(obj);
}
catch (JMSException e1)
{ _logger.error("Failed to read Serialized Object from JMS message.", e1);
@@ -190,6 +204,15 @@
catch (ClassCastException e2)
{ _logger.error("Object in JMS message is not a org.jboss.soa.esb.message.Message", e2);
}
+ catch (IOException e3)
+ { _logger.error("Object in JMS message is not a Serializeable", e3);
+ }
+ catch (ParserConfigurationException e4)
+ { _logger.error("Object in JMS message has invalid XML", e4);
+ }
+ catch (SAXException e5)
+ { _logger.error("Object in JMS message has invalid XML", e5);
+ }
return null;
}
@@ -210,6 +233,7 @@
protected String obtainAttribute(String p_sAtt, String p_sDefault)
throws ConfigurationException
{
+ _logger.info("Reading value for " + p_sAtt);
String sVal = _config.getAttribute(p_sAtt);
if ((null == sVal) && (null == p_sDefault))
throw new ConfigurationException("Missing or invalid <" + p_sAtt + "> attribute");
@@ -217,8 +241,7 @@
return (null != sVal) ? sVal : p_sDefault;
} // ________________________________
- protected EsbListenerController _controller;
- protected ConfigTree _config;
+ protected String _eprCategoryName;
protected String _eprName;
protected JMSEpr _epr;
protected MessageConsumer _receiver;
@@ -226,7 +249,13 @@
protected QueueConnection _oQconn;
protected QueueSession _oQsess;
protected Queue _oQueue;
- protected String _sSelector;
+ protected String _queueName
+ ,_sSelector
+ ,_jndiType
+ ,_jndiURL
+ ,_jmsFactoryClass
+ ;
+ protected Context _jndiCtx;
protected int _iSleepForRetry;
protected static transient Logger _logger = Logger.getLogger(JmsQueueListener.class);
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -182,7 +182,7 @@
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
* @since Version 4.0
*/
- private class ActionProcessingPipeline implements Runnable {
+ protected class ActionProcessingPipeline implements Runnable {
private Object initialObject;
@@ -190,7 +190,7 @@
* Private constructor.
* @param pMessage The inital processing target message.
*/
- private ActionProcessingPipeline(Object obj) {
+ protected ActionProcessingPipeline(Object obj) {
initialObject = obj;
}
@@ -290,4 +290,4 @@
}
}
-} // ____________________________________________________________________________
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractPassiveListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractPassiveListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractPassiveListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,28 @@
+package org.jboss.soa.esb.listeners.old;
+
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Base class to be implmented by listener implementations which use a channel
+ * implementation doing the listening stuff like periodically receiving on a
+ * queue.
+ *
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ *
+ */
+public abstract class AbstractPassiveListener extends AbstractListener {
+
+ protected AbstractPassiveListener(GpListener p_oDad, ConfigTree p_oParms,
+ ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+ super(p_oDad, p_oParms, actionDefinitionFactory);
+ }
+
+ @Override
+ protected Object[] receive() {
+ // nothing to be done here because channel implementation is taking care
+ // of blocking receive stuff
+ return null;
+ }
+
+}
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/DirectoryPoller.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/DirectoryPoller.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/DirectoryPoller.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -32,19 +32,11 @@
import org.jboss.soa.esb.actions.ActionDefinitionFactory;
import org.jboss.soa.esb.actions.ActionProcessor;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.util.Util;
public class DirectoryPoller extends AbstractPoller
{
- public static final String FILE_INPUT_DIR = "inputDirURI";
- public static final String FILE_INPUT_SFX = "inputSuffix";
- public static final String FILE_WORK_SFX = "workSuffix";
- public static final String FILE_ERROR_DIR = "errorDirURI";
- public static final String FILE_ERROR_SFX = "errorSuffix";
- public static final String FILE_POST_DIR = "postDirURI";
- public static final String FILE_POST_SFX = "postSuffix";
- public static final String FILE_POST_DEL = "postDelete";
-
public DirectoryPoller(GpListener p_oDad, ConfigTree p_oParms, ActionDefinitionFactory actionDefinitionFactory) throws Exception
{
super(p_oDad, p_oParms, actionDefinitionFactory);
@@ -97,49 +89,49 @@
private void checkMyParms() throws Exception
{
// INPUT directory and suffix (used for FileFilter)
- String sInpDir = GpListener.obtainAtt(listenerConfig,FILE_INPUT_DIR,null);
+ String sInpDir = GpListener.obtainAtt(listenerConfig,ListenerTagNames.FILE_INPUT_DIR_TAG,null);
m_oInpDir = getFile(sInpDir);
seeIfOkToWorkOnDir(m_oInpDir);
- m_sInpSfx = GpListener.obtainAtt(listenerConfig,FILE_INPUT_SFX,null);
+ m_sInpSfx = GpListener.obtainAtt(listenerConfig,ListenerTagNames.FILE_INPUT_SFX_TAG,null);
m_sInpSfx = m_sInpSfx.trim();
if (m_sInpSfx.length()<1)
- throw new Exception ("Invalid "+FILE_INPUT_SFX+" attribute");
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_INPUT_SFX_TAG+" attribute");
m_oFFilt = new FileEndsWith(m_sInpSfx);
// WORK suffix (will rename in input directory)
- m_sWrkSfx = GpListener.obtainAtt(listenerConfig,FILE_WORK_SFX,".esbWork").trim();
+ m_sWrkSfx = GpListener.obtainAtt(listenerConfig,ListenerTagNames.FILE_WORK_SFX_TAG,".esbWork").trim();
if (m_sWrkSfx.length()<1)
- throw new Exception ("Invalid "+FILE_WORK_SFX+" attribute");
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_WORK_SFX_TAG+" attribute");
if (m_sInpSfx.equals(m_sWrkSfx))
throw new Exception("Work suffix must differ from input suffix <"+m_sWrkSfx+">");
// ERROR directory and suffix (defaults to input dir and ".esbError" suffix)
- String sErrDir = GpListener.obtainAtt(listenerConfig,FILE_ERROR_DIR,sInpDir);
+ String sErrDir = GpListener.obtainAtt(listenerConfig,ListenerTagNames.FILE_ERROR_DIR_TAG,sInpDir);
m_oErrorDir = getFile(sErrDir);
seeIfOkToWorkOnDir(m_oErrorDir);
- m_sErrSfx = GpListener.obtainAtt(listenerConfig,FILE_ERROR_SFX,".esbError").trim();
+ m_sErrSfx = GpListener.obtainAtt(listenerConfig,ListenerTagNames.FILE_ERROR_SFX_TAG,".esbError").trim();
if (m_sErrSfx.length()<1)
- throw new Exception ("Invalid "+FILE_ERROR_SFX+" attribute");
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_ERROR_SFX_TAG+" attribute");
if (m_oErrorDir.equals(m_oInpDir) && m_sInpSfx.equals(m_sErrSfx))
throw new Exception("Error suffix must differ from input suffix <"+m_sErrSfx+">");
// Do users wish to delete files that were processed OK ?
- String sPostDel = GpListener.obtainAtt(listenerConfig,FILE_POST_DEL,"false").trim();
+ String sPostDel = GpListener.obtainAtt(listenerConfig,ListenerTagNames.FILE_POST_DEL_TAG,"false").trim();
m_bPostDel = Boolean.parseBoolean(sPostDel);
if (m_bPostDel)
return;
// POST (done) directory and suffix (defaults to input dir and ".esbDone" suffix)
- String sPostDir = GpListener.obtainAtt(listenerConfig,FILE_POST_DIR,sInpDir);
+ String sPostDir = GpListener.obtainAtt(listenerConfig,ListenerTagNames.FILE_POST_DIR_TAG,sInpDir);
m_oPostDir = getFile(sPostDir);
seeIfOkToWorkOnDir(m_oPostDir);
- m_sPostSfx = GpListener.obtainAtt(listenerConfig,FILE_POST_SFX,".esbDone").trim();
+ m_sPostSfx = GpListener.obtainAtt(listenerConfig,ListenerTagNames.FILE_POST_SFX_TAG,".esbDone").trim();
if (m_oPostDir.equals(m_oInpDir))
{ if (m_sPostSfx.length()<1)
- throw new Exception ("Invalid "+FILE_POST_SFX+" attribute");
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_POST_SFX_TAG+" attribute");
if (m_sPostSfx.equals(m_sInpSfx))
throw new Exception("Post process suffix must differ from input suffix <"+m_sPostSfx+">");
}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/HttpListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/HttpListener.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/HttpListener.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,143 @@
+package org.jboss.soa.esb.listeners.old;
+
+import javax.management.MBeanServer;
+
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ *
+ *
+ * @author Johan Kumps
+ *
+ */
+public class HttpListener extends AbstractPassiveListener implements ServerInvocationHandler{
+
+ /* The url to listen on */
+ public String listenHttpUrl = null;
+
+ /* The url this listener will listen on */
+ private static final String LISTEN_HTTP_URL = "listenHttpURL";
+
+ /* The default transport this listener will listen on */
+ private static final String transport = "http";
+
+ /* The default hostname this listener will listen on */
+ private static final String host = "localhost";
+
+ /* The default port this listener will listen on */
+ private static final int port = 5400;
+
+ public HttpListener(GpListener p_oDad, ConfigTree p_oParms, ActionDefinitionFactory actionDefinitionFactory) throws Exception
+ {
+ super(p_oDad, p_oParms, actionDefinitionFactory);
+ this.listenHttpUrl = GpListener.obtainAtt(p_oParms,LISTEN_HTTP_URL, this.getDefaultListenHttpUrl());
+ // initialize the HTTP server
+ this.initServer();
+ }
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ *
+ * @throws Exception -
+ * if actionClass not specified or not in classpath or invalid
+ * int values for maxThreads or pollLatencySecs
+ *
+ */
+ protected void checkParams() throws Exception {
+ // listener url
+ this.listenHttpUrl = GpListener.obtainAtt(this.listenerConfig, LISTEN_HTTP_URL,
+ this.getDefaultListenHttpUrl());
+ }
+
+ public Object invoke(InvocationRequest invocationRequest) throws Throwable {
+ //Retrieving the real payload of this invocationRequest
+ Object payload = invocationRequest.getParameter();
+
+ if (this.logger.isInfoEnabled()) {
+ this.logger
+ .info("HttpInvocationListener is invoked...The given payload is : "
+ + payload);
+ }
+ //Start the action processing pipeline
+ ActionProcessingPipeline pipelineRunner = new ActionProcessingPipeline(payload);
+ new Thread(pipelineRunner).start();
+
+ return payload;
+ }
+
+ /**
+ * Method returning the default listenHttpUrl for this HttpListener instance
+ *
+ * @return the default listen url
+ */
+ private String getDefaultListenHttpUrl() {
+ return HttpListener.transport + "://" + HttpListener.host + ":"
+ + HttpListener.port;
+ }
+
+ private void initServer() throws Exception {
+ InvokerLocator locator = new InvokerLocator(this.listenHttpUrl);
+ if (this.logger.isInfoEnabled()) {
+ this.logger.info("Starting remoting server with locator uri of: "
+ + this.listenHttpUrl);
+ }
+ Connector connector = new Connector(locator);
+ connector.create();
+ connector.addInvocationHandler("HttpInvocationHandler", this);
+
+ // Starting the server deamon
+ connector.start();
+
+ if (this.logger.isInfoEnabled()) {
+ this.logger.info("HttpListener deamon started successfully!");
+ }
+
+ }
+
+ @Override
+ protected void processingError(Object initialMsg, ActionProcessor processor, Throwable error) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void processingComplete(Object initialMsg) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void close() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setMBeanServer(MBeanServer arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setInvoker(ServerInvoker arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void addListener(InvokerCallbackHandler arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeListener(InvokerCallbackHandler arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/RemoteDirectoryPoller.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/RemoteDirectoryPoller.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/RemoteDirectoryPoller.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -32,20 +32,12 @@
import org.jboss.soa.esb.actions.ActionProcessor;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.util.FtpClientUtil;
import org.jboss.soa.esb.util.Util;
public class RemoteDirectoryPoller extends AbstractPoller
{
- public static final String FILE_INPUT_DIR = "inputDir";
- public static final String FILE_INPUT_SFX = "inputSuffix";
- public static final String FILE_WORK_SFX = "workSuffix";
- public static final String FILE_ERROR_DIR = "errorDir";
- public static final String FILE_ERROR_SFX = "errorSuffix";
- public static final String FILE_POST_DIR = "postDir";
- public static final String FILE_POST_SFX = "postSuffix";
- public static final String FILE_POST_DEL = "postDelete";
-
private ConfigTree _params;
private Logger _logger = Logger.getLogger(this.getClass());
FtpClientUtil _ftpClient;
@@ -131,45 +123,45 @@
protected void checkMyParms() throws Exception
{
// INPUT directory and suffix (used for FileFilter)
- String sInpDir = GpListener.obtainAtt(_params,FILE_INPUT_DIR,null);
+ String sInpDir = GpListener.obtainAtt(_params,ListenerTagNames.FILE_INPUT_DIR_TAG,null);
m_oInpDir = new File(sInpDir);
- m_sInpSfx = GpListener.obtainAtt(_params,FILE_INPUT_SFX,null);
+ m_sInpSfx = GpListener.obtainAtt(_params,ListenerTagNames.FILE_INPUT_SFX_TAG,null);
m_sInpSfx = m_sInpSfx.trim();
if (m_sInpSfx.length()<1)
- throw new Exception ("Invalid "+FILE_INPUT_SFX+" attribute");
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_INPUT_SFX_TAG+" attribute");
// WORK suffix (will rename in input directory)
- m_sWrkSfx = GpListener.obtainAtt(_params,FILE_WORK_SFX,".esbWork").trim();
+ m_sWrkSfx = GpListener.obtainAtt(_params,ListenerTagNames.FILE_WORK_SFX_TAG,".esbWork").trim();
if (m_sWrkSfx.length()<1)
- throw new Exception ("Invalid "+FILE_WORK_SFX+" attribute");
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_WORK_SFX_TAG+" attribute");
if (m_sInpSfx.equals(m_sWrkSfx))
throw new Exception("Work suffix must differ from input suffix <"+m_sWrkSfx+">");
// ERROR directory and suffix (defaults to input dir and ".esbError" suffix)
- String sErrDir = GpListener.obtainAtt(_params,FILE_ERROR_DIR,sInpDir);
+ String sErrDir = GpListener.obtainAtt(_params,ListenerTagNames.FILE_ERROR_DIR_TAG,sInpDir);
m_oErrorDir = new File(sErrDir);
- m_sErrSfx = GpListener.obtainAtt(_params,FILE_ERROR_SFX,".esbError").trim();
+ m_sErrSfx = GpListener.obtainAtt(_params,ListenerTagNames.FILE_ERROR_SFX_TAG,".esbError").trim();
if (m_sErrSfx.length()<1)
- throw new Exception ("Invalid "+FILE_ERROR_SFX+" attribute");
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_ERROR_SFX_TAG+" attribute");
if (m_oErrorDir.equals(m_oInpDir) && m_sInpSfx.equals(m_sErrSfx))
throw new Exception("Error suffix must differ from input suffix <"+m_sErrSfx+">");
// Do users wish to delete files that were processed OK ?
- String sPostDel = GpListener.obtainAtt(_params,FILE_POST_DEL,"false").trim();
+ String sPostDel = GpListener.obtainAtt(_params,ListenerTagNames.FILE_POST_DEL_TAG,"false").trim();
m_bPostDel = Boolean.parseBoolean(sPostDel);
if (m_bPostDel)
return;
// POST (done) directory and suffix (defaults to input dir and ".esbDone" suffix)
- String sPostDir = GpListener.obtainAtt(_params,FILE_POST_DIR,sInpDir);
+ String sPostDir = GpListener.obtainAtt(_params,ListenerTagNames.FILE_POST_DIR_TAG,sInpDir);
m_oPostDir = new File(sPostDir);
- m_sPostSfx = GpListener.obtainAtt(_params,FILE_POST_SFX,".esbDone").trim();
+ m_sPostSfx = GpListener.obtainAtt(_params,ListenerTagNames.FILE_POST_SFX_TAG,".esbDone").trim();
if (m_oPostDir.equals(m_oInpDir))
{ if (m_sPostSfx.length()<1)
- throw new Exception ("Invalid "+FILE_POST_SFX+" attribute");
+ throw new Exception ("Invalid "+ListenerTagNames.FILE_POST_SFX_TAG+" attribute");
if (m_sPostSfx.equals(m_sInpSfx))
throw new Exception("Post process suffix must differ from input suffix <"+m_sPostSfx+">");
}
@@ -232,7 +224,7 @@
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
* @since Version 4.0
*/
- public static class extends File
+ public static class WorkingFile extends File
{
private static final long serialVersionUID = 1L;
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions.converters;
+
+import java.net.URISyntaxException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+ * SmooksTransformer unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class SmooksTransformerUnitTest extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ SmooksTransformer.reset();
+ }
+
+ public void test_bad_config() {
+ ConfigTree properties = new ConfigTree("name");
+
+ // Should get exceptions where message type configs are specified but empty...
+ properties.setAttribute(SmooksTransformer.FROM_TYPE, " ");
+ assertConfigException(properties, "Empty '" + SmooksTransformer.FROM_TYPE + "' config attribute supplied.");
+ properties.setAttribute(SmooksTransformer.FROM_TYPE, "x");
+ properties.setAttribute(SmooksTransformer.TO_TYPE, " ");
+ assertConfigException(properties, "Empty '" + SmooksTransformer.TO_TYPE + "' config attribute supplied.");
+ }
+
+ public void test_trans() throws ActionProcessingException, ConfigurationException, URISyntaxException {
+ String stringMessage;
+ String transRes;
+
+ // Very basic test! Just illustrates profile based resource selection.
+ // Read the smooks-test.cdrl config file in this package!!
+
+ // Initialise the acme order message...
+ stringMessage = "<a><ddd>value</ddd></a>";
+
+ // Transform the order message going to "AcmePartner1"...
+ transRes = transform(stringMessage, "Acme-Order-XML", "Acme", "AcmePartner1", "Partner1-Order-XML");
+ assertEquals("<x><b>value</b></x>", transRes);
+
+ // Transform the order message going to "AcmePartner2"...
+ transRes = transform(stringMessage, "Acme-Order-XML", "Acme", "AcmePartner2", "Partner2-Order-XML");
+ assertEquals("<x><c>value</c></x>", transRes);
+ }
+
+ private String transform(String stringMessage, String fromType, String from, String to, String toType) throws ActionProcessingException, ConfigurationException, URISyntaxException {
+ Message oMsg = MessageFactory.getInstance().getMessage();
+ ConfigTree properties = new ConfigTree("name");
+
+ // Set the message properties in order to trigger the appropriate transformations
+ // on the message...
+ properties.setAttribute(SmooksTransformer.FROM_TYPE, fromType);
+ properties.setAttribute(SmooksTransformer.TO_TYPE, toType);
+
+ Call call = new Call();
+ EPR fromEPR = new EPR();
+ EPR toEPR = new EPR();
+ PortReference fromAddr = new PortReference();
+ PortReference toAddr = new PortReference();
+
+ oMsg.getHeader().setCall(call);
+
+ call.setFrom(fromEPR);
+ fromEPR.setAddr(fromAddr);
+ fromAddr.setAddress(from);
+
+ call.setTo(toEPR);
+ toEPR.setAddr(toAddr);
+ toAddr.setAddress(to);
+
+ // The smooks-cdr.lst and device-profile.xml files are located in the root of the
+ // test src folder. You need to look at these to see how this works...
+ SmooksTransformer transformer = new SmooksTransformer(properties);
+
+ ActionUtils.setTaskObject(oMsg, stringMessage);
+ oMsg = transformer.process(oMsg);
+
+ return (String) ActionUtils.getTaskObject(oMsg);
+ }
+
+ private void assertConfigException(ConfigTree properties, String expectedException) {
+ try {
+ new SmooksTransformer("trans", properties);
+ fail("Expected ConfigurationException: [" + expectedException + "...]");
+ } catch(ConfigurationException e) {
+ assertTrue("Expected exception message to start with [" + expectedException + "]. Was [" + e.getMessage() + "]", e.getMessage().startsWith(expectedException));
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/smooks-test.cdrl
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/smooks-test.cdrl 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/smooks-test.cdrl 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,28 @@
+<?xml version='1.0'?>
+<!DOCTYPE smooks-resource-list PUBLIC '-//MILYN//DTD SMOOKS 1.0//EN' 'http://milyn.org/dtd/smooksres-list-1.0.dtd'>
+
+<smooks-resource-list>
+
+ <!--
+ "Acme-Order-XML" messages going from "Acme" to "AcmePartner1"
+ -->
+ <smooks-resource useragent="from-type:Acme-Order-XML AND from-epr:Acme AND to-type:Partner1-Order-XML AND to-epr:AcmePartner1" selector="ddd" path="org.milyn.cdres.trans.RenameElementTU">
+ <param name="replacementElement">b</param>
+ </smooks-resource>
+
+ <!--
+ "Acme-Order-XML" messages going from "Acme" to "AcmePartner2"
+ -->
+ <smooks-resource useragent="from-type:Acme-Order-XML AND from-epr:Acme AND to-type:Partner2-Order-XML AND to-epr:AcmePartner2" selector="ddd" path="org.milyn.cdres.trans.RenameElementTU">
+ <param name="replacementElement">c</param>
+ </smooks-resource>
+
+ <!--
+ "Acme-Order-XML" messages going from "Acme" to anywhere
+ -->
+ <smooks-resource useragent="from-type:Acme-Order-XML AND from-epr:Acme" selector="a" path="org.milyn.cdres.trans.RenameElementTU">
+ <param name="replacementElement">x</param>
+ </smooks-resource>
+
+</smooks-resource-list>
+
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListenerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListenerUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListenerUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -21,20 +21,18 @@
package org.jboss.soa.esb.listeners.old;
+import junit.framework.TestCase;
+
import org.jboss.soa.esb.actions.ActionDefinition;
import org.jboss.soa.esb.actions.ActionDefinitionFactory;
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.actions.ActionUtils;
import org.jboss.soa.esb.actions.BaseTestActionProcessor;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.old.AbstractListener;
-import org.jboss.soa.esb.listeners.old.GpListener;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.util.MockNonblockingListener;
-import junit.framework.TestCase;
-
/**
* AbstractListener tests.
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/DirectoryPollerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/DirectoryPollerUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/DirectoryPollerUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -22,7 +22,6 @@
package org.jboss.soa.esb.listeners.old;
import org.jboss.soa.esb.common.tests.BaseTest;
-import org.jboss.soa.esb.listeners.old.DirectoryPoller;
/**
* Test the DirectoryPoller
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListenerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListenerUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListenerUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -27,7 +27,6 @@
import org.jboss.soa.esb.actions.ToNowhereRouter;
import org.jboss.soa.esb.common.tests.BaseTest;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.old.GpListener;
import org.jboss.soa.esb.util.ListenersManagerExecThread;
import org.jboss.soa.esb.util.MockPoller;
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -22,7 +22,6 @@
package org.jboss.soa.esb.listeners.old;
import org.jboss.soa.esb.common.tests.BaseTest;
-import org.jboss.soa.esb.listeners.old.SqlTablePoller;
/**
* Test the SqlTablePoller
Modified: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/smooks-cdr.lst
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/smooks-cdr.lst 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/smooks-cdr.lst 2006-11-13 21:42:31 UTC (rev 7573)
@@ -1 +1 @@
-/org/jboss/soa/esb/actions/smooks-test.cdrl
\ No newline at end of file
+classpath:/org/jboss/soa/esb/actions/converters/smooks-test.cdrl
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/build.xml 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/build.xml 2006-11-13 21:42:31 UTC (rev 7573)
@@ -71,6 +71,9 @@
includes="**/*.class"
excludes="test/**"
/>
+ <jar destfile="${org.jboss.esb.rosetta.distrib.dir}/lib/test-util.jar"
+ basedir="${org.jboss.esb.internal.dest}/tests/"
+ includes="org/jboss/soa/esb/testutils/**/*.class"/>
</target>
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -149,12 +149,14 @@
}
else
{
- Object value = MarshalUnmarshalManager.getInstance().unmarshal((Element) child.getFirstChild());
-
- if (value == null)
- throw new UnmarshalException("Cannot unpack object "+child.getNodeName());
- else
- _objects.put(child.getNodeName(), value);
+ Object value = child.getFirstChild();
+ if (value instanceof Element) {
+ value = MarshalUnmarshalManager.getInstance().unmarshal((Element) child.getFirstChild());
+ if (value == null)
+ throw new UnmarshalException("Cannot unpack object "+child.getNodeName());
+ else
+ _objects.put(child.getNodeName(), value);
+ }
}
}
}
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -21,7 +21,7 @@
* @author mark.little at jboss.com
*/
-import org.jboss.internal.soa.esb.addressing.CallHelper;
+import org.jboss.internal.soa.esb.addressing.helpers.CallHelper;
import org.jboss.soa.esb.addressing.Call;
import org.jboss.soa.esb.message.Header;
import org.w3c.dom.Document;
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -31,7 +31,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.jboss.internal.soa.esb.addressing.EPRHelper;
+import org.jboss.internal.soa.esb.addressing.helpers.EPRHelper;
import org.jboss.soa.esb.addressing.EPR;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -59,8 +59,8 @@
new KeyValuePair(Environment.MSG_STORE_DB_POOL_INITIAL_SIZE,getStorePoolInitialSize()),
new KeyValuePair(Environment.MSG_STORE_DB_POOL_TEST_TABLE, getStorePoolTestTable()),
new KeyValuePair(Environment.MSG_STORE_DB_POOL_TIMEOUT_MILLIS,getStorePoolTimeoutMillis()),
-
-
+ new KeyValuePair(Environment.MSG_STORE_CONN_FACTORY ,getStoreConnectionFactory()),
+ new KeyValuePair(Environment.ROUTER_CBR_CLASS, getContentBasedRouterImplementationClass())
};
public static String dump()
@@ -270,4 +270,19 @@
String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_POOL_TIMEOUT_MILLIS);
return property;
}
+
+ public static String getStoreConnectionFactory()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.MSG_STORE_CONN_FACTORY);
+ return property;
+ }
+
+ public static String getContentBasedRouterImplementationClass()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.ROUTER_MODULE).getProperty(Environment.ROUTER_CBR_CLASS);
+ return property;
+ }
+
+
+
}
\ No newline at end of file
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -70,15 +70,18 @@
*/
public static final String REGISTRY_PASSWORD = "org.jboss.soa.esb.registry.password";
/**
- * The Registry Scout Transport Class defines which communication protocol Scout should use to communicate
+ * The Registry Scout Transport Class property defines which communication protocol Scout should use to communicate
* with the UDDI registry. Note that this parameter is Scout specific.
*/
public static final String REGISTRY_SCOUT_TRANSPORT_CLASS = "org.jboss.soa.esb.scout.proxy.transportClass";
-
/**
* Property that holds directory to use with the helper EPRManager class.
*/
public static final String REGISTRY_FILE_HELPER_DIR = "org.jboss.soa.esb.registry.file.directory";
+ /**
+ * The Content Based Router class property declares which CBR Implementation should be used.
+ */
+ public static final String ROUTER_CBR_CLASS = "org.jboss.soa.esb.routing.cbrClass";
/*
* Connection specific properties
*/
@@ -100,6 +103,7 @@
/*
* DatabaseMessageStore Persistence Store properties.
*/
+ public static final String MSG_STORE_CONN_FACTORY = "org.jboss.soa.esb.persistence.connection.factory";
public static final String MSG_STORE_DB_CONNECTION_URL = "org.jboss.soa.esb.persistence.db.connection.url";
public static final String MSG_STORE_DB_CONNECTION_USER = "org.jboss.soa.esb.persistence.db.user";
public static final String MSG_STORE_DB_CONNECTION_PWD = "org.jboss.soa.esb.persistence.db.pwd";
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Factory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Factory.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Factory.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.common;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+/**
+ * Base class to find a class on the classpath.
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public abstract class Factory
+{
+ private static Logger logger = Logger.getLogger(Factory.class);
+ /**
+ * Loads the class with the given name.
+ * @param className - the className to be found
+ * @return - the class
+ * @throws ClassNotFoundException
+ */
+ protected static Class getClassForName(String className) throws ClassNotFoundException
+ {
+ Class clazz = null;
+ try {
+ logger.log(Priority.DEBUG, "Using the Context ClassLoader");
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ clazz = Class.forName(className, true, contextClassLoader);
+ } catch (ClassNotFoundException classNotFound) {
+ if (logger.isDebugEnabled()) {
+ logger.log(Priority.WARN, "The Contect ClassLoader could not find the class.");
+ logger.log(Priority.WARN, "Using the System ClassLoader");
+ }
+ ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+ clazz = Class.forName(className, true, systemClassLoader);
+ }
+ return clazz;
+ }
+}
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -86,6 +86,8 @@
public static final String TRANSPORTS_MODULE = "transports";
public static final String DBSTORE_MODULE = "dbstore";
+
+ public static final String ROUTER_MODULE = "messagerouting";
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -1,15 +1,36 @@
package org.jboss.soa.esb.helpers;
-import java.util.*;
-import java.io.*;
-import org.apache.log4j.Logger;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
-import javax.xml.parsers.*;
-import javax.xml.transform.*;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.w3c.dom.*;
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
* Objects of this class are to be used for run time configuration of ESB components
@@ -134,6 +155,21 @@
return oRet;
} // _______________________________
/**
+ * obtain the list of all child "property" elements as a List<KeyValuePair>
+ * @return List<KeyValuePair> - containing all child elements with tag name "property"
+ */
+ public List<KeyValuePair> childPropertyList()
+ {
+ List<KeyValuePair> oRet = new ArrayList<KeyValuePair>();
+ for (ConfigTree current : getChildren("property"))
+ {
+ String name = current.getAttribute("name");
+ if (null!=name)
+ oRet.add(new KeyValuePair(name,current.getAttribute("value")));
+ }
+ return oRet;
+ } // _______________________________
+ /**
* concatenated values of all child String values that have been added to 'this'
* <br/>"" (zero length String) if no String child nodes
* @return String - concatenation of all String segments (equivalent to xml text nodes)
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreFactory.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreFactory.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -5,9 +5,11 @@
import java.lang.reflect.Constructor;
import java.net.URI;
+import org.jboss.soa.esb.common.Configuration;
+
@SuppressWarnings("unchecked")
public abstract class MessageStoreFactory {
@@ -17,7 +19,8 @@
{
try {
- Class cls = Class.forName("org.jboss.internal.soa.esb.persistence.format.MessageStoreFactoryImpl");
+// Class cls = Class.forName("org.jboss.internal.soa.esb.persistence.format.MessageStoreFactoryImpl");
+ Class cls = Class.forName(Configuration.getStoreConnectionFactory());
Constructor<MessageStoreFactory> c = cls.getConstructor(new Class[]{});
theFactory = c.newInstance(new Object[]{});
} catch (Exception e) {
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -22,13 +22,272 @@
package org.jboss.soa.esb.util;
import java.io.File;
+import java.util.List;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+import com.enterprisedt.net.ftp.FTPClient;
+import com.enterprisedt.net.ftp.FTPConnectMode;
+import com.enterprisedt.net.ftp.FTPTransferType;
+
/**
- * FTP Utils
+ * Simplified FTP transfers
+ * <p>Description: Implements a simple set of FTP functionality
+ * Parameters to establish the FTP connection are provided at construction time
+ * and cannot change during the lifetime of the object
+ * <br/>Hides low level details. Current implementation is based on the
+ * "Entreprise Distributed Technology edtFTPj" library
+ * but this can be changed with no impact to existing code, just by changing
+ * this class without modifying the signature of it's public methods
+ * </p>
*/
public class FtpClientUtil
{
+ public static final String PARMS_FTP_SERVER = "ftpServer";
+ public static final String PARMS_USER = "ftpUser";
+ public static final String PARMS_PASSWD = "ftpPassword";
+ public static final String PARMS_PORT = "ftpPort";
+ public static final String PARMS_REMOTE_DIR = "ftpRemoteDir";
+ public static final String PARMS_LOCAL_DIR = "ftpLocalDir";
+ public static final String PARMS_ASCII = "ftpAscii";
+ public static final String PARMS_PASSIVE = "ftpPassive";
+
+ private static final String TMP_SUFFIX = ".rosettaPart";
+
+ public enum XFER_TYPE
+ {ascii
+ ,binary
+ };
+
+ private ConfigTree m_oParms;
+ private String m_sFtpServer ,m_sUser ,m_sPasswd;
+ private String m_sRemoteDir ,m_sLocalDir;
+ private int m_iPort;
+ private boolean m_bPassive;
+ public String getRemoteDir() { return m_sRemoteDir; }
+
+ private FTPClient m_oConn = new FTPClient();
+ private FTPTransferType m_oXferType = FTPTransferType.BINARY;
+
+ /**
+ * Checks validity and completeness of parameters, and keeps the info internally
+ * for subsequent FTP requests
+ * @param p_oP ConfigTree
+ * @throws Exception : if parameters are invalid or incomplete
+ * <li>Parameters: (XML attributes at the root level) </li>
+ * <li> ftpServer = name or IP of FTP server </li>
+ * <li> ftpUser = login ID for server </li>
+ * <li> ftpPassword </li>
+ * <li> localDirURI = absolute path in the local filesystem </li>
+ * <li> remoteDirURI = remote path is relative to ftp user home in remote
+ * computer </li>
+ */
+
+ public FtpClientUtil (ConfigTree p_oP, boolean p_bConnect) throws Exception
+ { m_oParms = p_oP;
+ initialize(p_bConnect);
+ } //_________________________________
+
+ public FtpClientUtil (List<KeyValuePair> attribs, boolean connect) throws Exception
+ {
+ m_oParms = new ConfigTree("fromProps");
+ for (KeyValuePair oCurr : attribs)
+ m_oParms.setAttribute(oCurr.getKey(),oCurr.getValue());
+ initialize(connect);
+ } //__________________________________
+
+ private void initialize(boolean bConnect) throws Exception
+ {
+ checkParms();
+ if (bConnect)
+ {
+ m_oConn.setRemoteHost (m_sFtpServer);
+ m_oConn.setRemotePort(m_iPort);
+ m_oConn.connect();
+ for (int i1=0; i1<10 && ! m_oConn.connected(); i1++)
+ Thread.sleep(200);
+ if (! m_oConn.connected())
+ throw new Exception("Can't connect to FTP server");
+ m_oConn.user (m_sUser);
+ m_oConn.password (m_sPasswd);
+ m_oConn.setConnectMode ((m_bPassive) ? FTPConnectMode.PASV : FTPConnectMode.ACTIVE);
+ }
+ } //__________________________________
+ /**
+ * Terminates ftp session and frees resources
+ * <li>Well behaved programs should make sure to call this method </li>
+ */
+ public void quit ()
+ { if (null != m_oConn)
+ try { m_oConn.quit(); }
+ catch (Exception e) {}
+ } //_________________________________
+
+ /**
+ * Deletes specified file in remote directory
+ * @param p_sFile String : filename to delete. Method will attempt to delete
+ * file with rightmost node of argument within remote directory specified in 'remoteDirURI'
+ * @throws Exception : if ftp connection cannot be established, or file
+ * cannot be deleted in remote directory
+ */
+ public void deleteRemoteFile (String p_sFile) throws Exception
+ { m_oConn.delete(getRemoteDir()+"/"+new File(p_sFile).getName());
+ } //_________________________________
+
+ public void remoteDelete (File p_oFile) throws Exception
+ { m_oConn.delete(fileToFtpString(p_oFile));
+ } //_________________________________
+
+ /**
+ * Gets the list of files in the remote directory that end with arg0
+ * @param p_sSuffix String : retrieve only files that end with that suffix - all files if null
+ * @throws Exception : if ftp connection cannot be established, or problems encountered
+ */
+ public String[] getFileListFromRemoteDir (String p_sSuffix) throws Exception
+ {
+ String sSuffix = (null==p_sSuffix)?"*":"*"+p_sSuffix;
+ return m_oConn.dir(sSuffix);
+ } //_________________________________
+
+ /**
+ * Change remote directory
+ * @param p_sDir String : directory to set
+ * @throws Exception : if ftp connection cannot be established, or problems encountered
+ */
+ public void setRemoteDir (String p_sDir) throws Exception
+ {
+ m_oConn.chdir(p_sDir);
+ } //_________________________________
+
+ /**
+ * Renames specified file in remote directory to specified new name
+ * @param p_sFrom String : filename to rename
+ * @param p_sTo String : new filename
+ * @throws Exception : if ftp connection cannot be established, or file
+ * cannot be renamed to new name in remote directory
+ * <li>Method will attempt to rename file with rightmost node of argument
+ * within remote directory specified in 'remoteDirURI', to new name inside
+ * the SAME remote directory
+ */
+ public void renameInRemoteDir (String p_sFrom, String p_sTo) throws Exception
+ {
+ String sRmtFrom = new File(p_sFrom).getName();
+ String sRmtTo = new File(p_sTo).getName();
+
+ try { m_oConn.rename (getRemoteDir()+"/"+sRmtFrom,getRemoteDir()+"/"+sRmtTo); }
+ catch (Exception e)
+ { String sMess = this.getClass().getSimpleName()
+ +" can't rename in remote directory <"
+ +e.getMessage()+">"
+ ;
+ throw new Exception(sMess);
+ }
+ } //_________________________________
+
+ public void remoteRename(File p_oFrom, File p_oTo) throws Exception
+ {
+ try { m_oConn.rename (fileToFtpString(p_oFrom),fileToFtpString(p_oTo)); }
+ catch (Exception e)
+ { String sMess = this.getClass().getSimpleName()
+ +" can't rename in remote directory <"
+ +e.getMessage()+">"
+ ;
+ throw new Exception(sMess);
+ }
+ } //_________________________________
+
+ /**
+ * Uploads specified file from local directory (localDirURI) to remote
+ * directory (remoteDirURI)
+ * @param p_sFile String : filename to upload
+ * @throws Exception : if ftp connection cannot be established, or file
+ * cannot be uploaded
+ * <li> local file will be renamed during transfer ('.xferNotReady' appended
+ * to name)</li>
+ * <li> upon successful completion. the suffix '.xferDone' will be appended
+ * to the original filename </li>
+ */
+ public void uploadFile (File p_oFile, String p_sRemoteName) throws Exception
+ {
+ String sRemoteOK = getRemoteDir() + "/" + p_sRemoteName;
+ String sRemoteTmp = sRemoteOK+TMP_SUFFIX;
+ m_oConn.setType(m_oXferType);
+ m_oConn.put(fileToFtpString(p_oFile),sRemoteTmp);
+ m_oConn.rename(sRemoteTmp,sRemoteOK);
+ } //_________________________________
+
+ /**
+ * Downloads specified file from remote directory (remoteDirURI) to local
+ * directory (localDirURI)
+ * @param p_sFile String : filename to download
+ * @throws Exception : if ftp connection cannot be established, or file
+ * cannot be downloaded
+ * <li> local file is assigned a temporary name during transfer </li>
+ * <li> upon successful completion, local temporary file will be renamed to
+ * name specified in argument, and suffix '.xferDone' will be appended
+ * to the original filename in the remote directory </li>
+ */
+ public void downloadFile (String p_sFile, String p_sFinalName) throws Exception
+ {
+ File oLocalDir = new File(m_sLocalDir);
+ File oLclFile= File.createTempFile("Rosetta_",TMP_SUFFIX,oLocalDir);
+
+ try { oLclFile.delete(); }
+ catch (Exception e) {}
+ m_oConn.setType(m_oXferType);
+ m_oConn.get(fileToFtpString(oLclFile),p_sFile);
+
+ File oNew = new File(oLocalDir,p_sFinalName);
+ if (oNew.exists()) oNew.delete();
+ oLclFile.renameTo(oNew);
+ } //_________________________________
+
+ // Beware !!! The logic here seems wrong, but it works
+ // It appears that there's some kind of bug in the edtftpj.jar library
+ // The !XFER_TYPE.ascii.equals(p_oMode) should NOT be negated
+ // But it works when negated (newlines from Unix to DOS)
+ private void setXferType (XFER_TYPE p_oMode)
+ { m_oXferType = !XFER_TYPE.ascii.equals(p_oMode)
+ ? FTPTransferType.ASCII : FTPTransferType.BINARY;
+ } //_________________________________
+
+ private void checkParms() throws Exception
+ {
+ m_sFtpServer = m_oParms.getAttribute(PARMS_FTP_SERVER);
+ if (null==m_sFtpServer) throw new Exception ("No FTP server specified");
+
+ m_sUser = m_oParms.getAttribute(PARMS_USER);
+ if (null==m_sUser) throw new Exception ("No username specified for FTP");
+
+ m_sPasswd = m_oParms.getAttribute(PARMS_PASSWD);
+ if (null==m_sPasswd) throw new Exception ("No password specified for FTP");
+
+ m_sRemoteDir = m_oParms.getAttribute(PARMS_REMOTE_DIR);
+ if (null==m_sRemoteDir)
+ m_sRemoteDir = "";
+
+ m_sLocalDir = m_oParms.getAttribute(PARMS_LOCAL_DIR);
+ if (null==m_sLocalDir)
+ m_sLocalDir = ".";
+
+ String sAux = m_oParms.getAttribute(PARMS_PORT);
+ m_iPort = (null==sAux) ? 21 : Integer.parseInt(sAux);
+
+ boolean bAscii = false;
+ sAux = m_oParms.getAttribute(PARMS_ASCII);
+ if (null!=sAux)
+ bAscii = Boolean.parseBoolean(sAux);
+ setXferType((bAscii)?XFER_TYPE.ascii:XFER_TYPE.binary);
+
+ m_bPassive = false;
+ sAux = m_oParms.getAttribute(PARMS_PASSIVE);
+ m_bPassive = (null!=sAux) && Boolean.parseBoolean(sAux);
+
+ return;
+ } //__________________________________
+
public static String fileToFtpString(File p_oF)
{
return(null==p_oF) ? null
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -28,6 +28,7 @@
import java.io.PrintStream;
import java.io.Serializable;
import java.io.StringWriter;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -167,8 +168,8 @@
InputStream inStream = new ByteArrayInputStream(((String)serial).getBytes());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(inStream);
-
+ Document doc = builder.parse(inStream);
+
org.jboss.internal.soa.esb.message.format.xml.MessageImpl message =
new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
message.fromXML(doc);
@@ -194,4 +195,13 @@
return oRet;
} //________________________________
+ public static String getStamp()
+ {
+ return s_oTS.format(new java.util.Date(System.currentTimeMillis()));
+ }
+
+ private static final SimpleDateFormat s_oTS
+ = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss.SSS");
+
+
} // ____________________________________________________________________________
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -24,7 +24,7 @@
import junit.framework.TestCase;
-import org.jboss.soa.esb.addressing.helpers.EmailEpr;
+import org.jboss.soa.esb.addressing.eprs.EmailEpr;
/**
* Unit tests for the EPR class.
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -24,7 +24,7 @@
import junit.framework.TestCase;
-import org.jboss.soa.esb.addressing.helpers.FTPEpr;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
/**
* Unit tests for the EPR class.
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -26,7 +26,7 @@
import junit.framework.TestCase;
-import org.jboss.soa.esb.addressing.helpers.HTTPEpr;
+import org.jboss.soa.esb.addressing.eprs.HTTPEpr;
/**
* Unit tests for the EPR class.
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -24,7 +24,7 @@
import junit.framework.TestCase;
-import org.jboss.soa.esb.addressing.helpers.JDBCEpr;
+import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
/**
* Unit tests for the EPR class.
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -24,7 +24,7 @@
import junit.framework.TestCase;
-import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
/**
* Unit tests for the EPR class.
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRHelperUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRHelperUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRHelperUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.addressing.util.tests;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.addressing.helpers.EPRHelper;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.EmailEpr;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class EPRHelperUnitTest extends TestCase
+{
+
+ public void testToFromXMLString ()
+ {
+ EmailEpr email = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "foobar", "25", "me", "letmein");
+
+ String xmlString = EPRHelper.toXMLString(email);
+
+ System.err.println(xmlString);
+
+ EPR epr = EPRHelper.fromXMLString(xmlString);
+
+ if (epr instanceof EmailEpr)
+ {
+ }
+ else
+ fail();
+ }
+
+}
Modified: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -24,7 +24,8 @@
import junit.framework.TestCase;
-import org.jboss.soa.esb.addressing.helpers.EmailEpr;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.EmailEpr;
import org.jboss.soa.esb.addressing.util.EPRManager;
/**
@@ -74,4 +75,36 @@
}
}
+ public void testSpecificInputOutput ()
+ {
+ EmailEpr email = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "foobar", "25", "me", "letmein");
+
+ String tmpDir = "/tmp";
+ String os = System.getProperty("os.name").toLowerCase();
+ if (os.indexOf("windows")>=0) {
+ tmpDir="/Temp";
+ }
+ EPRManager manager = EPRManager.getInstance(tmpDir);
+
+ try
+ {
+ manager.saveEPR("MyEmail", email);
+
+ EPR epr = manager.loadEPR("MyEmail");
+
+ if (epr instanceof EmailEpr)
+ {
+
+ }
+ else
+ fail();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
}
Modified: labs/jbossesb/workspace/b_georges/product/core/services/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/build.xml 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/services/build.xml 2006-11-13 21:42:31 UTC (rev 7573)
@@ -11,6 +11,7 @@
<property name="org.jboss.esb.services.classes.dir" value="${org.jboss.esb.internal.dest}/classes/services"/>
<property name="org.jboss.esb.services.src.dir" value="${basedir}/src"/>
+ <property name="org.jboss.esb.services.rules.dir" value="${basedir}/rules"/>
<property name="org.jboss.esb.root.dir" value="../.."/>
<property environment="env"/>
@@ -31,6 +32,7 @@
<path id="org.jboss.esb.services.base.classpath">
<fileset dir="${org.jboss.esb.ext.lib.dir}" includes="*.jar" excludes="jbossall-client.jar"/>
<fileset dir="${org.jboss.esb.ejb3.lib.dir}" includes="*.jar,*.zip"/>
+ <pathelement location="${org.jboss.esb.internal.dest}/classes/rosetta"/>
</path>
<!-- =================================================================== -->
@@ -115,6 +117,10 @@
basedir="${org.jboss.esb.services.classes.dir}"
includes="**/*.class"
/>
+ <jar destfile="${org.jboss.esb.services.dist.dir}/lib/jbossesb-rules.jar"
+ basedir="${org.jboss.esb.services.rules.dir}"
+ includes="**/*.drl,**/*.dsl"
+ />
<antcall target="-ear"/>
</target>
Modified: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreType.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreType.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreType.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -26,7 +26,7 @@
*
*/
-package org.jboss.internal.soa.esb.persistence.format;
+package org.jboss.soa.esb.services.persistence;
import java.net.URI;
Modified: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -29,7 +29,7 @@
*
* @author Kurt Stam
*/
-interface Registry
+public interface Registry
{
/**
* Removes a service from the Registry along with all the ServiceBindings underneath it.
@@ -51,7 +51,7 @@
* @param eprDescription - human readable description of the EPR
* @throws RegistryException
*/
- public void registerEPR(String category, String serviceName, String serviceDescription, EPR epr, String eprDescription)
+ public void registerEPR(String serviceCategoryName, String serviceName, String serviceDescription, EPR epr, String eprDescription)
throws RegistryException;
/**
* Removes an EPR from the Registry.
@@ -60,7 +60,7 @@
* @param epr - the EndPointReference (EPR) that needs to be unregistered.
* @throws RegistryException
*/
- public void unRegisterEPR(String category, String serviceName, EPR epr) throws RegistryException;
+ public void unRegisterEPR(String serviceCategoryName, String serviceName, EPR epr) throws RegistryException;
/**
* Find all Services assigned to the Red Hat/JBossESB organization.
* @return Collection of Strings containing the service names.
@@ -74,7 +74,7 @@
* @return Collection of Strings containing the service names
* @throws RegistryException
*/
- public Collection<String> findServices(String category) throws RegistryException;
+ public Collection<String> findServices(String serviceCategoryName) throws RegistryException;
/**
* Finds all the EPRs that belong to a specific category and service combination.
*
@@ -83,5 +83,5 @@
* @return Collection of EPRs.
* @throws RegistryException
*/
- public Collection<EPR> findEPRs(String category, String serviceName) throws RegistryException;
+ public Collection<EPR> findEPRs(String serviceCategoryName, String serviceName) throws RegistryException;
}
Modified: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryFactory.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryFactory.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -24,52 +24,30 @@
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.Factory;
/**
* Returns an Instance of the Registry.
* @author kstam
*
*/
-public class RegistryFactory
+public class RegistryFactory extends Factory
{
- private static Logger logger = Logger.getLogger(RegistryFactory.class);
+ private static Logger logger = Logger.getLogger(RegistryException.class);
- public static Registry getRegistry() {
+ public static Registry getRegistry() throws RegistryException{
Registry registry = null;
String className = Configuration.getRegistryImplementationClass();
+ logger.log(Priority.INFO, "Going to load " + className);
try {
- // instruct class loader to load the TransportFactory
+ // instruct class loader to load the Registry Implementation
Class registryClass = getClassForName(className);
// Try to instance the Registry
registry = (Registry) registryClass.newInstance();
} catch (ClassNotFoundException cnfex) {
- cnfex.printStackTrace();
- } catch (java.lang.Exception ex) {
- ex.printStackTrace();
+ throw new RegistryException("Registry Implementation=" + className + " not found", cnfex);
+ } catch (Exception e) {
+ throw new RegistryException("Invokation exception. " + e.getLocalizedMessage(), e);
}
return registry;
}
-
- /**
- * Loads the class with the given name.
- * @param className - the className to be found
- * @return - the class
- * @throws ClassNotFoundException
- */
- private static Class getClassForName(String className) throws ClassNotFoundException
- {
- Class clazz = null;
- try {
- logger.log(Priority.DEBUG, "Using the Context ClassLoader");
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- clazz = Class.forName(className, true, contextClassLoader);
- } catch (ClassNotFoundException classNotFound) {
- if (logger.isDebugEnabled()) {
- logger.log(Priority.WARN, "The Contect ClassLoader could not find the class.");
- logger.log(Priority.WARN, "Using the System ClassLoader");
- }
- ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
- clazz = Class.forName(className, true, systemClassLoader);
- }
- return clazz;
- }
}
Modified: labs/jbossesb/workspace/b_georges/product/core/services/tests/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/build.xml 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/build.xml 2006-11-13 21:42:31 UTC (rev 7573)
@@ -23,7 +23,8 @@
<path id="org.jboss.esb.tests.base.classpath">
<fileset dir="../${org.jboss.esb.ext.lib.dir}"
- includes="*.jar" excludes="jbossall-client.jar"/>
+ includes="*.jar" excludes="jbossall-client.jar"/>
+ <pathelement location="${basedir}/../rules"/>
<pathelement location="${org.jboss.esb.module.classes.dir}"/>
<pathelement location="${org.jboss.esb.internal.dest}/classes/rosetta"/>
<pathelement location="${org.jboss.esb.ejb3_conf.tests.src.dir}"/>
Modified: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -26,6 +26,8 @@
*
*
*/
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.File;
@@ -35,50 +37,42 @@
import java.sql.Connection;
import java.sql.Statement;
-import junit.framework.TestCase;
+import junit.framework.JUnit4TestAdapter;
-import org.jboss.internal.soa.esb.persistence.format.MessageStoreType;
import org.jboss.internal.soa.esb.persistence.format.db.DBConnectionManager;
import org.jboss.soa.esb.common.Configuration;
-import org.jboss.soa.esb.common.tests.HsqldbUtil;
-import org.jboss.soa.esb.common.tests.TestUtil;
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.esb.services.persistence.MessageStore;
import org.jboss.soa.esb.services.persistence.MessageStoreFactory;
+import org.jboss.soa.esb.services.persistence.MessageStoreType;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
-public class MessageStoreUnitTest extends TestCase{
+public class MessageStoreUnitTest {
// private static Logger log = Logger.getLogger(MessageStoreUnitTest.class);
@Test
public void testDefaultMessageStore() {
- TestUtil.setESBPropertiesFileToUse();
- MessageStoreUnitTest.runBeforeAllTests();
MessageStore store = MessageStoreFactory.getInstance().getMessageStore();
assertEquals((store != null), true);
- MessageStoreUnitTest.runAfterAllTests();
}
@Test
public void testURIMessageStore() {
- TestUtil.setESBPropertiesFileToUse();
-
//only DB supported for now
- MessageStoreUnitTest.runBeforeAllTests();
MessageStore store1 = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
assertEquals((store1 != null), true);
- MessageStoreUnitTest.runAfterAllTests();
}
@Test
public void testStoreAndRetrieve() {
- TestUtil.setESBPropertiesFileToUse();
- MessageStoreUnitTest.runBeforeAllTests();
-
//add new messages
Message msg1 = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
Message msg2 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
@@ -125,34 +119,38 @@
} catch (Exception e) {
e.printStackTrace();
}
-
- MessageStoreUnitTest.runAfterAllTests();
}
@Test
public void testDBConnectionManager() {
- TestUtil.setESBPropertiesFileToUse();
- MessageStoreUnitTest.runBeforeAllTests();
MessageStore store = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
assertEquals((store != null), true);
DBConnectionManager mgr = DBConnectionManager.getInstance();
assertEquals((mgr != null), true);
- MessageStoreUnitTest.runAfterAllTests();
}
-
- private static void runBeforeAllTests() {
- TestUtil.setESBPropertiesFileToUse();
+ @BeforeClass
+ public static void runBeforeAllTests() {
+ TestEnvironmentUtil.setESBPropertiesFileToUse();
+ System.out.println(Configuration.dump());
try {
if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
- HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "jbossesb");
+ HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir() + "build/hsqltestdb", "jbossesb");
//Get the registry-schema create scripts
String database = "hsqldb";
- String sqlDir = TestUtil.getPrefix() + "install/message-store/sql/" + database + "/";
+ String sqlDir = TestEnvironmentUtil.getUserDir() + "install/message-store/sql/" + database + "/";
//Drop what is there now, if exists. We want to start fresh.
String sqlCreateCmd = MessageStoreUnitTest.readTextFile(new File(sqlDir + "create_database.sql"));
String sqlDropCmd = MessageStoreUnitTest.readTextFile(new File(sqlDir + "drop_database.sql"));
+ try {
+ Class.forName(Configuration.getStoreDriver());
+ } catch (Exception e) {
+ System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+ e.printStackTrace();
+ return;
+ }
+
DBConnectionManager mgr = DBConnectionManager.getInstance();
Connection con = mgr.getConnection();
Statement stmnt = con.createStatement();
@@ -168,7 +166,8 @@
}
}
- private static void runAfterAllTests() {
+ @AfterClass
+ public static void runAfterAllTests() {
try {
if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver"))
HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
@@ -197,6 +196,9 @@
return sb.toString();
}
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(MessageStoreUnitTest.class);
+ }
}
Modified: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java 2006-11-13 20:51:54 UTC (rev 7572)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java 2006-11-13 21:42:31 UTC (rev 7573)
@@ -36,10 +36,11 @@
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
+import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.common.tests.HsqldbUtil;
-import org.jboss.soa.esb.common.tests.TestUtil;
-import org.jboss.soa.esb.services.util.FileUtil;
+import org.jboss.soa.esb.testutils.FileUtil;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -66,15 +67,25 @@
@Test
public void publishEPR()
{
- Registry registry = RegistryFactory.getRegistry();
EPR epr = new EPR();
try {
+ Registry registry = RegistryFactory.getRegistry();
registry.registerEPR(CATEGORY, SERVICE_NAME, "Service for traveling",
epr, "Specific Service Binding for traveling");
} catch (RegistryException re) {
logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
assertTrue(false);
}
+ try {
+ Registry registry = RegistryFactory.getRegistry();
+ registry.registerEPR(null, SERVICE_NAME, null,
+ epr, null);
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ //make sure we can handle some null arguments
+
}
/**
* This test will try to find all services in the "travel" category.
@@ -82,8 +93,8 @@
@Test
public void findService()
{
- Registry registry = RegistryFactory.getRegistry();
try {
+ Registry registry = RegistryFactory.getRegistry();
Collection<String> services = registry.findServices(CATEGORY);
for (Iterator i=services.iterator();i.hasNext();) {
String serviceName = (String) i.next();
@@ -101,8 +112,8 @@
@Test
public void findEPRs()
{
- Registry registry = RegistryFactory.getRegistry();
try {
+ Registry registry = RegistryFactory.getRegistry();
Collection<EPR> eprs = registry.findEPRs(CATEGORY, SERVICE_NAME);
for (Iterator i=eprs.iterator();i.hasNext();) {
EPR epr = (EPR) i.next();
@@ -116,8 +127,8 @@
@Test
public void unregisterEPR()
{
- Registry registry = RegistryFactory.getRegistry();
try {
+ Registry registry = RegistryFactory.getRegistry();
EPR eprToBeRemoved = new EPR();
registry.unRegisterEPR(CATEGORY, SERVICE_NAME, eprToBeRemoved);
// Now make sure this EPR is really gone
@@ -132,8 +143,8 @@
@Test
public void unregisterService()
{
- Registry registry = RegistryFactory.getRegistry();
try {
+ Registry registry = RegistryFactory.getRegistry();
registry.unRegisterService(CATEGORY, SERVICE_NAME);
//Make sure it's really gone
Collection<String> services = registry.findAllServices();
@@ -149,9 +160,10 @@
* @throws Exception
*/
@BeforeClass
- public static void runBeforeAllTests() throws Exception {
+ public static void runBeforeAllTests() {
try {
- TestUtil.setESBPropertiesFileToUse();
+ DOMConfigurator.configure(TestEnvironmentUtil.getUserDir() + "etc/test/resources/log4j.xml");
+ TestEnvironmentUtil.setESBPropertiesFileToUse();
//Set the juddi properties file in System so juddi will pick it up later and use the test values.
String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-unittest.properties";
System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
@@ -168,13 +180,13 @@
if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
database = "hsqldb";
//Bring up hsql on default port 9001
- HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "juddi");
+ HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir() + "build/hsqltestdb", "juddi");
} else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
database = "mysql";
} //add and test your own database..
//Get the registry-schema create scripts
- String sqlDir = TestUtil.getPrefix() + "install/jUDDI-registry/sql/" + database + "/";
+ String sqlDir = TestEnvironmentUtil.getUserDir() + "install/jUDDI-registry/sql/" + database + "/";
//Drop what is there now, if exists. We want to start fresh.
String sqlDropCmd = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
String sqlCreateCmd = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
More information about the jboss-svn-commits
mailing list