Author: davsclaus Date: Mon Jul 19 13:35:50 2010 New Revision: 965474 URL: http://svn.apache.org/viewvc?rev=965474&view=rev Log: CAMEL-2965: Moving to DLC forces using MEP InOnly. Added tests to Spring XML showing using custom predicate and expression.
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomExpressionTest.java (with props) camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomPredicateTest.java (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomExpressionTest.xml (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomPredicateTest.xml - copied, changed from r965438, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopbefore.xml Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java?rev=965474&r1=965473&r2=965474&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java Mon Jul 19 13:35:50 2010 @@ -33,13 +33,17 @@ import java.util.concurrent.locks.Reentr import org.apache.camel.CamelContext; import org.apache.camel.CamelExchangeException; +import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; import org.apache.camel.Expression; import org.apache.camel.Navigate; +import org.apache.camel.NoSuchEndpointException; import org.apache.camel.Predicate; import org.apache.camel.Processor; import org.apache.camel.impl.LoggingExceptionHandler; import org.apache.camel.impl.ServiceSupport; +import org.apache.camel.processor.SendProcessor; import org.apache.camel.processor.Traceable; import org.apache.camel.spi.AggregationRepository; import org.apache.camel.spi.ExceptionHandler; @@ -772,7 +776,14 @@ public class AggregateProcessor extends throw new IllegalArgumentException("Option maximumRedeliveries must be a positive number, was: " + max); } LOG.info("After " + max + " failed redelivery attempts Exchanges will be moved to deadLetterUri: " + recoverable.getDeadLetterUri()); - deadLetterProcessor = camelContext.getEndpoint(recoverable.getDeadLetterUri()).createProducer(); + + // dead letter uri must be a valid endpoint + Endpoint endpoint = camelContext.getEndpoint(recoverable.getDeadLetterUri()); + if (endpoint == null) { + throw new NoSuchEndpointException(recoverable.getDeadLetterUri()); + } + // force MEP to be InOnly so when sending to DLQ we would not expect a reply if the MEP was InOut + deadLetterProcessor = new SendProcessor(endpoint, ExchangePattern.InOnly); ServiceHelper.startService(deadLetterProcessor); } } Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomExpressionTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomExpressionTest.java?rev=965474&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomExpressionTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomExpressionTest.java Mon Jul 19 13:35:50 2010 @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.processor; + +import org.apache.camel.Exchange; +import org.apache.camel.impl.ExpressionAdapter; +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class SpringCustomExpressionTest extends SpringTestSupport { + + public void testTransformMyExpression() throws InterruptedException { + getMockEndpoint("mock:result").expectedBodiesReceived("Yes Camel rocks", "Hello World"); + + template.sendBody("direct:start", "Camel"); + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringCustomExpressionTest.xml"); + } + + public static class MyExpression extends ExpressionAdapter { + + @Override + public Object evaluate(Exchange exchange) { + String body = exchange.getIn().getBody(String.class); + if (body.contains("Camel")) { + return "Yes Camel rocks"; + } else { + return "Hello " + body; + } + } + } + +} \ No newline at end of file Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomExpressionTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomExpressionTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomPredicateTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomPredicateTest.java?rev=965474&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomPredicateTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomPredicateTest.java Mon Jul 19 13:35:50 2010 @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.processor; + +import org.apache.camel.Exchange; +import org.apache.camel.Predicate; +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class SpringCustomPredicateTest extends SpringTestSupport { + + public void testFilterMyPredicate() throws InterruptedException { + getMockEndpoint("mock:foo").expectedBodiesReceived("Hello Camel", "Secret Agent"); + getMockEndpoint("mock:result").expectedBodiesReceived("Hello Camel", "Hello World", "Secret Agent"); + + template.sendBody("direct:start", "Hello Camel"); + template.sendBody("direct:start", "Hello World"); + template.sendBody("direct:start", "Secret Agent"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringCustomPredicateTest.xml"); + } + + public static class MyPredicate implements Predicate { + + public boolean matches(Exchange exchange) { + String body = exchange.getIn().getBody(String.class); + if (body.contains("Camel")) { + return true; + } else if (body.startsWith("Secret")) { + return true; + } + + return false; + } + } +} Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomPredicateTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringCustomPredicateTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomExpressionTest.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomExpressionTest.xml?rev=965474&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomExpressionTest.xml (added) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomExpressionTest.xml Mon Jul 19 13:35:50 2010 @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <bean id="myExpression" class="org.apache.camel.spring.processor.SpringCustomExpressionTest$MyExpression"/> + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <transform> + <method ref="myExpression"/> + </transform> + <to uri="mock:result"/> + </route> + </camelContext> + +</beans> Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomExpressionTest.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomExpressionTest.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomExpressionTest.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomPredicateTest.xml (from r965438, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopbefore.xml) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomPredicateTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomPredicateTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopbefore.xml&r1=965438&r2=965474&rev=965474&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopbefore.xml (original) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringCustomPredicateTest.xml Mon Jul 19 13:35:50 2010 @@ -22,16 +22,17 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd "> - <!-- START SNIPPET: e1 --> + <bean id="myPredicate" class="org.apache.camel.spring.processor.SpringCustomPredicateTest$MyPredicate"/> + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> - <aop beforeUri="mock:before"> - <transform><constant>Bye World</constant></transform> - <to uri="mock:result"/> - </aop> + <filter> + <method ref="myPredicate"/> + <to uri="mock:foo"/> + </filter> + <to uri="mock:result"/> </route> </camelContext> - <!-- END SNIPPET: e1 --> </beans>