[jboss-svn-commits] JBL Code SVN: r23249 - in labs/jbossesb/workspace/skeagh/runtime/src: test/java/org/jboss/esb/routing/scenario_014 and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Oct 1 12:53:53 EDT 2008
Author: tfennelly
Date: 2008-10-01 12:53:53 -0400 (Wed, 01 Oct 2008)
New Revision: 23249
Added:
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/01-deployment.xml
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/RoutingTest.java
Modified:
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/dispatch/AbstractDispatcher.java
Log:
more tests... exception in the outrouter
Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/dispatch/AbstractDispatcher.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/dispatch/AbstractDispatcher.java 2008-10-01 16:53:51 UTC (rev 23248)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/dispatch/AbstractDispatcher.java 2008-10-01 16:53:53 UTC (rev 23249)
@@ -26,7 +26,6 @@
import org.jboss.esb.context.InvocationContext;
import org.jboss.esb.deploy.config.OutboundRouterConfig;
import org.jboss.esb.deploy.config.ServiceConfig;
-import org.jboss.esb.service.ServiceMEP;
import org.jboss.esb.failure.DeadLetterPersistanceService;
import org.jboss.esb.federate.bus.BusMessage;
import org.jboss.esb.federate.bus.BusOutboundRouter;
@@ -39,10 +38,11 @@
import org.jboss.esb.routing.OutboundRouter;
import org.jboss.esb.routing.RoutingException;
import org.jboss.esb.routing.ServiceInvoker;
+import org.jboss.esb.serialization.SerializationException;
+import org.jboss.esb.serialization.java.JavaSerializer;
import org.jboss.esb.service.ServiceException;
+import org.jboss.esb.service.ServiceMEP;
import org.jboss.esb.service.ServiceName;
-import org.jboss.esb.serialization.java.JavaSerializer;
-import org.jboss.esb.serialization.SerializationException;
import java.util.ArrayList;
import java.util.Collections;
@@ -207,9 +207,9 @@
ProcessingEventLog.getEventLog().logEvent(new ServiceProcessingEvent(getServiceName()));
// If we need to send a reply, send it now...
- if(outMessage != null && replyTo != null)
+ if (outMessage != null && replyTo != null)
{
- if(service.getServiceMEP() == ServiceMEP.InOut)
+ if (service.getServiceMEP() == ServiceMEP.InOut)
{
serviceInvoker.send(outMessage, replyTo);
}
@@ -292,7 +292,7 @@
}
catch (Throwable t)
{
- logger.error("Exception routing message to Service '" + addressContext.getTo() + "' via OutboundRouter. Router Configuration '" + outboundRouterConfig.getName() + "'. Routing to Dead Letter Service '" + DeadLetterPersistanceService.SERVICE_NAME + "'.", t);
+ logger.debug("Exception routing message to Service '" + addressContext.getTo() + "' via OutboundRouter. Router Configuration '" + outboundRouterConfig.getName() + "'. Routing to Dead Letter Service '" + DeadLetterPersistanceService.SERVICE_NAME + "'.", t);
routeToDeadLetterService(outMessage, t);
}
// In this case, we don't pass the message to the outrouters (below).
@@ -310,15 +310,7 @@
// Create a clone of the message in case there's an error or
// there are multiple outrouters with processors on them...
- Message clone;
- try
- {
- clone = JavaSerializer.copy(outMessage);
- }
- catch (SerializationException e)
- {
- throw new RuntimeException("Cannot route message. Unable to copy message.", e);
- }
+ Message clone = cloneMessage(outMessage);
if (outRouter instanceof BusOutboundRouter)
{
@@ -330,7 +322,10 @@
}
catch (Throwable t)
{
- logger.error("Exception routing message to remote OutboundRouter for Service '" + addressContext.getTo() + "' via OutboundRouter. Router Configuration '" + outboundRouterConfig.getName() + "'. Routing to Dead Letter Service '" + DeadLetterPersistanceService.SERVICE_NAME + "'.", t);
+ logger.debug("Exception routing message to remote OutboundRouter for Service '" + addressContext.getTo() + "' via OutboundRouter. Router Configuration '" + outboundRouterConfig.getName() + "'. Routing to Dead Letter Service '" + DeadLetterPersistanceService.SERVICE_NAME + "'.", t);
+ // Copy the original message again in case there were any mods
+ // made to it in the router...
+ clone = cloneMessage(outMessage);
routeToDeadLetterService(clone, t);
}
}
@@ -343,9 +338,10 @@
}
catch (Throwable t)
{
- logger.error("Exception applying message processors on OutboundRouter for Service '" + addressContext.getTo() + "' via OutboundRouter. Router Configuration '" + outboundRouterConfig.getName() + "'. Routing to Dead Letter Service '" + DeadLetterPersistanceService.SERVICE_NAME + "'.", t);
- // We route the clone because it's unmodified... allows us to
- // start from scratch again...
+ logger.debug("Exception applying message processors on OutboundRouter for Service '" + addressContext.getTo() + "' via OutboundRouter. Router Configuration '" + outboundRouterConfig.getName() + "'. Routing to Dead Letter Service '" + DeadLetterPersistanceService.SERVICE_NAME + "'.", t);
+ // Copy the original message again in case there were any mods
+ // made to it in the processors...
+ clone = cloneMessage(outMessage);
routeToDeadLetterService(clone, t);
continue;
}
@@ -358,9 +354,10 @@
}
catch (Throwable t)
{
- logger.error("Exception routing message to OutboundRouter for Service '" + addressContext.getTo() + "' via OutboundRouter. Router Configuration '" + outboundRouterConfig.getName() + "'. Routing to Dead Letter Service '" + DeadLetterPersistanceService.SERVICE_NAME + "'.", t);
- // We route the clone because it's unmodified... allows us to
- // start from scratch again...
+ logger.debug("Exception routing message to OutboundRouter for Service '" + addressContext.getTo() + "' via OutboundRouter. Router Configuration '" + outboundRouterConfig.getName() + "'. Routing to Dead Letter Service '" + DeadLetterPersistanceService.SERVICE_NAME + "'.", t);
+ // Copy the original message again in case there were any mods
+ // made to it in the router...
+ clone = cloneMessage(outMessage);
routeToDeadLetterService(clone, t);
}
}
@@ -370,9 +367,26 @@
}
/**
+ * Create a full clone of the supplied message.
+ * @param message The message to be cloned.
+ * @return A full clone of the message.
+ */
+ private Message cloneMessage(final Message message)
+ {
+ try
+ {
+ return JavaSerializer.copy(message);
+ }
+ catch (SerializationException e)
+ {
+ throw new RuntimeException("Cannot route message. Unable to copy message.", e);
+ }
+ }
+
+ /**
* Apply the supplied set of processors on the supplied message.
*
- * @param outMessage The message.
+ * @param outMessage The message.
* @param outboundProcessors The processors to be applied.
* @throws org.jboss.esb.routing.RoutingException
* Error applying processor.
@@ -501,7 +515,7 @@
{
AddressingContext addressingContext = AddressingContext.getContext();
- if(addressingContext.getTo().equals(DeadLetterPersistanceService.SERVICE_NAME))
+ if (addressingContext.getTo().equals(DeadLetterPersistanceService.SERVICE_NAME))
{
return false;
}
Copied: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/01-deployment.xml (from rev 23246, labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_012/01-deployment.xml)
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/01-deployment.xml (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/01-deployment.xml 2008-10-01 16:53:53 UTC (rev 23249)
@@ -0,0 +1,12 @@
+<jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd">
+
+ <services>
+
+ <service serviceCategory="Service" serviceName="A" serviceDescription="A Service" class="org.jboss.esb.TestService" mep="In-Out">
+ <inRouter name="inrouter" class="org.jboss.esb.TestInboundRouter" />
+ <outRouter name="outrouter" class="org.jboss.esb.TestOutboundRouter" />
+ </service>
+
+ </services>
+
+</jbossesb>
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/01-deployment.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/RoutingTest.java (from rev 23246, labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_011/RoutingTest.java)
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/RoutingTest.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/routing/scenario_014/RoutingTest.java 2008-10-01 16:53:53 UTC (rev 23249)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.routing.scenario_014;
+
+import junit.framework.TestCase;
+import org.jboss.esb.TestInboundRouter;
+import org.jboss.esb.TestOutboundRouter;
+import org.jboss.esb.TestService;
+import org.jboss.esb.deploy.DeploymentRuntime;
+import org.jboss.esb.deploy.DeploymentUtil;
+import org.jboss.esb.failure.DeadLetterPersistanceService;
+import org.jboss.esb.failure.MockDeadLetterService;
+import org.jboss.esb.federate.bus.BusMessage;
+import org.jboss.esb.jms.JmsTestRunner;
+import org.jboss.esb.routing.RoutingException;
+import org.jboss.esb.service.ServiceName;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class RoutingTest extends TestCase
+{
+
+ /*
+ * The message should go:
+ * [inrouter_ServiceA -> ServiceA -> outrouter_ServiceA] -|
+ * [DeadLetterService] <-|
+ *
+ * RoutingException inside the outrouter... should route to the DLS.
+ */
+ public void test() throws Exception
+ {
+ new JmsTestRunner() {
+ @Override
+ public void test() throws Exception
+ {
+ ServiceName serviceNameA = new ServiceName("Service", "A");
+ DeploymentRuntime deployment1 = DeploymentUtil.createRuntime(getClass().getResourceAsStream("01-deployment.xml"));
+
+ deployment1.setDeploymentName("deployment1");
+ deployment1.setDeploymentId("deployment1-Id");
+ deployment1.deploy();
+ try
+ {
+ TestInboundRouter inrouter = (TestInboundRouter) DeploymentUtil.getInboundRouter(serviceNameA, "inrouter", deployment1).getRouter();
+ TestService serviceA = (TestService) DeploymentUtil.getService(serviceNameA, deployment1).getService();
+ TestOutboundRouter outrouter = (TestOutboundRouter) DeploymentUtil.getOutboundRouter(serviceNameA, "outrouter", deployment1).getRouter();
+ MockDeadLetterService dlService = (MockDeadLetterService) DeploymentUtil.getService(DeadLetterPersistanceService.SERVICE_NAME, deployment1).getService();
+ String faultString = "A Routing Exception - should route to DLS.";
+
+ outrouter.setThrowException(new RoutingException(faultString));
+ dlService.setExpectingMessages(true);
+
+ inrouter.sendMessage("Hi there!!", true);
+
+ serviceA.waitForMessage(10000);
+
+ // Check that the message has been routed across deployments, from the inrouter
+ // to the service instance and then to the outrouter...
+ assertEquals("Hi there!!", serviceA.getMessage());
+ BusMessage dlsMessage = (BusMessage) dlService.getMessages().peek().getPayload();
+ assertEquals("Hi there!!", dlsMessage.getMessage().getPayload());
+ assertEquals("Service:A", dlsMessage.getAddressingContext().getFrom().toString()); // The service was applied, so the from address should reflect this.
+ assertEquals("Service:A", dlsMessage.getAddressingContext().getTo().toString());
+ assertTrue(dlsMessage.getFault() instanceof RoutingException);
+ assertEquals(faultString, dlsMessage.getFault().getMessage());
+ }
+ finally
+ {
+ deployment1.undeploy();
+ }
+ }
+ }.run();
+ }
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list