This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 98994ec camel-core - Untangle model from processor in reifier for
interceptSendToEndpoint EIP
98994ec is described below
commit 98994ec1773f4269967eedad1db88afb8c5a1ed9
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue May 18 20:04:42 2021 +0200
camel-core - Untangle model from processor in reifier for
interceptSendToEndpoint EIP
---
.../org/apache/camel/catalog/docs/intercept.adoc | 16 ++--
.../main/docs/modules/eips/pages/intercept.adoc | 16 ++--
.../processor/InterceptSendToEndpointCallback.java | 87 ++++++++++++++++++++++
.../reifier/InterceptSendToEndpointReifier.java | 51 +------------
4 files changed, 105 insertions(+), 65 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/intercept.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/intercept.adoc
index 25618f3..c0d44a7 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/intercept.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/intercept.adoc
@@ -84,7 +84,7 @@ The same hello world sample in Spring DSL would be:
[source,xml]
--------------------------------------
-<camelContext ...>
+<camelContext>
<intercept>
<to uri="log:hello"/>
</intercept>
@@ -193,11 +193,11 @@ tag:
[source,xml]
--------------------------------------
-<camelContext ...>
+<camelContext>
<interceptSendToEndpoint uri="mock:foo" skipSendToOriginalEndpoint="true">
<when><simple>${body} == 'Hello World'</simple></when>
<to uri="log:intercepted"/>
- </intercept>
+ </interceptSendToEndpoint>
<route>
<from uri="jms:queue:order"/>
@@ -207,7 +207,7 @@ tag:
</camelContext>
--------------------------------------
-[[Intercept-InterceptSendToEndpoint with afterUrl]]
+[[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:
@@ -222,11 +222,9 @@ And in XML DSL:
[source,xml]
--------------------------------------
-<camelContext ...>
- <interceptSendToEndpoint uri="jms*" afterUrl="log:jms-reply">
- <to uri="log:jms-request"/>
- </intercept>
-</camelContext>
+<interceptSendToEndpoint uri="jms*" afterUrl="log:jms-reply">
+ <to uri="log:jms-request"/>
+</inteinterceptSendToEndpointcept>
--------------------------------------
diff --git
a/core/camel-core-engine/src/main/docs/modules/eips/pages/intercept.adoc
b/core/camel-core-engine/src/main/docs/modules/eips/pages/intercept.adoc
index 25618f3..c0d44a7 100644
--- a/core/camel-core-engine/src/main/docs/modules/eips/pages/intercept.adoc
+++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/intercept.adoc
@@ -84,7 +84,7 @@ The same hello world sample in Spring DSL would be:
[source,xml]
--------------------------------------
-<camelContext ...>
+<camelContext>
<intercept>
<to uri="log:hello"/>
</intercept>
@@ -193,11 +193,11 @@ tag:
[source,xml]
--------------------------------------
-<camelContext ...>
+<camelContext>
<interceptSendToEndpoint uri="mock:foo" skipSendToOriginalEndpoint="true">
<when><simple>${body} == 'Hello World'</simple></when>
<to uri="log:intercepted"/>
- </intercept>
+ </interceptSendToEndpoint>
<route>
<from uri="jms:queue:order"/>
@@ -207,7 +207,7 @@ tag:
</camelContext>
--------------------------------------
-[[Intercept-InterceptSendToEndpoint with afterUrl]]
+[[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:
@@ -222,11 +222,9 @@ And in XML DSL:
[source,xml]
--------------------------------------
-<camelContext ...>
- <interceptSendToEndpoint uri="jms*" afterUrl="log:jms-reply">
- <to uri="log:jms-request"/>
- </intercept>
-</camelContext>
+<interceptSendToEndpoint uri="jms*" afterUrl="log:jms-reply">
+ <to uri="log:jms-request"/>
+</inteinterceptSendToEndpointcept>
--------------------------------------
diff --git
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/InterceptSendToEndpointCallback.java
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/InterceptSendToEndpointCallback.java
new file mode 100644
index 0000000..65d4313
--- /dev/null
+++
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/InterceptSendToEndpointCallback.java
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.Processor;
+import org.apache.camel.spi.EndpointStrategy;
+import org.apache.camel.spi.InterceptSendToEndpoint;
+import org.apache.camel.support.EndpointHelper;
+import org.apache.camel.util.URISupport;
+
+/**
+ * Endpoint strategy used by intercept send to endpoint.
+ */
+public class InterceptSendToEndpointCallback implements EndpointStrategy {
+
+ private final CamelContext camelContext;
+ private final Processor before;
+ private final Processor after;
+ private final String matchURI;
+ private final boolean skip;
+
+ public InterceptSendToEndpointCallback(CamelContext camelContext,
Processor before, Processor after, String matchURI,
+ boolean skip) {
+ this.camelContext = camelContext;
+ this.before = before;
+ this.after = after;
+ this.matchURI = matchURI;
+ this.skip = skip;
+ }
+
+ public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
+ if (endpoint instanceof InterceptSendToEndpoint) {
+ // endpoint already decorated
+ return endpoint;
+ } else if (matchURI == null || matchPattern(uri, matchURI)) {
+ // only proxy if the uri is matched decorate endpoint with
+ // our proxy should be false by default
+ return
camelContext.adapt(ExtendedCamelContext.class).getInterceptEndpointFactory()
+ .createInterceptSendToEndpoint(camelContext, endpoint,
skip, before, after);
+ } else {
+ // no proxy so return regular endpoint
+ return endpoint;
+ }
+ }
+
+ /**
+ * Does the uri match the pattern.
+ *
+ * @param uri the uri
+ * @param pattern the pattern, which can be an endpoint uri as well
+ * @return <tt>true</tt> if matched and we should intercept,
<tt>false</tt> if not matched, and not
+ * intercept.
+ */
+ protected boolean matchPattern(String uri, String pattern) {
+ // match using the pattern as-is
+ boolean match = EndpointHelper.matchEndpoint(camelContext, uri,
pattern);
+ if (!match) {
+ try {
+ // the pattern could be an uri, so we need to normalize it
+ // before matching again
+ pattern = URISupport.normalizeUri(pattern);
+ match = EndpointHelper.matchEndpoint(camelContext, uri,
pattern);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ return match;
+ }
+
+}
diff --git
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/InterceptSendToEndpointReifier.java
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/InterceptSendToEndpointReifier.java
index 0fe838d..502779c 100644
---
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/InterceptSendToEndpointReifier.java
+++
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/InterceptSendToEndpointReifier.java
@@ -18,7 +18,6 @@ package org.apache.camel.reifier;
import java.util.List;
-import org.apache.camel.Endpoint;
import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.Processor;
import org.apache.camel.Route;
@@ -27,10 +26,7 @@ import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDefinition;
import org.apache.camel.processor.InterceptEndpointProcessor;
-import org.apache.camel.spi.EndpointStrategy;
-import org.apache.camel.spi.InterceptSendToEndpoint;
-import org.apache.camel.support.EndpointHelper;
-import org.apache.camel.util.URISupport;
+import org.apache.camel.processor.InterceptSendToEndpointCallback;
public class InterceptSendToEndpointReifier extends
ProcessorReifier<InterceptSendToEndpointDefinition> {
@@ -56,26 +52,11 @@ public class InterceptSendToEndpointReifier extends
ProcessorReifier<InterceptSe
}
final Processor after = afterProcessor;
final String matchURI = parseString(definition.getUri());
+ final boolean skip =
parseBoolean(definition.getSkipSendToOriginalEndpoint(), false);
// register endpoint callback so we can proxy the endpoint
-
camelContext.adapt(ExtendedCamelContext.class).registerEndpointCallback(new
EndpointStrategy() {
- public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
- if (endpoint instanceof InterceptSendToEndpoint) {
- // endpoint already decorated
- return endpoint;
- } else if (matchURI == null || matchPattern(uri, matchURI)) {
- // only proxy if the uri is matched decorate endpoint with
- // our proxy
- // should be false by default
- boolean skip =
parseBoolean(definition.getSkipSendToOriginalEndpoint(), false);
- return
camelContext.adapt(ExtendedCamelContext.class).getInterceptEndpointFactory()
- .createInterceptSendToEndpoint(camelContext,
endpoint, skip, before, after);
- } else {
- // no proxy so return regular endpoint
- return endpoint;
- }
- }
- });
+ camelContext.adapt(ExtendedCamelContext.class)
+ .registerEndpointCallback(new
InterceptSendToEndpointCallback(camelContext, before, after, matchURI, skip));
// remove the original intercepted route from the outputs as we do not
// intercept as the regular interceptor
@@ -89,28 +70,4 @@ public class InterceptSendToEndpointReifier extends
ProcessorReifier<InterceptSe
return new InterceptEndpointProcessor(matchURI, before);
}
- /**
- * Does the uri match the pattern.
- *
- * @param uri the uri
- * @param pattern the pattern, which can be an endpoint uri as well
- * @return <tt>true</tt> if matched and we should intercept,
<tt>false</tt> if not matched, and not
- * intercept.
- */
- protected boolean matchPattern(String uri, String pattern) {
- // match using the pattern as-is
- boolean match = EndpointHelper.matchEndpoint(camelContext, uri,
pattern);
- if (!match) {
- try {
- // the pattern could be an uri, so we need to normalize it
- // before matching again
- pattern = URISupport.normalizeUri(pattern);
- match = EndpointHelper.matchEndpoint(camelContext, uri,
pattern);
- } catch (Exception e) {
- // ignore
- }
- }
- return match;
- }
-
}