[jboss-svn-commits] JBL Code SVN: r8597 - in labs/jbossesb/trunk/product/core: listeners/src/org/jboss/internal/soa/esb/listeners listeners/src/org/jboss/soa/esb/actions listeners/src/org/jboss/soa/esb/listeners/gateway rosetta/src/org/jboss/internal/soa/esb/couriers rosetta/src/org/jboss/internal/soa/esb/couriers/helpers

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 27 22:39:46 EST 2006


Author: estebanschifman
Date: 2006-12-27 22:39:33 -0500 (Wed, 27 Dec 2006)
New Revision: 8597

Added:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java
Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/DefaultListenerManager.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/Notifier.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java
Log:
StaticRouter action class + minor adjustments to core classes

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/DefaultListenerManager.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/DefaultListenerManager.java	2006-12-28 03:37:53 UTC (rev 8596)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/DefaultListenerManager.java	2006-12-28 03:39:33 UTC (rev 8597)
@@ -672,7 +672,11 @@
 		Registry registry = RegistryFactory.getRegistry();
 		synchronized (_synchRegistry)
 		{
-			registry.unRegisterEPR(serviceCategoryName, serviceName, epr);
+			try { registry.unRegisterEPR(serviceCategoryName, serviceName, epr); }
+			catch (Exception e)
+			{
+				_logger.warn(e);
+			}
 		}
 	} // ____________________________
 

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/Notifier.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/Notifier.java	2006-12-28 03:37:53 UTC (rev 8596)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/Notifier.java	2006-12-28 03:39:33 UTC (rev 8597)
@@ -1,3 +1,25 @@
+/*
+ * 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.util.ArrayList;
@@ -8,6 +30,11 @@
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.notification.NotificationList;
 
+/**
+ * Stand alone action class that replaces the NotificationHandler EJB (beta 1) 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ */
 public class Notifier 
 {
 	public Notifier(ConfigTree config)

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java	2006-12-28 03:37:53 UTC (rev 8596)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java	2006-12-28 03:39:33 UTC (rev 8597)
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+
+/**
+ * Routes the Message argument to a fixed list of services ([category,name]) 
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ */
+package org.jboss.soa.esb.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
+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.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
+
+public class StaticRouter 
+{
+	public static final String DESTINATION_LIST_TAG="destinations";
+	public static final String ROUTE_TO_TAG="route-to";
+	
+	private StaticRouter() {}
+	public  StaticRouter (ConfigTree config) throws Exception
+	{
+		_config	= config;
+		checkMyParms();
+		_registry = RegistryFactory.getRegistry();
+	} //________________________________
+	
+	public Message process(Message message) throws Exception
+	{
+		Call call = message.getHeader().getCall();
+		if (null==call  || null==call.getMessageID())
+			throw new IllegalArgumentException("Null message ID");
+
+		for (String[] curr : _destinations)
+		{
+			EPR epr = _registry.findEPR(curr[0], curr[1]);
+			if (epr instanceof FileEpr)
+			{
+				FileEpr fpr = (FileEpr)epr;
+				FileEpr newEpr = new FileEpr(fpr.getURL());
+				newEpr.setPostDelete(false);
+				newEpr.setPostDirectory(fpr.getURL().getFile());
+				newEpr.setPostSuffix(curr[2]);
+				epr	= newEpr;
+			}
+			CourierFactory.getCourier(epr).deliver(message);
+		}
+		return message;
+	} //________________________________
+	
+	protected void checkMyParms() throws ConfigurationException
+	{
+		_destinations = new ArrayList<String[]>();
+		ConfigTree[] destList = _config.getChildren(ROUTE_TO_TAG);
+		if (null==destList || destList.length<1)
+		{
+			_logger.warn("Missing or empty destination list - This action class won't have any effect");
+			return;
+		}
+		for(ConfigTree curr : destList)
+			try
+			{
+				String category	= curr.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG,"");
+				String name		= curr.getAttribute(ListenerTagNames.SERVICE_NAME_TAG,null);
+				String suffix	= curr.getAttribute(FileEpr.POST_SUFFIX_TAG);
+				_destinations.add(new String[] {category,name,suffix});
+			}
+			catch (Exception e)
+			{
+				throw new ConfigurationException("Problems with destination list",e);
+			}
+	} //________________________________
+
+	protected ConfigTree		_config;
+	protected List<String[]> 	_destinations;
+	protected Registry			_registry;
+	protected static Logger		_logger=Logger.getLogger(StaticRouter.class);
+	
+}

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2006-12-28 03:37:53 UTC (rev 8596)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2006-12-28 03:39:33 UTC (rev 8597)
@@ -34,6 +34,7 @@
 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.FileEpr;
 import org.jboss.soa.esb.couriers.Courier;
 import org.jboss.soa.esb.couriers.CourierException;
 import org.jboss.soa.esb.couriers.CourierFactory;
