[jboss-svn-commits] JBL Code SVN: r12085 - in labs/jbossesb/trunk/product/core/listeners: tests/src/org/jboss/soa/esb/listeners/message and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue May 22 13:37:34 EDT 2007


Author: mark.little at jboss.com
Date: 2007-05-22 13:37:34 -0400 (Tue, 22 May 2007)
New Revision: 12085

Added:
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/ErrorActionProcessor.java
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/NPEActionProcessor.java
Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java
Log:
Added some more defensive code around errors during pipeline processing.

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java	2007-05-22 13:58:58 UTC (rev 12084)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java	2007-05-22 17:37:34 UTC (rev 12085)
@@ -357,27 +357,39 @@
 		if (replyToEPR != null)
 			replyToAddress = replyToEPR;
 
-		try
+		if (replyToAddress == null)
 		{
-			courier = CourierFactory.getCourier(replyToAddress);
-			courier.deliver(message);
+			LOGGER.warn("No reply to address defined for reply message!");
 		}
-		catch (final CourierException e)
+		else
 		{
-			LOGGER.error("Failed to reply to address " + replyToAddress + ".",
-					e);
-		}
-		catch (final MalformedEPRException e)
-		{
-			LOGGER.error("Failed to reply to address " + replyToAddress + ".",
-					e);
-		}
-		finally
-		{
-			if (courier != null)
+			try
 			{
-				CourierUtil.cleanCourier(courier);
+				courier = CourierFactory.getCourier(replyToAddress);
+				courier.deliver(message);
 			}
+			catch (final CourierException e)
+			{
+				LOGGER.error("Failed to reply to address " + replyToAddress + ".",
+						e);
+			}
+			catch (final MalformedEPRException e)
+			{
+				LOGGER.error("Failed to reply to address " + replyToAddress + ".",
+						e);
+			}
+			catch (final Throwable e)
+			{
+				LOGGER.error("Failed to reply to address " + replyToAddress + ".",
+						e);
+			}
+			finally
+			{
+				if (courier != null)
+				{
+					CourierUtil.cleanCourier(courier);
+				}
+			}
 		}
 	}
 
@@ -430,27 +442,39 @@
 		if (faultToEPR != null)
 			faultToAddress = faultToEPR;
 
-		try
+		if (faultToAddress == null)
 		{
-			courier = CourierFactory.getCourier(faultToAddress);
-			courier.deliver(message);
+			LOGGER.warn("No fault address defined for fault message!");
 		}
-		catch (final CourierException e)
+		else
 		{
-			LOGGER.error("Failed to send error to address " + faultToAddress
-					+ ".", e);
-		}
-		catch (final MalformedEPRException e)
-		{
-			LOGGER.error("Failed to send error to address " + faultToAddress
-					+ ".", e);
-		}
-		finally
-		{
-			if (courier != null)
+			try
 			{
-				CourierUtil.cleanCourier(courier);
+				courier = CourierFactory.getCourier(faultToAddress);
+				courier.deliver(message);
 			}
+			catch (final CourierException e)
+			{
+				LOGGER.error("Failed to send error to address " + faultToAddress
+						+ ".", e);
+			}
+			catch (final MalformedEPRException e)
+			{
+				LOGGER.error("Failed to send error to address " + faultToAddress
+						+ ".", e);
+			}
+			catch (final Throwable e)
+			{
+				LOGGER.error("Failed to send error to address " + faultToAddress
+						+ ".", e);
+			}
+			finally
+			{
+				if (courier != null)
+				{
+					CourierUtil.cleanCourier(courier);
+				}
+			}
 		}
 	}
 

Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java	2007-05-22 13:58:58 UTC (rev 12084)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java	2007-05-22 17:37:34 UTC (rev 12085)
@@ -314,6 +314,54 @@
         checkOrder(MockActionInfo.getDestroyList()) ;
     }
     
