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 2013/04/22 15:46:20 UTC
svn commit: r1470508 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
main/java/org/apache/camel/model/TryDefinition.java
test/java/org/apache/camel/processor/interceptor/AdviceWithTryCatchTest.java
Author: davsclaus
Date: Mon Apr 22 13:46:19 2013
New Revision: 1470508
URL: http://svn.apache.org/r1470508
Log:
CAMEL-6300: Fixed advice with not working with doTry .. doCatch.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithTryCatchTest.java
- copied, changed from r1470431, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithReplaceFromTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java?rev=1470508&r1=1470507&r2=1470508&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java Mon Apr 22 13:46:19 2013
@@ -213,6 +213,25 @@ public final class ProcessorDefinitionHe
}
}
+ // special for try ... catch ... finally
+ if (out instanceof TryDefinition) {
+ TryDefinition doTry = (TryDefinition) out;
+ List<ProcessorDefinition<?>> doTryOut = doTry.getOutputsWithoutCatches();
+ doFindType(doTryOut, type, found);
+
+ List<CatchDefinition> doTryCatch = doTry.getCatchClauses();
+ for (CatchDefinition doCatch : doTryCatch) {
+ doFindType(doCatch.getOutputs(), type, found);
+ }
+
+ if (doTry.getFinallyClause() != null) {
+ doFindType(doTry.getFinallyClause().getOutputs(), type, found);
+ }
+
+ // do not check children as we already did that
+ continue;
+ }
+
// try children as well
List<ProcessorDefinition<?>> children = out.getOutputs();
doFindType(children, type, found);
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java?rev=1470508&r1=1470507&r2=1470508&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java Mon Apr 22 13:46:19 2013
@@ -245,6 +245,13 @@ public class TryDefinition extends Outpu
super.addOutput(output);
}
+ @Override
+ protected void preCreateProcessor() {
+ // force re-creating initialization to ensure its up-to-date
+ initialized = false;
+ checkInitialized();
+ }
+
/**
* Checks whether or not this object has been initialized
*/
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithTryCatchTest.java (from r1470431, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithReplaceFromTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithTryCatchTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithTryCatchTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithReplaceFromTest.java&r1=1470431&r2=1470508&rev=1470508&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithReplaceFromTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithTryCatchTest.java Mon Apr 22 13:46:19 2013
@@ -17,73 +17,51 @@
package org.apache.camel.processor.interceptor;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Endpoint;
-import org.apache.camel.FailedToCreateRouteException;
-import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
/**
- * Advice with match multiple ids test
+ * Advice with try catch
*/
-public class AdviceWithReplaceFromTest extends ContextTestSupport {
+public class AdviceWithTryCatchTest extends ContextTestSupport {
- public void testReplaceFromUri() throws Exception {
+ public void testTryCatch() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
- // replace the input in the route with a new endpoint uri
- replaceFromWith("seda:foo");
+ weaveById("foo").replace().process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ throw new IllegalArgumentException("Kaboom");
+ }
+ });
}
});
- getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:before").expectedMessageCount(1);
+ getMockEndpoint("mock:after").expectedMessageCount(1);
+ getMockEndpoint("mock:error").expectedMessageCount(1);
- // has been replaced to a seda endpoint instead
- template.sendBody("seda:foo", "Hello World");
+ template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
- public void testReplaceFromEndpoint() throws Exception {
- final Endpoint endpoint = context.getEndpoint("seda:foo");
-
- context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
- @Override
- public void configure() throws Exception {
- // replace the input in the route with a new endpoint
- replaceFromWith(endpoint);
- }
- });
-
- getMockEndpoint("mock:result").expectedMessageCount(1);
-
- // has been replaced to a seda endpoint instead
- template.sendBody("seda:foo", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- public void testReplaceFromInvalidUri() throws Exception {
- try {
- context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
- @Override
- public void configure() throws Exception {
- replaceFromWith("xxx:foo");
- }
- });
- fail("Should have thrown exception");
- } catch (FailedToCreateRouteException e) {
- assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
- }
- }
-
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").to("mock:result");
+ from("direct:start")
+ .to("mock:before")
+ .doTry()
+ .to("mock:foo").id("foo")
+ .doCatch(Exception.class)
+ .to("mock:error")
+ .end()
+ .to("mock:after");
}
};
}