This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 416e8562d3a49500fba6a3abd7c3ca9d8870adf5
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jul 31 05:41:13 2019 +0200

    CAMEL-6901: Intercept send to endpoint now supports after url to send 
result to this url like an AOP before|after.
---
 .../apache/camel/spi/InterceptSendToEndpoint.java  | 15 ++---
 .../engine/DefaultInterceptSendToEndpoint.java     | 26 ++++----
 docs/user-manual/modules/ROOT/pages/intercept.adoc | 72 ++++++++++++++++------
 3 files changed, 71 insertions(+), 42 deletions(-)

diff --git 
a/core/camel-api/src/main/java/org/apache/camel/spi/InterceptSendToEndpoint.java
 
b/core/camel-api/src/main/java/org/apache/camel/spi/InterceptSendToEndpoint.java
index d812a2b..6adb9bd 100644
--- 
a/core/camel-api/src/main/java/org/apache/camel/spi/InterceptSendToEndpoint.java
+++ 
b/core/camel-api/src/main/java/org/apache/camel/spi/InterceptSendToEndpoint.java
@@ -20,7 +20,8 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Processor;
 
 /**
- * This is an endpoint when sending to it, is intercepted and is routed in a 
detour
+ * This is an endpoint when sending to it, is intercepted and is routed in a 
detour, with the following flow:
+ * before, send to original endpoint (can be skipped), after (optional).
  */
 public interface InterceptSendToEndpoint extends Endpoint {
 
@@ -31,24 +32,16 @@ public interface InterceptSendToEndpoint extends Endpoint {
 
     /**
      * The processor for routing in a detour before sending to the original 
endpoint.
-     *
-     * @deprecated use {@link #getBefore()}
-     */
-    @Deprecated
-    Processor getDetour();
-
-    /**
-     * The processor for routing in a detour before sending to the original 
endpoint.
      */
     Processor getBefore();
 
     /**
-     * The processor for routing after sending to the original endpoint.
+     * The processor (optional) for routing after sending to the original 
endpoint.
      */
     Processor getAfter();
 
     /**
-     * Whether to skip sending after the detour to the original endpoint.
+     * Whether to skip sending to the original endpoint.
      */
     boolean isSkip();
 
diff --git 
a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultInterceptSendToEndpoint.java
 
b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultInterceptSendToEndpoint.java
index 8542a2a..ff526de 100644
--- 
a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultInterceptSendToEndpoint.java
+++ 
b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultInterceptSendToEndpoint.java
@@ -32,7 +32,7 @@ import org.apache.camel.spi.InterceptSendToEndpoint;
 import org.apache.camel.support.service.ServiceHelper;
 
 /**
- * This is an endpoint when sending to it, is intercepted and is routed in a 
detour
+ * This is an endpoint when sending to it, is intercepted and is routed in a 
detour (before and optionally after).
  */
 public class DefaultInterceptSendToEndpoint implements 
InterceptSendToEndpoint, ShutdownableService {
 
@@ -52,11 +52,6 @@ public class DefaultInterceptSendToEndpoint implements 
InterceptSendToEndpoint,
         this.skip = skip;
     }
 
-    @Deprecated
-    public void setDetour(Processor detour) {
-        setBefore(detour);
-    }
-
     public void setBefore(Processor before) {
         this.before = before;
     }
@@ -70,11 +65,6 @@ public class DefaultInterceptSendToEndpoint implements 
InterceptSendToEndpoint,
     }
 
     @Override
-    public Processor getDetour() {
-        return getBefore();
-    }
-
-    @Override
     public Processor getBefore() {
         return before;
     }
@@ -94,26 +84,32 @@ public class DefaultInterceptSendToEndpoint implements 
InterceptSendToEndpoint,
         return skip;
     }
 
+    @Override
     public String getEndpointUri() {
         return delegate.getEndpointUri();
     }
 
+    @Override
     public String getEndpointKey() {
         return delegate.getEndpointKey();
     }
 
+    @Override
     public Exchange createExchange() {
         return delegate.createExchange();
     }
 
+    @Override
     public Exchange createExchange(ExchangePattern pattern) {
         return delegate.createExchange(pattern);
     }
 
+    @Override
     public CamelContext getCamelContext() {
         return delegate.getCamelContext();
     }
 
+    @Override
     public Producer createProducer() throws Exception {
         return createAsyncProducer();
     }
@@ -124,34 +120,42 @@ public class DefaultInterceptSendToEndpoint implements 
InterceptSendToEndpoint,
         return new InterceptSendToEndpointProcessor(this, delegate, producer, 
skip);
     }
 
+    @Override
     public Consumer createConsumer(Processor processor) throws Exception {
         return delegate.createConsumer(processor);
     }
 
+    @Override
     public PollingConsumer createPollingConsumer() throws Exception {
         return delegate.createPollingConsumer();
     }
 
+    @Override
     public void configureProperties(Map<String, Object> options) {
         delegate.configureProperties(options);
     }
 
+    @Override
     public void setCamelContext(CamelContext context) {
         delegate.setCamelContext(context);
     }
 
+    @Override
     public boolean isLenientProperties() {
         return delegate.isLenientProperties();
     }
 
+    @Override
     public boolean isSingleton() {
         return delegate.isSingleton();
     }
 
+    @Override
     public void start() {
         ServiceHelper.startService(before, delegate);
     }
 