+    public void testErrorActionProcessorException() throws Exception
+	{
+		final ConfigTree configTree = new ConfigTree("parent");
+
+		addAction(configTree, ErrorActionProcessor.class.getName(), "process",
+				null, null);
+		addAction(configTree, ErrorActionProcessor.class.getName(), null,
+				"anotherProcessSuccess", null);
+		addAction(configTree, MockActionProcessorFailure.class.getName(), null,
+				null, "anotherProcessException");
+		addAction(configTree, ErrorActionProcessor.class.getName(),
+				"process, anotherProcess", "anotherProcessSuccess",
+				"anotherProcessException");
+
+		final ActionProcessingPipeline pipeline = new ActionProcessingPipeline(
+				configTree);
+		pipeline.initialise();
+		
+		final boolean result = pipeline.process(MessageFactory.getInstance()
+				.getMessage());
+		
+		assertFalse(result);
+	}
+    
+    public void testNPEActionProcessorException() throws Exception
+	{
+		final ConfigTree configTree = new ConfigTree("parent");
+
+		addAction(configTree, NPEActionProcessor.class.getName(), "process",
+				null, null);
+		addAction(configTree, NPEActionProcessor.class.getName(), null,
+				"anotherProcessSuccess", null);
+		addAction(configTree, MockActionProcessorFailure.class.getName(), null,
+				null, "anotherProcessException");
+		addAction(configTree, ErrorActionProcessor.class.getName(),
+				"process, anotherProcess", "anotherProcessSuccess",
+				"anotherProcessException");
+
+		final ActionProcessingPipeline pipeline = new ActionProcessingPipeline(
+				configTree);
+		pipeline.initialise();
+		
+		final boolean result = pipeline.process(MessageFactory.getInstance()
+				.getMessage());
+		
+		assertFalse(result);
+	}
+    
     public void testInvalidConstructor()
         throws Exception
     {

Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/ErrorActionProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/ErrorActionProcessor.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/ErrorActionProcessor.java	2007-05-22 17:37:34 UTC (rev 12085)
@@ -0,0 +1,81 @@
+/*
+ * 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 org.jboss.soa.esb.actions.ActionLifecycleException;
+import org.jboss.soa.esb.actions.ActionPipelineProcessor;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+public class ErrorActionProcessor implements ActionPipelineProcessor
+{
+    private final Integer id ;
+    private final Integer anotherId ;
+    
+    public ErrorActionProcessor(final ConfigTree tree)
+    {
+        id = MockActionInfo.getNextId() ;
+        anotherId = MockActionInfo.getNextId() ;
+    }
+    
+    public Message process(Message message) throws ActionProcessingException
+    {
+        throw new ActionProcessingException("foo");
+    }
+    
+    public Message anotherProcess(Message message) throws ActionProcessingException
+    {
+    	throw new ActionProcessingException("foo");
+    }
+
+    public void processException(Message message, Throwable th)
+    {
+        MockActionInfo.addExceptionId(id) ;
+    }
+
+    public void anotherProcessException(Message message, Throwable th)
+    {
+        MockActionInfo.addExceptionId(anotherId) ;
+    }
+
+    public void processSuccess(Message message)
+    {
+        MockActionInfo.addSuccessId(id) ;
+    }
+
+    public void anotherProcessSuccess(Message message)
+    {
+        MockActionInfo.addSuccessId(anotherId) ;
+    }
+
+    public void destroy() throws ActionLifecycleException
+    {
+        MockActionInfo.addDestroyId(id) ;
+    }
+
+    public void initialise() throws ActionLifecycleException
+    {
+        MockActionInfo.addInitialiseId(id) ;
+    }
+}

Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/NPEActionProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/NPEActionProcessor.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/NPEActionProcessor.java	2007-05-22 17:37:34 UTC (rev 12085)
@@ -0,0 +1,81 @@
+/*
+ * 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 org.jboss.soa.esb.actions.ActionLifecycleException;
+import org.jboss.soa.esb.actions.ActionPipelineProcessor;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+public class NPEActionProcessor implements ActionPipelineProcessor
+{
+    private final Integer id ;
+    private final Integer anotherId ;
+    
+    public NPEActionProcessor(final ConfigTree tree)
+    {
+        id = MockActionInfo.getNextId() ;
+        anotherId = MockActionInfo.getNextId() ;
+    }
+    
+    public Message process(Message message) throws ActionProcessingException
+    {
+        throw new NullPointerException();
+    }
+    
+    public Message anotherProcess(Message message) throws ActionProcessingException
+    {
+    	throw new NullPointerException();
+    }
+
+    public void processException(Message message, Throwable th)
+    {
+        MockActionInfo.addExceptionId(id) ;
+    }
+
+    public void anotherProcessException(Message message, Throwable th)
+    {
+        MockActionInfo.addExceptionId(anotherId) ;
+    }
+
+    public void processSuccess(Message message)
+    {
+        MockActionInfo.addSuccessId(id) ;
+    }
+
+    public void anotherProcessSuccess(Message message)
+    {
+        MockActionInfo.addSuccessId(anotherId) ;
+    }
+
+    public void destroy() throws ActionLifecycleException
+    {
+        MockActionInfo.addDestroyId(id) ;
+    }
+
+    public void initialise() throws ActionLifecycleException
+    {
+        MockActionInfo.addInitialiseId(id) ;
+    }
+}




More information about the jboss-svn-commits mailing list