camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wilson, Chad (Equity Technology)" <c.wil...@baml.com>
Subject RE: Issue with route specific onException and jms component
Date Fri, 24 Dec 2010 10:39:16 GMT
Attachment appear to be nuked - here's the test I'm working with.

-------------------------------------------------------------
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.component.jms.JmsConfiguration;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

import com.tibco.tibjms.TibjmsConnectionFactory;

public class Camel25ExceptionChangeTest extends CamelTestSupport {

	@Produce(uri = "direct:entry")
	protected ProducerTemplate entry;

	@Produce(uri = "direct:secondaryEntry")
	protected ProducerTemplate secondaryEntry;

	@EndpointInject(uri = "mock:mainEnd")
	protected MockEndpoint mainEnd;

	@EndpointInject(uri = "mock:secondaryEnd")
	protected MockEndpoint secondaryEnd;

	@EndpointInject(uri = "mock:mainErrors")
	protected MockEndpoint mainErrors;

	@EndpointInject(uri = "mock:secondaryErrors")
	protected MockEndpoint secondaryErrors;

	@Override
	protected RouteBuilder createRouteBuilder() throws Exception {
		return new RouteBuilder() {
			@Override
			public void configure() throws Exception {

				// Primary route (like an input route)
				from("direct:entry")
					.onException(Exception.class)
						.handled(true)
						.to("mock:mainErrors")
						.end()

					// This bean generates a new
message to go down the secondary route over JMS
					.bean(new
ProducingBean(secondaryEntry))
					.to("mock:mainEnd")
					.routeId("mainRoute");

				// Secondary route that is invoked by
producing bean
				from("direct:secondaryEntry")
					.onException(Exception.class)
						.handled(true)
	
.to("mock:secondaryErrors")
						.end()
	
.recipientList(simple("jms:topic:SOMETOPIC"))
					.to("mock:secondaryEnd")
					.routeId("secondaryRoute");
			}
		};
	}

	@Test
	public void testExceptionHandlingChanges() throws Exception {

		// Create a JMS component with an invalid host name
		context.addComponent("jms", new JmsComponent(new
JmsConfiguration(new
TibjmsConnectionFactory("tcp://hostthatdoesntexist:7222"))));

		// Expect original mesage to be correctly delivered
since error on secondary route is handled inside that route
		mainEnd.expectedMessageCount(1);
		mainErrors.expectedMessageCount(0);

		// Expect an error on this route generated from jms
component
		secondaryEnd.expectedMessageCount(0);
		secondaryErrors.expectedMessageCount(1);

		entry.sendBody("message1");

		assertMockEndpointsSatisfied();
		
		assertEquals("Expect no messages stuck in flight...", 0,
context.getInflightRepository().size());
	}

	public static class ProducingBean {

		private ProducerTemplate sendTo;

		public ProducingBean(ProducerTemplate sendTo) {
			this.sendTo = sendTo;
		}

		public void produce(String message) {
			sendTo.sendBody("REPLY-TO-"+message);
		}
	}

}

----------------------------------------------------------------------
This message w/attachments (message) is intended solely for the use of the intended recipient(s)
and may contain information that is privileged, confidential or proprietary. If you are not
an intended recipient, please notify the sender, and then please delete and destroy all copies
and attachments, and be advised that any review or dissemination of, or the taking of any
action in reliance on, the information contained in or attached to this message is prohibited.

Unless specifically indicated, this message is not an offer to sell or a solicitation of any
investment products or other financial product or service, an official confirmation of any
transaction, or an official statement of Sender. Subject to applicable law, Sender may intercept,
monitor, review and retain e-communications (EC) traveling through its networks/systems and
may produce any such EC to regulators, law enforcement, in litigation and as required by law.

The laws of the country of each sender/recipient may impact the handling of EC, and EC may
be archived, supervised and produced in countries other than the country in which you are
located. This message cannot be guaranteed to be secure or free of errors or viruses. 

References to "Sender" are references to any subsidiary of Bank of America Corporation. Securities
and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value
* Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not
Insured by Any Federal Government Agency. Attachments that are part of this EC may have additional
important disclosures and disclaimers, which you should read. This message is subject to terms
available at the following link: 
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you consent to the
foregoing.

Mime
View raw message