Author: davsclaus
Date: Wed May 4 11:24:30 2011
New Revision: 1099417
URL: http://svn.apache.org/viewvc?rev=1099417&view=rev
Log:
CAMEL-3928: Fixed InterceptStrategy not passing in actual output definition,
but often the parent instead.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/CustomInterceptorRouteWithChildOutputTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExceptionHandler.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationCustomMBeanTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugExceptionBreakpointTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java?rev=1099417&r1=1099416&r2=1099417&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
Wed May 4 11:24:30 2011
@@ -165,17 +165,19 @@ public class DefaultChannel extends Serv
((CamelContextAware) target).setCamelContext(camelContext);
}
+ // the definition to wrap should be the fine grained,
+ // so if a child is set then use it, if not then its the original
output used
+ ProcessorDefinition<?> targetOutputDef = childDefinition != null ?
childDefinition : outputDefinition;
+
// first wrap the output with the managed strategy if any
InterceptStrategy managed = routeContext.getManagedInterceptStrategy();
if (managed != null) {
next = target == nextProcessor ? null : nextProcessor;
- target =
managed.wrapProcessorInInterceptors(routeContext.getCamelContext(),
outputDefinition, target, next);
+ target =
managed.wrapProcessorInInterceptors(routeContext.getCamelContext(),
targetOutputDef, target, next);
}
// then wrap the output with the tracer
- // the tracer should have the fine grained definition so if a child is
set then use it, if not then its the original output used
- ProcessorDefinition<?> traceDef = childDefinition != null ?
childDefinition : outputDefinition;
- TraceInterceptor trace = (TraceInterceptor)
getOrCreateTracer().wrapProcessorInInterceptors(routeContext.getCamelContext(),
traceDef, target, null);
+ TraceInterceptor trace = (TraceInterceptor)
getOrCreateTracer().wrapProcessorInInterceptors(routeContext.getCamelContext(),
targetOutputDef, target, null);
// trace interceptor need to have a reference to route context so we
at runtime can enable/disable tracing on-the-fly
trace.setRouteContext(routeContext);
target = trace;
@@ -191,7 +193,8 @@ public class DefaultChannel extends Serv
if (strategy instanceof Tracer) {
continue;
}
- Processor wrapped =
strategy.wrapProcessorInInterceptors(routeContext.getCamelContext(),
outputDefinition, target, next);
+ // use the fine grained definition (eg the child if available).
Its always possible to get back to the parent
+ Processor wrapped =
strategy.wrapProcessorInInterceptors(routeContext.getCamelContext(),
targetOutputDef, target, next);
if (!(wrapped instanceof AsyncProcessor)) {
LOG.warn("Interceptor: " + strategy + " at: " +
outputDefinition + " does not return an AsyncProcessor instance."
+ " This causes the asynchronous routing engine to not
work as optimal as possible."
@@ -202,7 +205,7 @@ public class DefaultChannel extends Serv
// use a bridge and wrap again which allows us to adapt and
leverage the asynchronous routing engine anyway
// however its not the most optimal solution, but we can still
run.
InterceptorToAsyncProcessorBridge bridge = new
InterceptorToAsyncProcessorBridge(target);
- wrapped =
strategy.wrapProcessorInInterceptors(routeContext.getCamelContext(),
outputDefinition, bridge, next);
+ wrapped =
strategy.wrapProcessorInInterceptors(routeContext.getCamelContext(),
targetOutputDef, bridge, next);
bridge.setTarget(wrapped);
wrapped = bridge;
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExceptionHandler.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExceptionHandler.java?rev=1099417&r1=1099416&r2=1099417&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExceptionHandler.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExceptionHandler.java
Wed May 4 11:24:30 2011
@@ -20,6 +20,9 @@ import org.apache.camel.Exchange;
/**
* A Strategy pattern for handling exceptions; particularly in asynchronous
processes such as consumers
+ * <p/>
+ * Its important to <b>not</b> throw any exceptions when handling exceptions
as they handler
+ * is often invoked in a try .. catch logic already
*
* @version
*/
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java?rev=1099417&r1=1099416&r2=1099417&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java
Wed May 4 11:24:30 2011
@@ -26,9 +26,10 @@ import org.apache.camel.model.OptionalId
public interface NodeIdFactory {
/**
- * Creates an id for the given model definiton.
+ * Creates an id for the given model definition.
*
* @param definition model definition
+ * (its most likely a {@link
org.apache.camel.model.OutputDefinition OutputDefinition} instance)
* @return the id created
*/
String createId(OptionalIdentifiedDefinition<?> definition);
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java?rev=1099417&r1=1099416&r2=1099417&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
Wed May 4 11:24:30 2011
@@ -71,6 +71,7 @@ public class CustomIdFactoryTest extends
.when(body().contains("Hello"))
.to("mock:hello")
.otherwise()
+ .log("Hey")
.to("mock:other")
.end();
}
@@ -87,8 +88,8 @@ public class CustomIdFactoryTest extends
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
- // this should take the when path
- assertEquals("#choice6##when3#", ids);
+ // this should take the when path (first to)
+ assertEquals("#choice5##to2#", ids);
}
/**
@@ -102,7 +103,7 @@ public class CustomIdFactoryTest extends
assertMockEndpointsSatisfied();
// this should take the otherwise path
- assertEquals("#choice6##otherwise5#", ids);
+ assertEquals("#choice5##log3##to4#", ids);
}
private class MyDebuggerCheckingId implements InterceptStrategy {
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationCustomMBeanTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationCustomMBeanTest.java?rev=1099417&r1=1099416&r2=1099417&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationCustomMBeanTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationCustomMBeanTest.java
Wed May 4 11:24:30 2011
@@ -100,7 +100,7 @@ public class JmxInstrumentationCustomMBe
assertEquals("Could not find 1 context: " + s, 1, s.size());
s = CastUtils.cast(mbsc.queryNames(new ObjectName(domainName +
":type=processors,*"), null));
- assertEquals("Could not find 1 processors: " + s, 1, s.size());
+ assertEquals("Could not find 1 processors: " + s, 2, s.size());
s = CastUtils.cast(mbsc.queryNames(new ObjectName(domainName +
":type=routes,*"), null));
assertEquals("Could not find 1 route: " + s, 1, s.size());
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java?rev=1099417&r1=1099416&r2=1099417&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
Wed May 4 11:24:30 2011
@@ -69,7 +69,7 @@ public class JmxInstrumentationUsingDefa
assertEquals("Could not find 1 context: " + s, 1, s.size());
s = mbsc.queryNames(new ObjectName(domainName + ":type=processors,*"),
null);
- assertEquals("Could not find 1 processors: " + s, 1, s.size());
+ assertEquals("Could not find 1 processors: " + s, 2, s.size());
s = mbsc.queryNames(new ObjectName(domainName + ":type=consumers,*"),
null);
assertEquals("Could not find 1 consumers: " + s, 1, s.size());
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/CustomInterceptorRouteWithChildOutputTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/CustomInterceptorRouteWithChildOutputTest.java?rev=1099417&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/CustomInterceptorRouteWithChildOutputTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/CustomInterceptorRouteWithChildOutputTest.java
Wed May 4 11:24:30 2011
@@ -0,0 +1,89 @@
+/**
+ * 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.processor.interceptor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.LogDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.SplitDefinition;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.spi.InterceptStrategy;
+
+/**
+ *
+ */
+public class CustomInterceptorRouteWithChildOutputTest extends
ContextTestSupport {
+
+ private MyInterceptor myInterceptor = new MyInterceptor();
+
+ public void testCustomInterceptor() throws Exception {
+ getMockEndpoint("mock:child").expectedMessageCount(3);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "A,B,C");
+
+ assertMockEndpointsSatisfied();
+
+ assertEquals(4, myInterceptor.getDefs().size());
+ assertIsInstanceOf(LogDefinition.class,
myInterceptor.getDefs().get(0));
+ assertIsInstanceOf(ToDefinition.class, myInterceptor.getDefs().get(1));
+ assertEquals("mock:child", myInterceptor.getDefs().get(1).getLabel());
+ assertIsInstanceOf(SplitDefinition.class,
myInterceptor.getDefs().get(2));
+ assertIsInstanceOf(ToDefinition.class, myInterceptor.getDefs().get(3));
+ assertEquals("mock:result", myInterceptor.getDefs().get(3).getLabel());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // add our custom interceptor
+ context.addInterceptStrategy(myInterceptor);
+
+ from("direct:start")
+ .split(body().tokenize(","))
+ .log("Spltted ${body}")
+ .to("mock:child")
+ .end()
+ .to("mock:result");
+ }
+ };
+ }
+
+ private class MyInterceptor implements InterceptStrategy {
+
+ private final List<ProcessorDefinition> defs = new
ArrayList<ProcessorDefinition>();
+
+ @Override
+ public Processor wrapProcessorInInterceptors(CamelContext context,
ProcessorDefinition<?> definition,
+ Processor target,
Processor nextTarget) throws Exception {
+ defs.add(definition);
+ return target;
+ }
+
+ public List<ProcessorDefinition> getDefs() {
+ return defs;
+ }
+ }
+}
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugExceptionBreakpointTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugExceptionBreakpointTest.java?rev=1099417&r1=1099416&r2=1099417&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugExceptionBreakpointTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DebugExceptionBreakpointTest.java
Wed May 4 11:24:30 2011
@@ -75,7 +75,7 @@ public class DebugExceptionBreakpointTes
assertMockEndpointsSatisfied();
assertEquals(2, logs.size());
- assertEquals("Breakpoint at when caused by:
IllegalArgumentException[Damn]", logs.get(0));
+ assertEquals("Breakpoint at throwException caused by:
IllegalArgumentException[Damn]", logs.get(0));
assertEquals("Breakpoint at choice caused by:
IllegalArgumentException[Damn]", logs.get(1));
}