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/05/04 10:14:03 UTC
svn commit: r771233 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/model/
test/java/org/apache/camel/processor/intercept/
Author: davsclaus
Date: Mon May 4 08:14:03 2009
New Revision: 771233
URL: http://svn.apache.org/viewvc?rev=771233&view=rev
Log:
CAMEL-1580: A little DSL cleanup for interceptSendToEndpoint.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java?rev=771233&r1=771232&r2=771233&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptSendToEndpointDefinition.java Mon May 4 08:14:03 2009
@@ -70,10 +70,6 @@
return "interceptEndpoint";
}
- public void skipSendToOriginalEndpoint() {
- setSkipSendToOriginalEndpoint(Boolean.TRUE);
- }
-
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
// we have to reuse the createProcessor method to build the detour route
@@ -126,6 +122,16 @@
}
/**
+ * Skip sending the {@link org.apache.camel.Exchange} to the original intended endpoint
+ *
+ * @return the builder
+ */
+ public InterceptSendToEndpointDefinition skipSendToOriginalEndpoint() {
+ setSkipSendToOriginalEndpoint(Boolean.TRUE);
+ return this;
+ }
+
+ /**
* 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
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=771233&r1=771232&r2=771233&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Mon May 4 08:14:03 2009
@@ -1332,35 +1332,6 @@
}
/**
- * Skip sending the {@link org.apache.camel.Exchange} to the original intended endpoint
- * when used with <tt>interceptSendToEndpoint</tt>.
- *
- * @return the builder
- */
- @SuppressWarnings("unchecked")
- public Type skip() {
- // TODO: move this to InterceptSendToEndpoint so its a special builder method on it only
- ProcessorDefinition currentProcessor = this;
-
- if (currentProcessor instanceof InterceptSendToEndpointDefinition) {
- ((InterceptSendToEndpointDefinition) currentProcessor).skipSendToOriginalEndpoint();
- } else {
- ProcessorDefinition node;
- for (node = parent; node != null; node = node.getParent()) {
- if (node instanceof InterceptSendToEndpointDefinition) {
- ((InterceptSendToEndpointDefinition) node).skipSendToOriginalEndpoint();
- break;
- }
- }
- if (node == null) {
- throw new IllegalArgumentException("Cannot use skip() without being within an interceptSendToEndpoint() block");
- }
- }
-
- return (Type) this;
- }
-
- /**
* <a href="http://camel.apache.org/exception-clause.html">Exception clause</a>
* for cathing certain exceptions and handling them.
*
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointTest.java?rev=771233&r1=771232&r2=771233&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointTest.java Mon May 4 08:14:03 2009
@@ -40,7 +40,8 @@
// this endpoint, its intercepted and routed with this detour route beforehand
// afterwards its send to the original intended destination. So this is kinda AOP before.
// That means mock:foo will receive the message (Bye World).
- interceptSendToEndpoint("mock:foo").to("mock:detour").transform(constant("Bye World"));
+ interceptSendToEndpoint("mock:foo")
+ .to("mock:detour").transform(constant("Bye World"));
from("direct:first")
.to("mock:bar")
@@ -69,7 +70,8 @@
// START SNIPPET: e2
// we can also attach a predicate to the endpoint interceptor. So in this example the exchange is
// only intercepted if the body is Hello World
- interceptSendToEndpoint("mock:foo").when(body().isEqualTo("Hello World")).to("mock:detour").transform(constant("Bye World"));
+ interceptSendToEndpoint("mock:foo").when(body().isEqualTo("Hello World"))
+ .to("mock:detour").transform(constant("Bye World"));
from("direct:second")
.to("mock:bar")
@@ -98,12 +100,14 @@
@Override
public void configure() throws Exception {
// START SNIPPET: e3
- // since we use the skip() at the end of the detour route we instruct Camel to skip
- // sending the exchange to the original intended destination.
+ // since we use the skipSendToOriginalEndpoint() we instruct Camel to skip
+ // sending the exchange to the original intended destination after the intercept
+ // route is complete.
// That means that mock:foo will NOT receive the message, but the message
// is skipped and continued in the original route, so mock:result will receive
// the message.
- interceptSendToEndpoint("mock:foo").transform(constant("Bye World")).to("mock:detour").skip();
+ interceptSendToEndpoint("mock:foo").skipSendToOriginalEndpoint()
+ .transform(constant("Bye World")).to("mock:detour");
from("direct:third")
.to("mock:bar")
@@ -130,7 +134,8 @@
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
- interceptSendToEndpoint("direct:start").to("mock:detour").transform(constant("Bye World"));
+ interceptSendToEndpoint("direct:start")
+ .to("mock:detour").transform(constant("Bye World"));
from("direct:start")
.to("mock:foo")
@@ -148,4 +153,27 @@
assertMockEndpointsSatisfied();
}
+ public void testInterceptEndpointWithStop() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("direct:start")
+ .to("mock:detour").stop();
+
+ from("direct:start")
+ .to("mock:foo")
+ .to("mock:result");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:detour").expectedMessageCount(1);
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
}