You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/02/19 12:54:31 UTC
svn commit: r745826 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/model/
camel-core/src/main/java/org/apache/camel/util/
camel-core/src/main/resources/org/apache/camel/model/
camel-core/src/test/java/org/apache/camel/processor/ component...
Author: davsclaus
Date: Thu Feb 19 11:54:30 2009
New Revision: 745826
URL: http://svn.apache.org/viewvc?rev=745826&view=rev
Log:
CAMEL-879: Fixed intercept in spring DSL not working with predicate and having stop/proceed. In fact better initialization of interceptor in Spring DSL.
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/StopType.java (with props)
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenNoStopTest.java
- copied, changed from r745749, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenWithChoiceTest.java (contents, props changed)
- copied, changed from r745749, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenTest.java (contents, props changed)
- copied, changed from r745506, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.java (with props)
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml (with props)
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenTest.xml (contents, props changed)
- copied, changed from r745506, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java?rev=745826&r1=745825&r2=745826&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java Thu Feb 19 11:54:30 2009
@@ -16,8 +16,8 @@
*/
package org.apache.camel.model;
+import java.util.ArrayList;
import java.util.List;
-
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@@ -94,9 +94,49 @@
setStopIntercept(Boolean.TRUE);
}
- @XmlElement(name = "stop", required = false)
- public void setStop(String elementValue /* not used */) {
- stopIntercept();
+ /**
+ * This method is <b>only</b> for handling some post configuration
+ * that is needed from the Spring DSL side as JAXB does not invoke the fluent
+ * builders, so we need to manually handle this afterwards, and since this is
+ * an interceptor it has to do a bit of magic logic to fixup to handle predicates
+ * with or without proceed/stop set as well.
+ */
+ public void afterPropertiesSet() {
+ List<ProcessorType> list = new ArrayList<ProcessorType>();
+ for (ProcessorType out : outputs) {
+ if (out instanceof WhenType) {
+ // JAXB does not invoke the when() fluent builder so we need to wrap the when in
+ // a choice with the proceed as the when for the Java DSL does
+ WhenType when = (WhenType) out;
+ usePredicate = Boolean.TRUE;
+ ChoiceType choice = new ChoiceType();
+ choice.when(PredicateBuilder.not(when.getExpression()));
+ choice.addOutput(proceed);
+ list.add(choice);
+
+ ChoiceType otherwise = choice.otherwise();
+ // add the children to the otherwise
+ for (ProcessorType child : when.getOutputs()) {
+ if (child instanceof StopType) {
+ // notify we should stop
+ stopIntercept();
+ } else {
+ otherwise.addOutput(child);
+ }
+ }
+ } else if (out instanceof StopType) {
+ // notify we shuld stop
+ stopIntercept();
+ } else {
+ list.add(out);
+ }
+ }
+
+ // replace old output with this redone output list
+ outputs.clear();
+ for (ProcessorType out : list) {
+ addOutput(out);
+ }
}
public InterceptType createProxy() {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java?rev=745826&r1=745825&r2=745826&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/OutputType.java Thu Feb 19 11:54:30 2009
@@ -60,14 +60,5 @@
output.setErrorHandlerBuilder(getErrorHandlerBuilder());
}
// don't inherit interceptors by default
-/*
- List<InterceptorType> list = output.getInterceptors();
- if (list == null) {
- log.warn("No interceptor collection: " + output);
- }
- else {
- list.addAll(getInterceptors());
- }
-*/
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java?rev=745826&r1=745825&r2=745826&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProceedType.java Thu Feb 19 11:54:30 2009
@@ -48,6 +48,6 @@
@Override
public String toString() {
- return getShortName();
+ return "proceed[" + getOutputs() + "]";
}
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=745826&r1=745825&r2=745826&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java Thu Feb 19 11:54:30 2009
@@ -784,184 +784,6 @@
}
/**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param aggregationStrategy the strategy used to aggregate responses for every part
- * @return the expression clause for the expression on which to split
- * @deprecated will be removed in Camel 2.0
- */
- public ExpressionClause<SplitterType> split(AggregationStrategy aggregationStrategy) {
- SplitterType answer = new SplitterType();
- addOutput(answer);
- answer.setAggregationStrategy(aggregationStrategy);
- return ExpressionClause.createAndSetExpression(answer);
- }
-
- /**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param expression the expression on which to split
- * @param parallelProcessing if is <tt>true</tt> camel will fork thread to call the endpoint producer
- * @return the builder
- * @deprecated will be removed in Camel 2.0
- */
- public SplitterType split(Expression expression, boolean parallelProcessing) {
- SplitterType answer = new SplitterType(expression);
- addOutput(answer);
- answer.setParallelProcessing(parallelProcessing);
- return answer;
- }
-
- /**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param expression the expression on which to split
- * @param parallelProcessing if is <tt>true</tt> camel will fork thread to call the endpoint producer
- * @param executor override the default {@link Executor}
- * @return the builder
- * @deprecated will be removed in Camel 2.0
- */
- public SplitterType split(Expression expression, boolean parallelProcessing,
- Executor executor) {
- SplitterType answer = new SplitterType(expression);
- addOutput(answer);
- answer.setParallelProcessing(parallelProcessing);
- answer.setExecutor(executor);
- return answer;
- }
-
- /**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param parallelProcessing if is <tt>true</tt> camel will fork thread to call the endpoint producer
- * @return the expression clause for the expression on which to split
- * @deprecated will be removed in Camel 2.0
- */
- public ExpressionClause<SplitterType> split(boolean parallelProcessing) {
- SplitterType answer = new SplitterType();
- addOutput(answer);
- answer.setParallelProcessing(parallelProcessing);
- return ExpressionClause.createAndSetExpression(answer);
- }
-
- /**
- /**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param parallelProcessing if is <tt>true</tt> camel will fork thread to call the endpoint producer
- * @param executor override the default {@link Executor}
- * @return the expression clause for the expression on which to split
- * @deprecated will be removed in Camel 2.0
- */
- public ExpressionClause<SplitterType> split(boolean parallelProcessing, Executor executor) {
- SplitterType answer = new SplitterType();
- addOutput(answer);
- answer.setParallelProcessing(parallelProcessing);
- answer.setExecutor(executor);
- return ExpressionClause.createAndSetExpression(answer);
- }
-
- /**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param expression the expression on which to split
- * @param aggregationStrategy the strategy used to aggregate responses for every part
- * @param parallelProcessing if is <tt>true</tt> camel will fork thread to call the endpoint producer
- * @return the builder
- * @deprecated will be removed in Camel 2.0
- */
- public SplitterType split(Expression expression, AggregationStrategy aggregationStrategy,
- boolean parallelProcessing) {
- SplitterType answer = new SplitterType(expression);
- addOutput(answer);
- answer.setAggregationStrategy(aggregationStrategy);
- answer.setParallelProcessing(parallelProcessing);
- return answer;
- }
-
- /**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param expression the expression on which to split
- * @param aggregationStrategy the strategy used to aggregate responses for every part
- * @param parallelProcessing if is <tt>true</tt> camel will fork thread to call the endpoint producer
- * @param executor override the default {@link Executor}
- * @return the builder
- * @deprecated will be removed in Camel 2.0
- */
- public SplitterType split(Expression expression, AggregationStrategy aggregationStrategy,
- boolean parallelProcessing, Executor executor) {
- SplitterType answer = new SplitterType(expression);
- addOutput(answer);
- answer.setAggregationStrategy(aggregationStrategy);
- answer.setParallelProcessing(parallelProcessing);
- answer.setExecutor(executor);
- return answer;
- }
-
- /**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param aggregationStrategy the strategy used to aggregate responses for every part
- * @param parallelProcessing if is <tt>true</tt> camel will fork thread to call the endpoint producer
- * @return the expression clause for the expression on which to split
- * @deprecated will be removed in Camel 2.0
- */
- public ExpressionClause<SplitterType> split(AggregationStrategy aggregationStrategy, boolean parallelProcessing) {
- SplitterType answer = new SplitterType();
- addOutput(answer);
- answer.setAggregationStrategy(aggregationStrategy);
- answer.setParallelProcessing(parallelProcessing);
- return ExpressionClause.createAndSetExpression(answer);
- }
-
- /**
- * <a href="http://camel.apache.org/splitter.html">Splitter EIP:</a>
- * Creates a splitter allowing you split a message into a number of pieces and process them individually.
- * <p>
- * The splitter responds with the answer produced by the given {@link AggregationStrategy}.
- *
- * @param aggregationStrategy the strategy used to aggregate responses for every part
- * @param parallelProcessing if is <tt>true</tt> camel will fork thread to call the endpoint producer
- * @param executor override the default {@link Executor}
- * @return the expression clause for the expression on which to split
- * @deprecated will be removed in Camel 2.0
- */
- public ExpressionClause<SplitterType> split(AggregationStrategy aggregationStrategy, boolean parallelProcessing,
- Executor executor) {
- SplitterType answer = new SplitterType();
- addOutput(answer);
- answer.setAggregationStrategy(aggregationStrategy);
- answer.setParallelProcessing(parallelProcessing);
- answer.setExecutor(executor);
- return ExpressionClause.createAndSetExpression(answer);
- }
-
- /**
* <a href="http://camel.apache.org/resequencer.html">Resequencer EIP:</a>
* Creates a resequencer allowing you to reorganize messages based on some comparator.
*
@@ -2113,8 +1935,8 @@
List<Processor> list = new ArrayList<Processor>();
for (ProcessorType output : outputs) {
Processor processor = output.createProcessor(routeContext);
- // if the ProceedType create processor is null we keep on going
- if (output instanceof ProceedType && processor == null) {
+ // if the ProceedType/StopType create processor is null we keep on going
+ if ((output instanceof ProceedType || output instanceof StopType) && processor == null) {
continue;
}
processor = output.wrapProcessorInInterceptors(routeContext, processor);
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/StopType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/StopType.java?rev=745826&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/StopType.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/StopType.java Thu Feb 19 11:54:30 2009
@@ -0,0 +1,55 @@
+/**
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Processor;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * Represents an XML <stop/> element
+ *
+ * @version $Revision$
+ */
+@XmlRootElement(name = "stop")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class StopType extends OutputType<ProcessorType> {
+
+ @Override
+ public String getShortName() {
+ return "stop";
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ // stop does not have any processor
+ return null;
+ }
+
+ @Override
+ public String getLabel() {
+ return getShortName();
+ }
+
+ @Override
+ public String toString() {
+ return getShortName();
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/StopType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/StopType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java?rev=745826&r1=745825&r2=745826&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java Thu Feb 19 11:54:30 2009
@@ -38,9 +38,6 @@
* Creates a {@link PollingConsumer} and polls all pending messages on the endpoint
* and invokes the given {@link Processor} to process each {@link Exchange} and then closes
* down the consumer and throws any exceptions thrown.
- *
- * @param endpoint
- * @param processor
*/
public static void pollEndpoint(Endpoint endpoint, Processor processor, long timeout) throws Exception {
PollingConsumer consumer = endpoint.createPollingConsumer();
@@ -69,9 +66,6 @@
* endpoint and invokes the given {@link Processor} to process each
* {@link Exchange} and then closes down the consumer and throws any
* exceptions thrown.
- *
- * @param endpoint
- * @param processor
*/
public static void pollEndpoint(Endpoint endpoint, Processor processor) throws Exception {
pollEndpoint(endpoint, processor, 1000L);
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java?rev=745826&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java Thu Feb 19 11:54:30 2009
@@ -0,0 +1,81 @@
+/**
+ * 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.util;
+
+import java.util.List;
+
+import org.apache.camel.model.ChoiceType;
+import org.apache.camel.model.ProcessorType;
+import org.apache.camel.model.WhenType;
+
+/**
+ * Helper class for ProcessorType and the other model classes.
+ */
+public final class ProcessorTypeHelper {
+
+ private ProcessorTypeHelper() {
+ }
+
+ /**
+ * Looks for the given type in the list of outputs and recurring all the children as well.
+ * Will stop at first found and return it.
+ *
+ * @param outputs list of outputs, can be null or empty.
+ * @param type the type to look for
+ * @return the first found type, or <tt>null</tt> if not found
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T findFirstTypeInOutputs(List<ProcessorType> outputs, Class<T> type) {
+ if (outputs == null || outputs.isEmpty()) {
+ return null;
+ }
+
+ for (ProcessorType out : outputs) {
+ if (type.isInstance(out)) {
+ return type.cast(out);
+ }
+
+ // special for choice
+ if (out instanceof ChoiceType) {
+ ChoiceType choice = (ChoiceType) out;
+ for (WhenType when : choice.getWhenClauses()) {
+ List<ProcessorType> children = when.getOutputs();
+ T child = findFirstTypeInOutputs(children, type);
+ if (child != null) {
+ return child;
+ }
+ }
+
+ List<ProcessorType> children = choice.getOtherwise().getOutputs();
+ T child = findFirstTypeInOutputs(children, type);
+ if (child != null) {
+ return child;
+ }
+ }
+
+ // try children as well
+ List<ProcessorType> children = out.getOutputs();
+ T child = findFirstTypeInOutputs(children, type);
+ if (child != null) {
+ return child;
+ }
+ }
+
+ return null;
+ }
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index?rev=745826&r1=745825&r2=745826&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index (original)
+++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index Thu Feb 19 11:54:30 2009
@@ -59,6 +59,7 @@
SetOutHeaderType
SetPropertyType
SplitterType
+StopType
ThrottlerType
ThreadType
ThrowFaultType
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenNoStopTest.java (from r745749, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenNoStopTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenNoStopTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenTest.java&r1=745749&r2=745826&rev=745826&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenNoStopTest.java Thu Feb 19 11:54:30 2009
@@ -24,7 +24,7 @@
/**
* @version $Revision$
*/
-public class InterceptWhenTest extends ContextTestSupport {
+public class InterceptWhenNoStopTest extends ContextTestSupport {
public void testInterceptorWhen() throws Exception {
getMockEndpoint("mock:goofy").expectedMessageCount(0);
@@ -37,7 +37,7 @@
public void testInterceptorWhenGoofy() throws Exception {
getMockEndpoint("mock:goofy").expectedMessageCount(1);
- getMockEndpoint("mock:end").expectedMessageCount(0);
+ getMockEndpoint("mock:end").expectedMessageCount(1);
sendBody("direct:start", "Hello Goofy");
@@ -49,7 +49,7 @@
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- intercept().when(toPredicate(simple("${body} contains 'Goofy'"))).to("mock:goofy").stop();
+ intercept().when(toPredicate(simple("${body} contains 'Goofy'"))).to("mock:goofy");
from("direct:start").to("mock:end");
}
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenWithChoiceTest.java (from r745749, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenWithChoiceTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenWithChoiceTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenTest.java&r1=745749&r2=745826&rev=745826&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenWithChoiceTest.java Thu Feb 19 11:54:30 2009
@@ -24,10 +24,12 @@
/**
* @version $Revision$
*/
-public class InterceptWhenTest extends ContextTestSupport {
+public class InterceptWhenWithChoiceTest extends ContextTestSupport {
- public void testInterceptorWhen() throws Exception {
+ public void testInterceptorHelloWorld() throws Exception {
getMockEndpoint("mock:goofy").expectedMessageCount(0);
+ getMockEndpoint("mock:hello").expectedMessageCount(0);
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:end").expectedMessageCount(1);
sendBody("direct:start", "Hello World!");
@@ -35,8 +37,10 @@
assertMockEndpointsSatisfied();
}
- public void testInterceptorWhenGoofy() throws Exception {
- getMockEndpoint("mock:goofy").expectedMessageCount(1);
+ public void testInterceptorHelloGoofy() throws Exception {
+ getMockEndpoint("mock:goofy").expectedMessageCount(0);
+ getMockEndpoint("mock:hello").expectedMessageCount(1);
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
getMockEndpoint("mock:end").expectedMessageCount(0);
sendBody("direct:start", "Hello Goofy");
@@ -44,14 +48,31 @@
assertMockEndpointsSatisfied();
}
+ public void testInterceptorByeGoofy() throws Exception {
+ getMockEndpoint("mock:goofy").expectedMessageCount(1);
+ getMockEndpoint("mock:hello").expectedMessageCount(0);
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:end").expectedMessageCount(0);
+
+ sendBody("direct:start", "Bye Goofy");
+
+ assertMockEndpointsSatisfied();
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- intercept().when(toPredicate(simple("${body} contains 'Goofy'"))).to("mock:goofy").stop();
+ intercept()
+ .when(toPredicate(simple("${body} contains 'Goofy'")))
+ .choice()
+ .when(body().contains("Hello")).to("mock:hello")
+ .otherwise().to("mock:goofy")
+ .end()
+ .stop();
- from("direct:start").to("mock:end");
+ from("direct:start").to("mock:foo").to("mock:end");
}
};
}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenWithChoiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWhenWithChoiceTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=745826&r1=745825&r2=745826&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Thu Feb 19 11:54:30 2009
@@ -49,6 +49,7 @@
import org.apache.camel.processor.interceptor.Tracer;
import org.apache.camel.spi.LifecycleStrategy;
import org.apache.camel.spi.Registry;
+import org.apache.camel.util.ProcessorTypeHelper;
import org.apache.camel.util.ResolverUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -64,7 +65,6 @@
import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;
-
/**
* A Spring {@link FactoryBean} to create and initialize a
* {@link SpringCamelContext} and install routes either explicitly configured in
@@ -217,17 +217,17 @@
// add exception handlers as top children
route.getOutputs().addAll(exceptionHandlers);
- // add the interceptor
+ // add the interceptor but we must do some pre configuration beforehand
+ intercept.afterPropertiesSet();
InterceptType proxy = intercept.createProxy();
route.addOutput(proxy);
route.pushBlock(proxy.getProceed());
- int outputsSize = proxy.getOutputs().size();
- if (outputsSize > 0) {
- ProcessorType processorType = proxy.getOutputs().get(outputsSize - 1);
- if (processorType instanceof ProceedType) {
- route.getOutputs().addAll(outputs);
- }
+ // if there is a proceed in the interceptor proxy then we should add
+ // the current outputs to out route so we will proceed and continue to route to them
+ ProceedType proceed = ProcessorTypeHelper.findFirstTypeInOutputs(proxy.getOutputs(), ProceedType.class);
+ if (proceed != null) {
+ proceed.getOutputs().addAll(outputs);
}
}
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.java?rev=745826&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.java Thu Feb 19 11:54:30 2009
@@ -0,0 +1,29 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.processor.InterceptWhenNoStopTest;
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringInterceptWhenNoStopTest extends InterceptWhenNoStopTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml");
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenTest.java (from r745506, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java&r1=745506&r2=745826&rev=745826&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenTest.java Thu Feb 19 11:54:30 2009
@@ -16,29 +16,14 @@
*/
package org.apache.camel.spring.processor;
-
import org.apache.camel.CamelContext;
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.component.mock.MockEndpoint;
-
+import org.apache.camel.processor.InterceptWhenTest;
import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
-public class SpringInterceptorWithStopTest extends ContextTestSupport {
-
- public void testSetInterceptorWithStop() throws Exception {
- MockEndpoint inteceptorEndpoint = getMockEndpoint("mock:middle1");
- MockEndpoint resultEndpoint = getMockEndpoint("mock:end");
- resultEndpoint.expectedMessageCount(0);
- inteceptorEndpoint.expectedBodiesReceived("Hello World!");
-
- sendBody("direct:start", "Hello World!");
-
- inteceptorEndpoint.assertIsSatisfied();
- resultEndpoint.assertIsSatisfied();
- }
+public class SpringInterceptWhenTest extends InterceptWhenTest {
protected CamelContext createCamelContext() throws Exception {
- return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml");
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringInterceptWhenTest.xml");
}
-}
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.java?rev=745826&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.java Thu Feb 19 11:54:30 2009
@@ -0,0 +1,29 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.processor.InterceptWhenWithChoiceTest;
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringInterceptWhenWithChoiceTest extends InterceptWhenWithChoiceTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml");
+ }
+
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml?rev=745826&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml Thu Feb 19 11:54:30 2009
@@ -0,0 +1,39 @@
+<?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
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <intercept>
+ <when>
+ <simple>${body} contains 'Goofy'</simple>
+ <to uri="mock:goofy"/>
+ </when>
+ </intercept>
+ <route>
+ <from uri="direct:start"/>
+ <to uri="mock:end"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
+</beans>
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenNoStopTest.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenTest.xml (from r745506, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml&r1=745506&r2=745826&rev=745826&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptorWithStopTest.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenTest.xml Thu Feb 19 11:54:30 2009
@@ -22,16 +22,19 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
- <!-- START SNIPPET: example -->
- <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
- <intercept>
- <to uri="mock:middle1"/>
- <stop/>
- </intercept>
- <route>
- <from uri="direct:start"/>
- <to uri="mock:end"/>
- </route>
- </camelContext>
- <!-- END SNIPPET: example -->
+ <!-- START SNIPPET: example -->
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <intercept>
+ <when>
+ <simple>${body} contains 'Goofy'</simple>
+ <to uri="mock:goofy"/>
+ <stop/>
+ </when>
+ </intercept>
+ <route>
+ <from uri="direct:start"/>
+ <to uri="mock:end"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
</beans>
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenTest.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenTest.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenTest.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml?rev=745826&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml Thu Feb 19 11:54:30 2009
@@ -0,0 +1,49 @@
+<?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
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <intercept>
+ <when>
+ <simple>${body} contains 'Goofy'</simple>
+ <choice>
+ <when>
+ <simple>${body} contains 'Hello'</simple>
+ <to uri="mock:hello"/>
+ </when>
+ <otherwise>
+ <to uri="mock:goofy"/>
+ </otherwise>
+ </choice>
+ <stop/>
+ </when>
+ </intercept>
+ <route>
+ <from uri="direct:start"/>
+ <to uri="mock:foo"/>
+ <to uri="mock:end"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
+</beans>
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringInterceptWhenWithChoiceTest.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml