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 2015/07/20 22:47:24 UTC

[3/7] camel git commit: CAMEL-8965: WireTap supports dynamic uris like enrich/pollEnrich now does.

CAMEL-8965: WireTap supports dynamic uris like enrich/pollEnrich now does.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b269ae57
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b269ae57
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b269ae57

Branch: refs/heads/master
Commit: b269ae570314bd45f122a24ed4a92ef18f86c7f3
Parents: 2696b57
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jul 20 16:51:06 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jul 20 22:54:08 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/model/ProcessorDefinition.java | 16 +++++++
 .../apache/camel/model/WireTapDefinition.java   |  3 +-
 .../camel/processor/SendDynamicProcessor.java   |  5 ++
 .../model/GatherAllStaticEndpointUrisTest.java  |  2 +-
 .../camel/processor/WireTapExpressionTest.java  | 49 ++++++++++++++++++++
 .../processor/SpringWireTapExpressionTest.java  | 32 +++++++++++++
 .../processor/SpringWireTapExpressionTest.xml   | 37 +++++++++++++++
 7 files changed, 142 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b269ae57/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 91d0e6f..57bf273 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -2270,6 +2270,22 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
      * destination gets a copy of the original message to avoid the processors
      * interfering with each other using {@link ExchangePattern#InOnly}.
      *
+     * @param expression  the expression to compute the uri to use as wire tap
+     * @return the builder
+     */
+    public Type wireTap(Expression expression) {
+        WireTapDefinition answer = new WireTapDefinition();
+        answer.setExpression(new ExpressionDefinition(expression));
+        addOutput(answer);
+        return (Type) this;
+    }
+
+    /**
+     * <a href="http://camel.apache.org/wiretap.html">WireTap EIP:</a>
+     * Sends messages to all its child outputs; so that each processor and
+     * destination gets a copy of the original message to avoid the processors
+     * interfering with each other using {@link ExchangePattern#InOnly}.
+     *
      * @param uri  the destination
      * @return the builder
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/b269ae57/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java b/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
index ebe95b1..64e339e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
@@ -73,7 +73,8 @@ public class WireTapDefinition extends NoOutputExpressionNode implements Executo
         ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "WireTap", this, true);
 
         // create the send dynamic producer to send to the wire tapped endpoint
-        Processor dynamicTo = new SendDynamicProcessor(null, getExpression());
+        SendDynamicProcessor dynamicTo = new SendDynamicProcessor(getExpression());
+        dynamicTo.setCamelContext(routeContext.getCamelContext());
 
         // create error handler we need to use for processing the wire tapped
         Processor target = wrapInErrorHandler(routeContext, dynamicTo);

http://git-wip-us.apache.org/repos/asf/camel/blob/b269ae57/camel-core/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java
index b207ba5..bdde81e 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/SendDynamicProcessor.java
@@ -54,6 +54,11 @@ public class SendDynamicProcessor extends ServiceSupport implements AsyncProcess
     protected boolean ignoreInvalidEndpoint;
     protected int cacheSize;
 
+    public SendDynamicProcessor(Expression expression) {
+        this.uri = null;
+        this.expression = expression;
+    }
+
     public SendDynamicProcessor(String uri, Expression expression) {
         this.uri = uri;
         this.expression = expression;

http://git-wip-us.apache.org/repos/asf/camel/blob/b269ae57/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java b/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java
index f423c84..7461bf9 100644
--- a/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java
+++ b/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java
@@ -27,7 +27,7 @@ public class GatherAllStaticEndpointUrisTest extends ContextTestSupport {
         RouteDefinition route = context.getRouteDefinition("foo");
         Set<String> uris = RouteDefinitionHelper.gatherAllStaticEndpointUris(context, route, true, true);
         assertNotNull(uris);
-        assertEquals(4, uris.size());
+        assertEquals(3, uris.size());
 
         RouteDefinition route2 = context.getRouteDefinition("bar");
         Set<String> uris2 = RouteDefinitionHelper.gatherAllStaticEndpointUris(context, route2, true, true);

http://git-wip-us.apache.org/repos/asf/camel/blob/b269ae57/camel-core/src/test/java/org/apache/camel/processor/WireTapExpressionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/WireTapExpressionTest.java b/camel-core/src/test/java/org/apache/camel/processor/WireTapExpressionTest.java
new file mode 100644
index 0000000..b214474
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/WireTapExpressionTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Wire tap unit test
+ *
+ * @version 
+ */
+public class WireTapExpressionTest extends ContextTestSupport {
+
+    public void testWireTapExpression() throws Exception {
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello Camel");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
+
+        template.sendBodyAndHeader("direct:start", "Hello Camel", "tap", "foo");
+        template.sendBodyAndHeader("direct:start", "Hello World", "tap", "bar");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                // START SNIPPET: e1
+                from("direct:start")
+                    .wireTap(simple("mock:${header.tap}"));
+                // END SNIPPET: e1
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/b269ae57/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapExpressionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapExpressionTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapExpressionTest.java
new file mode 100644
index 0000000..a8f886e
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapExpressionTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.spring.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.WireTapExpressionTest;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ * @version 
+ */
+public class SpringWireTapExpressionTest extends WireTapExpressionTest {
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringWireTapExpressionTest.xml");
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b269ae57/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringWireTapExpressionTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringWireTapExpressionTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringWireTapExpressionTest.xml
new file mode 100644
index 0000000..80d7e0b
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringWireTapExpressionTest.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+    <route>
+      <from uri="direct:start"/>
+      <wireTap>
+        <simple>mock:${header.tap}</simple>
+      </wireTap>
+    </route>
+
+  </camelContext>
+  <!-- END SNIPPET: example -->
+</beans>