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 2017/07/11 09:30:53 UTC
camel git commit: CAMEL-11528: WireTap - Allow to specify the url as
non-dynamic
Repository: camel
Updated Branches:
refs/heads/master 401f091a2 -> e60c9c122
CAMEL-11528: WireTap - Allow to specify the url as non-dynamic
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e60c9c12
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e60c9c12
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e60c9c12
Branch: refs/heads/master
Commit: e60c9c122fc50d65caf53b15bf518b58d383b268
Parents: 401f091
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 11 11:18:42 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 11 11:30:48 2017 +0200
----------------------------------------------------------------------
.../apache/camel/model/WireTapDefinition.java | 40 ++++++++++
.../camel/management/ManagedWireTapTest.java | 2 +-
.../camel/processor/WireTapVoidBeanTest.java | 80 ++++++++++++++++++++
components/camel-spring/pom.xml | 5 ++
.../processor/SpringWireTapVoidBeanTest.java | 30 ++++++++
.../processor/SpringWireTapVoidBeanTest.xml | 37 +++++++++
6 files changed, 193 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e60c9c12/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 a8116d4..51440aa 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
@@ -30,6 +30,7 @@ import javax.xml.bind.annotation.XmlTransient;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Expression;
import org.apache.camel.Processor;
+import org.apache.camel.builder.ExpressionBuilder;
import org.apache.camel.processor.CamelInternalProcessor;
import org.apache.camel.processor.SendDynamicProcessor;
import org.apache.camel.processor.WireTapProcessor;
@@ -58,6 +59,8 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T
private String executorServiceRef;
@XmlAttribute @Metadata(defaultValue = "true")
private Boolean copy;
+ @XmlAttribute @Metadata(defaultValue = "true")
+ private Boolean dynamicUri;
@XmlAttribute
private String onPrepareRef;
@XmlTransient
@@ -115,6 +118,21 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T
return answer;
}
+ @Override
+ protected Expression createExpression(RouteContext routeContext) {
+ // whether to use dynamic or static uri
+ if (isDynamic()) {
+ return super.createExpression(routeContext);
+ } else {
+ return ExpressionBuilder.constantExpression(getUri());
+ }
+ }
+
+ private boolean isDynamic() {
+ // its dynamic by default
+ return dynamicUri == null || dynamicUri;
+ }
+
public ExchangePattern getPattern() {
return ExchangePattern.InOnly;
}
@@ -192,6 +210,20 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T
}
/**
+ * Whether the uri is dynamic or static.
+ * If the uri is dynamic then the simple language is used to evaluate a dynamic uri to use as the wire-tap destination,
+ * for each incoming message. This works similar to how the <tt>toD</tt> EIP pattern works.
+ * If static then the uri is used as-is as the wire-tap destination.
+ *
+ * @param dynamicUri whether to use dynamic or static uris
+ * @return the builder
+ */
+ public WireTapDefinition<Type> dynamicUri(boolean dynamicUri) {
+ setDynamicUri(dynamicUri);
+ return this;
+ }
+
+ /**
* @deprecated will be removed in Camel 3.0 Instead use {@link #newExchangeBody(org.apache.camel.Expression)}
*/
@Deprecated
@@ -373,6 +405,14 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T
this.copy = copy;
}
+ public Boolean getDynamicUri() {
+ return dynamicUri;
+ }
+
+ public void setDynamicUri(Boolean dynamicUri) {
+ this.dynamicUri = dynamicUri;
+ }
+
public String getOnPrepareRef() {
return onPrepareRef;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/e60c9c12/camel-core/src/test/java/org/apache/camel/management/ManagedWireTapTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedWireTapTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedWireTapTest.java
index 42f53d8..30f9370 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedWireTapTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedWireTapTest.java
@@ -85,7 +85,7 @@ public class ManagedWireTapTest extends ManagementTestSupport {
data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{true}, new String[]{"boolean"});
assertNotNull(data);
- assertEquals(11, data.size());
+ assertEquals(12, data.size());
String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
assertNotNull(json);
http://git-wip-us.apache.org/repos/asf/camel/blob/e60c9c12/camel-core/src/test/java/org/apache/camel/processor/WireTapVoidBeanTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/WireTapVoidBeanTest.java b/camel-core/src/test/java/org/apache/camel/processor/WireTapVoidBeanTest.java
new file mode 100644
index 0000000..71b75e6
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/WireTapVoidBeanTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.awaitility.Awaitility.await;
+
+/**
+ * Wire tap unit test
+ */
+public class WireTapVoidBeanTest extends ContextTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(WireTapVoidBeanTest.class);
+
+ public void testWireTapToVoidBean() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ final MyTapBean tapBean = (MyTapBean) context.getRegistry().lookupByName("tap");
+
+ await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
+ assertEquals("Hello World", tapBean.getTapped());
+ });
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("tap", new MyTapBean());
+ return jndi;
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .wireTap("bean:tap").dynamicUri(false)
+ .to("mock:result");
+ }
+ };
+ }
+
+ public static class MyTapBean {
+
+ private String tapped;
+
+ public void tapSomething(String body) {
+ LOG.info("Wire tapping: {}", body);
+ tapped = body;
+ }
+
+ public String getTapped() {
+ return tapped;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e60c9c12/components/camel-spring/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml
index 9ef3c5a..c7970b6 100644
--- a/components/camel-spring/pom.xml
+++ b/components/camel-spring/pom.xml
@@ -112,6 +112,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/camel/blob/e60c9c12/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.java
new file mode 100644
index 0000000..dd8ce8c
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.java
@@ -0,0 +1,30 @@
+/**
+ * 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.WireTapVoidBeanTest;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringWireTapVoidBeanTest extends WireTapVoidBeanTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.xml");
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e60c9c12/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.xml
new file mode 100644
index 0000000..57c115d
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringWireTapVoidBeanTest.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
+ ">
+
+ <bean id="tap" class="org.apache.camel.processor.WireTapVoidBeanTest$MyTapBean"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <wireTap uri="bean:tap" dynamicUri="false"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+</beans>