+    @Override
     public void stop() {
         ServiceHelper.stopService(delegate, before);
     }
diff --git a/docs/user-manual/modules/ROOT/pages/intercept.adoc 
b/docs/user-manual/modules/ROOT/pages/intercept.adoc
index 436ce43..e13fb91 100644
--- a/docs/user-manual/modules/ROOT/pages/intercept.adoc
+++ b/docs/user-manual/modules/ROOT/pages/intercept.adoc
@@ -2,9 +2,7 @@
 = Intercept
 
 The intercept feature in Camel supports intercepting
-Exchanges while they are _on route_.  +
- We have overhauled the Intercept in Camel 2.0 so
-the following information is based on Camel 2.0.
+Exchanges while they are _on route_. 
 
 Camel supports three kinds of interceptors:
 
@@ -26,6 +24,8 @@ will by default *not stop*.
 * `skip` when used with `interceptSendToEndpoint` will *skip* sending
 the Exchange to the original intended endpoint.
 Camel will by default *not skip*.
+* `afterUrl` when using with `interceptSendToEndpoint` allows to send
+the Exchange to an endpoint url after the detour and sending to the original 
endpoint.
 * `interceptFrom` and `interceptSendToEndpoint` supports endpoint URI
 matching by: exact uri, wildcard, regular expression. See advanced
 section.
@@ -142,12 +142,10 @@ not continue routing in the original intended route path.
 [[Intercept-InterceptSendToEndpoint]]
 == InterceptSendToEndpoint
 
-*Available as of Camel 2.0*
-
 Intercept send to endpoint is triggered when an
 Exchange is being sent to the intercepted endpoint.
 This allows you to route the Exchange to a
-Detour or do some custom processing before the
+detour or do some custom processing before the
 Exchange is sent to the original intended
 destination. You can also skip sending to the intended destination. By
 default Camel will send to the original intended destination after the
@@ -155,7 +153,7 @@ intercepted route completes. And as the regular intercept 
you can also
 define an `when` Predicate so we only intercept if
 the Predicate evaluates to *true*. This allows you
 do do a bit of filtering, to only intercept when certain criteria is
-meet.
+meet. And finally you can send the Exchange to an endpoint with the `afterUrl` 
option. You can use this to process the response from the original endpoint.
 
 Let start with a simple example, where we want to intercept when an
 Exchange is being sent to `mock:foo`:
@@ -169,15 +167,15 @@ original intended endpoint.
 
 *Conditional skipping*
 
-The combination of `skipSendToEndpoint` with a `when` predicate behaves
-differently depending on the Camel version:
+The combination of `skipSendToEndpoint` with a `when` predicate only occurs if 
the `when` predicate is matched, leading to more natural logic altogether.
+
+[source,java]
+-------------------------------------
+interceptSendToEndpoint("mock:foo").skipSendToOriginalEndpoint()
+    .when(simple("${body} == 'Hello World'")
+    .to("log:intercepted");
+-------------------------------------
 
-* *Before Camel 2.10:* the skipping is applied unconditionally whether
-the `when` predicate is matched or not, i.e. the `when` predicate only
-determines whether the body of the interception will execute, but it
-does not control skipping behaviour
-* *As of Camel 2.10:* the skipping only occurs if the `when` predicate
-is matched, leading to more natural logic altogether.
 
 [[Intercept-UsingfromSpringDSL.2]]
 === Using from Spring DSL
@@ -193,6 +191,45 @@ And the 3rd with the `skip`, notice skip is set with the
 `skipSendToOriginalEndpoint` attribute on the *interceptSendToEndpoint*
 tag:
 
+[source,xml]
+--------------------------------------
+<camelContext ...>
+    <interceptSendToEndpoint uri="mock:foo" skipSendToOriginalEndpoint="true">
+        <when><simple>${body} == 'Hello World'</simple></when>
+        <to uri="log:intercepted"/>
+    </intercept>
+
+    <route>
+        <from uri="jms:queue:order"/>
+        <to uri="bean:validateOrder"/>
+        <to uri="bean:handleOrder"/>
+    </route>
+</camelContext>
+--------------------------------------
+
+[[Intercept-InterceptSendToEndpoint with afterUrl]]
+== InterceptSendToEndpoint with afterUrl
+
+The interceptor allows to call an endpoint after the intercepted message has 
been sent to the original endpoint, which allows you to process the response 
from the original endpoint. For example to log the request/response from 
sending to all JMS endpoints you can do:
+
+[source,java]
+-------------------------------------
+interceptSendToEndpoint("jms*").afterUrl("log:jms-reply")
+    .to("log:jms-request");
+-------------------------------------
+
+And in XML DSL:
+
+[source,xml]
+--------------------------------------
+<camelContext ...>
+    <interceptSendToEndpoint uri="jms*" afterUrl="log:jms-reply">
+        <to uri="log:jms-request"/>
+    </intercept>
+</camelContext>
+--------------------------------------
+
+
 [[Intercept-AdvancedusageofIntercpt]]
 == Advanced usage of Intercpt
 
@@ -255,9 +292,4 @@ routes registered as routes in `CamelContext`. So if you 
dynamic
 construct a `Consumer` using the Camel API and consumes an
 Endpoint then the `interceptFrom` is not triggered.
 
-[[Intercept-SeeAlso]]
-== See Also
-
-* xref:architecture.adoc[Architecture]
-
 

Reply via email to