@@ -134,6 +135,22 @@
         			boolean bSent = false;
 	        		for (EPR current : _targetEprs)
 	        		{
+	        			if (current instanceof FileEpr)
+	        			{
+        					try
+        					{
+            					FileEpr fpr = (FileEpr)current;
+        						FileEpr newEpr = new FileEpr(fpr.getURL());
+        						newEpr.setPostDelete(false);
+        						newEpr.setPostDirectory(fpr.getURL().getFile());
+        						newEpr.setPostSuffix(fpr.getInputSuffix());
+            					current = newEpr;
+        					}
+        					catch (Exception e)
+        					{
+        						_logger.error("Problems with file EPR",e);
+        					}
+	        			}
 	        			_courier = CourierFactory.getCourier(current);
 	        			if (_courier.deliver((org.jboss.soa.esb.message.Message)obj))
 	        			{

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java	2006-12-28 03:37:53 UTC (rev 8596)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java	2006-12-28 03:39:33 UTC (rev 8597)
@@ -26,8 +26,10 @@
 import java.io.IOException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.UUID;
 
 import javax.xml.parsers.ParserConfigurationException;
 
@@ -35,6 +37,7 @@
 import org.jboss.internal.soa.esb.couriers.helpers.FileHandler;
 import org.jboss.internal.soa.esb.couriers.helpers.FileHandlerFactory;
 import org.jboss.internal.soa.esb.couriers.helpers.LocalFileHandler;
+import org.jboss.soa.esb.addressing.Call;
 import org.jboss.soa.esb.addressing.eprs.FileEpr;
 import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.common.ModulePropertyManager;
@@ -99,6 +102,7 @@
 		try
 		{
 			_outputSuffix = _epr.getPostSuffix();
+			_logger.debug("output suffix set to "+_outputSuffix,new Exception("DEBUGGING"));
 		}
 		catch (URISyntaxException e)
 		{
@@ -177,6 +181,18 @@
 					"Can't find appropriate file handler for "
 							+ _url.toString());
 
+		Call call = message.getHeader().getCall();
+		if (null==call)
+			message.getHeader().setCall(call=new Call());
+		try
+		{
+			if (null==call.getMessageID())
+				call.setMessageID(new URI(UUID.randomUUID().toString()));
+		}
+		catch (URISyntaxException e)
+		{
+			throw new CourierException("Problems with message header ",e);
+		}
 		File tmpFile = null;
 
 		if (handler instanceof LocalFileHandler)

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java	2006-12-28 03:37:53 UTC (rev 8596)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java	2006-12-28 03:39:33 UTC (rev 8597)
@@ -28,6 +28,7 @@
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.UUID;
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.addressing.Call;
@@ -116,17 +117,18 @@
 			return false;
 
 		String msgId = null;
+		Call call = message.getHeader().getCall();
+		if (null==call)
+			message.getHeader().setCall(call=new Call());
 		try
 		{
-			Call call = message.getHeader().getCall();
-			URI uri = (null == call) ? null : call.getMessageID();
-			msgId = (null == uri) ? null : uri.toString();
-			if (null == msgId)
-				throw new CourierException("Message ID must not be null");
+			if (null==call.getMessageID())
+				call.setMessageID(new URI(UUID.randomUUID().toString()));
+			msgId = call.getMessageID().toString();
 		}
 		catch (URISyntaxException e)
 		{
-			throw new CourierException(e);
+			throw new CourierException("Problems with message header ",e);
 		}
 
 		if (null == _conn)

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java	2006-12-28 03:37:53 UTC (rev 8596)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/LocalFileHandler.java	2006-12-28 03:39:33 UTC (rev 8597)
@@ -95,10 +95,12 @@
 	{
 		try
 		{
-			to.delete();
+			if (to.exists())
+				to.delete();
 			if (!from.renameTo(to))
 				throw new CourierException("Unable to rename from " + from
 						+ " to " + to);
+			System.out.println(from+"--renamed to --"+to);
 			return true;
 		}
 		catch (Exception e)




More information about the jboss-svn-commits mailing list