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 7bc5ba6 CAMEL-17668: camel-core - WireTap - Remove function to tap as new body/header 7bc5ba6 is described below commit 7bc5ba6168dafa8887f136f05d43c35f19deae63 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Feb 17 10:07:46 2022 +0100 CAMEL-17668: camel-core - WireTap - Remove function to tap as new body/header --- .../org/apache/camel/catalog/models/wireTap.json | 2 - .../apache/camel/catalog/schemas/camel-spring.xsd | 20 +-- .../processor/SpringWireTapNewExchangeTest.java | 31 ---- .../SpringWireTapUsingFireAndForgetCopyTest.java | 96 ----------- .../SpringWireTapUsingFireAndForgetTest.java | 95 ----------- .../processor/SpringWireTapNewExchangeTest.xml | 52 ------ .../SpringWireTapUsingFireAndForgetCopyTest.xml | 56 ------- .../SpringWireTapUsingFireAndForgetTest.xml | 56 ------- .../main/docs/modules/eips/pages/wireTap-eip.adoc | 61 +------ .../resources/org/apache/camel/model/wireTap.json | 2 - .../org/apache/camel/model/WireTapDefinition.java | 105 ------------ .../apache/camel/processor/WireTapProcessor.java | 49 ------ .../org/apache/camel/reifier/WireTapReifier.java | 20 +-- .../camel/processor/WireTapNewExchangeTest.java | 67 -------- .../camel/processor/WireTapOnPrepareTest.java | 2 +- ...WireTapUsingFireAndForgetCopyAsDefaultTest.java | 177 --------------------- .../WireTapUsingFireAndForgetCopyTest.java | 177 --------------------- .../processor/WireTapUsingFireAndForgetTest.java | 107 ------------- .../OnExceptionWireTapNewExchangeBodyTest.java | 47 ------ .../java/org/apache/camel/xml/in/ModelParser.java | 10 +- .../ROOT/pages/camel-3x-upgrade-guide-3_16.adoc | 4 + .../dsl/yaml/deserializers/ModelDeserializers.java | 18 --- .../src/generated/resources/camel-yaml-dsl.json | 12 -- .../src/generated/resources/camelYamlDsl.json | 12 -- 24 files changed, 11 insertions(+), 1267 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/wireTap.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/wireTap.json index f135ac6..d0e6691 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/wireTap.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/wireTap.json @@ -12,8 +12,6 @@ "output": false }, "properties": { - "processorRef": { "kind": "attribute", "displayName": "Processor Ref", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a Processor to use for creating a new body as the message to use for wire tapping" }, - "body": { "kind": "expression", "displayName": "Body", "required": false, "type": "object", "javaType": "org.apache.camel.model.ExpressionSubElementDefinition", "oneOf": [ "constant", "csimple", "datasonnet", "exchangeProperty", "groovy", "header", "hl7terser", "joor", "jsonpath", "language", "method", "mvel", "ognl", "ref", "simple", "spel", "tokenize", "xpath", "xquery", "xtokenize" ], "deprecated": false, "autowired": false, "secret": false, "description": "Uses the expression for [...] "executorServiceRef": { "kind": "attribute", "displayName": "Executor Service Ref", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Uses a custom thread pool" }, "copy": { "kind": "attribute", "displayName": "Copy", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Uses a copy of the original exchange" }, "dynamicUri": { "kind": "attribute", "displayName": "Dynamic Uri", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "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 toD EIP pattern works. If static then the [...] diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd index 59c7ab3..6781005 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd @@ -12399,25 +12399,7 @@ exception to throw instead. <xs:complexType name="wireTapDefinition"> <xs:complexContent> <xs:extension base="tns:toDynamicDefinition"> - <xs:sequence> - <xs:element minOccurs="0" name="body" type="tns:expressionSubElementDefinition"> - <xs:annotation> - <xs:documentation xml:lang="en"><![CDATA[ -Uses the expression for creating a new body as the message to use for wire -tapping. - ]]></xs:documentation> - </xs:annotation> - </xs:element> - <xs:element maxOccurs="unbounded" minOccurs="0" ref="tns:setHeader"/> - </xs:sequence> - <xs:attribute name="processorRef" type="xs:string"> - <xs:annotation> - <xs:documentation xml:lang="en"><![CDATA[ -Reference to a Processor to use for creating a new body as the message to use -for wire tapping. - ]]></xs:documentation> - </xs:annotation> - </xs:attribute> + <xs:sequence/> <xs:attribute name="executorServiceRef" type="xs:string"> <xs:annotation> <xs:documentation xml:lang="en"><![CDATA[ diff --git a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapNewExchangeTest.java b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapNewExchangeTest.java deleted file mode 100644 index 8598db7..0000000 --- a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapNewExchangeTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.WireTapNewExchangeTest; - -import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; - -public class SpringWireTapNewExchangeTest extends WireTapNewExchangeTest { - - @Override - protected CamelContext createCamelContext() throws Exception { - return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringWireTapNewExchangeTest.xml"); - } - -} diff --git a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetCopyTest.java b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetCopyTest.java deleted file mode 100644 index 7fd0e34..0000000 --- a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetCopyTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.ContextTestSupport; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -public class SpringWireTapUsingFireAndForgetCopyTest extends ContextTestSupport { - - @Override - protected CamelContext createCamelContext() throws Exception { - return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetCopyTest.xml"); - } - - @Test - public void testFireAndForgetUsingExpression() throws Exception { - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingProcessor() throws Exception { - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - foo.expectedHeaderReceived("foo", "bar"); - - template.sendBody("direct:start2", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start2", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start2", e2.getFromEndpoint().getEndpointUri()); - } - - // START SNIPPET: e1 - public static class MyProcessor implements Processor { - - @Override - public void process(Exchange exchange) throws Exception { - String body = exchange.getIn().getBody(String.class); - // here we prepare the new exchange by setting the payload on the exchange - // on the IN message. - exchange.getIn().setBody("Bye " + body); - exchange.getIn().setHeader("foo", "bar"); - } - } - // END SNIPPET: e1 - -} diff --git a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetTest.java b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetTest.java deleted file mode 100644 index b2ff2fd..0000000 --- a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.ContextTestSupport; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -public class SpringWireTapUsingFireAndForgetTest extends ContextTestSupport { - - @Override - protected CamelContext createCamelContext() throws Exception { - return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetTest.xml"); - } - - @Test - public void testFireAndForgetUsingExpression() throws Exception { - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("Hello World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingProcessor() throws Exception { - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("Hello World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - foo.expectedHeaderReceived("foo", "bar"); - - template.sendBody("direct:start2", "Hello World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start2", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start2", e2.getFromEndpoint().getEndpointUri()); - } - - // START SNIPPET: e1 - public static class MyProcessor implements Processor { - - @Override - public void process(Exchange exchange) throws Exception { - // here we prepare the new exchange by setting the payload on the exchange - // on the IN message. - exchange.getIn().setBody("Bye World"); - exchange.getIn().setHeader("foo", "bar"); - } - } - // END SNIPPET: e1 - -} diff --git a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapNewExchangeTest.xml b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapNewExchangeTest.xml deleted file mode 100644 index 6c60365..0000000 --- a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapNewExchangeTest.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?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 - "> - - <camelContext xmlns="http://camel.apache.org/schema/spring"> - <!-- START SNIPPET: e1 --> - <route> - <from uri="direct:start"/> - <!-- tap a new message and send it to direct:tap --> - <!-- the new message should be Bye World with 2 headers --> - <wireTap uri="direct:tap"> - <!-- create the new tap message body and headers --> - <body><constant>Bye World</constant></body> - <setHeader name="id"><constant>123</constant></setHeader> - <setHeader name="date"><simple>${date:now:yyyyMMdd}</simple></setHeader> - </wireTap> - <!-- here we continue routing the original message --> - <to uri="mock:result"/> - </route> - <!-- END SNIPPET: e1 --> - - <!-- this is the tapped route --> - <route> - <from uri="direct:tap"/> - <to uri="mock:tap"/> - </route> - - </camelContext> - -</beans> diff --git a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetCopyTest.xml b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetCopyTest.xml deleted file mode 100644 index b9d7140..0000000 --- a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetCopyTest.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?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 - "> - - - <camelContext xmlns="http://camel.apache.org/schema/spring"> - <!-- START SNIPPET: e1 --> - <route> - <from uri="direct:start"/> - <wireTap uri="direct:foo"> - <body><simple>Bye ${body}</simple></body> - </wireTap> - <to uri="mock:result"/> - </route> - <!-- END SNIPPET: e1 --> - - <!-- START SNIPPET: e2 --> - <route> - <from uri="direct:start2"/> - <wireTap uri="direct:foo" processorRef="myProcessor"/> - <to uri="mock:result"/> - </route> - <!-- END SNIPPET: e2 --> - - <route> - <from uri="direct:foo"/> - <to uri="mock:foo"/> - </route> - - </camelContext> - - <bean id="myProcessor" class="org.apache.camel.spring.processor.SpringWireTapUsingFireAndForgetCopyTest$MyProcessor"/> - -</beans> diff --git a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetTest.xml b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetTest.xml deleted file mode 100644 index 0ac3e10..0000000 --- a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringWireTapUsingFireAndForgetTest.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?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 - "> - - - <camelContext xmlns="http://camel.apache.org/schema/spring"> - <!-- START SNIPPET: e1 --> - <route> - <from uri="direct:start"/> - <wireTap uri="direct:foo"> - <body><constant>Bye World</constant></body> - </wireTap> - <to uri="mock:result"/> - </route> - <!-- END SNIPPET: e1 --> - - <!-- START SNIPPET: e2 --> - <route> - <from uri="direct:start2"/> - <wireTap uri="direct:foo" processorRef="myProcessor"/> - <to uri="mock:result"/> - </route> - <!-- END SNIPPET: e2 --> - - <route> - <from uri="direct:foo"/> - <to uri="mock:foo"/> - </route> - - </camelContext> - - <bean id="myProcessor" class="org.apache.camel.spring.processor.SpringWireTapUsingFireAndForgetTest$MyProcessor"/> - -</beans> diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/wireTap-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/wireTap-eip.adoc index 2840de7..454fed4 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/wireTap-eip.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/wireTap-eip.adoc @@ -18,12 +18,9 @@ image::eip/WireTap.gif[image] include::partial$eip-options.adoc[] // eip options: END -== WireTap Nodes +== Wire Tap -Camel's Wire Tap node supports two modes when wire tapping an -xref:manual::exchange.adoc[Exchange]: - -- _Default mode_: Camel will copy the original +Camel's Wire Tap will copy the original xref:manual::exchange.adoc[Exchange] and set its xref:manual::exchange-pattern.adoc[Exchange Pattern] to *`InOnly`*, as we want the tapped xref:manual::exchange.adoc[Exchange] to be sent in a fire and forget @@ -33,15 +30,11 @@ only the `Exchange` is copied - Wire Tap won't do a deep clone (unless you specify a custom processor via *`onPrepareRef`* which does that). So all copies could share objects from the original `Exchange`. -- _New mode_: Camel also provides an option of sending a new -xref:manual::exchange.adoc[Exchange] allowing you to populate it with new -values. - === Using Wire Tap In the example below the exchange is wire tapped to the direct:tap route. This route delays the message 1 second before continuing. This is because -it allows you to see that the tapped message is routed independently from the original +it allows you to see that the tapped message is routed independently of the original route, so that you would see log:result happens before log:tap [source,java] @@ -102,54 +95,6 @@ And in XML: </route> ---- -=== Wire tapping a new message - -In the _new mode_ then the wire tap will create a new `Exchange` that gets populated with new data, to be sent -out from the wire tap. The idea is to allow you to construct the tapped message with information from the original -message. - -The construction of the new message is done via a `Processor` where you populate the `Exchange` - -[source,java] ----- -from("direct:start") - .wireTap("direct:tap").newExchange(exchange -> { - String oldBody = exchange.getMessage().getBody(String.class); - String newBody = "We are listening: " + oldBody; - exchange.getMessage().setBody(newBody); - exchange.getMessage().setHeader("tapId", "123"); - }) - .to("log:result"); - -from("direct:tap") - .to("log:tap"); ----- - -And in XML we are using `<body>` and `<setHeader`> (This is also possible in Java DSL) -to construct the message, instead of using a `Processor`: - -[source,xml] ----- -<routes> - - <route> - <from uri="direct:start"/> - <wireTap uri="direct:tap"> - <body><simple>We are listening: ${body}</simple></body> - <setHeader name="tapId"><constant>123</constant></setHeader> - </wireTap> - <to uri="log:result"/> - </route> - - <route> - <from uri="direct:tap"/> - <to uri="log:log"/> - </route> - -</routes> - ----- - == WireTap Thread Pools diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/wireTap.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/wireTap.json index f135ac6..d0e6691 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/wireTap.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/wireTap.json @@ -12,8 +12,6 @@ "output": false }, "properties": { - "processorRef": { "kind": "attribute", "displayName": "Processor Ref", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to a Processor to use for creating a new body as the message to use for wire tapping" }, - "body": { "kind": "expression", "displayName": "Body", "required": false, "type": "object", "javaType": "org.apache.camel.model.ExpressionSubElementDefinition", "oneOf": [ "constant", "csimple", "datasonnet", "exchangeProperty", "groovy", "header", "hl7terser", "joor", "jsonpath", "language", "method", "mvel", "ognl", "ref", "simple", "spel", "tokenize", "xpath", "xquery", "xtokenize" ], "deprecated": false, "autowired": false, "secret": false, "description": "Uses the expression for [...] "executorServiceRef": { "kind": "attribute", "displayName": "Executor Service Ref", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Uses a custom thread pool" }, "copy": { "kind": "attribute", "displayName": "Copy", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Uses a copy of the original exchange" }, "dynamicUri": { "kind": "attribute", "displayName": "Dynamic Uri", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "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 toD EIP pattern works. If static then the [...] diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/WireTapDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/WireTapDefinition.java index da87d26..f79bf76 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/WireTapDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/WireTapDefinition.java @@ -16,20 +16,15 @@ */ package org.apache.camel.model; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ExecutorService; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementRef; import javax.xml.bind.annotation.XmlRootElement; 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.spi.Metadata; @@ -43,14 +38,6 @@ import org.apache.camel.spi.Metadata; public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends ToDynamicDefinition implements ExecutorServiceAwareDefinition<WireTapDefinition<Type>> { @XmlTransient - private Processor newExchangeProcessor; - @XmlAttribute(name = "processorRef") - private String newExchangeProcessorRef; - @XmlElement(name = "body") - private ExpressionSubElementDefinition newExchangeExpression; - @XmlElementRef - private List<SetHeaderDefinition> headers = new ArrayList<>(); - @XmlTransient private ExecutorService executorService; @XmlAttribute private String executorServiceRef; @@ -187,57 +174,6 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T } /** - * Sends a <i>new</i> Exchange, instead of tapping an existing, using {@link ExchangePattern#InOnly} - * - * @param expression expression that creates the new body to send - * @return the builder - * @see #newExchangeHeader(String, org.apache.camel.Expression) - */ - public WireTapDefinition<Type> newExchangeBody(Expression expression) { - setNewExchangeExpression(new ExpressionSubElementDefinition(expression)); - return this; - } - - /** - * Sends a <i>new</i> Exchange, instead of tapping an existing, using {@link ExchangePattern#InOnly} - * - * @param ref reference to the {@link Processor} to lookup in the {@link org.apache.camel.spi.Registry} to be used - * for preparing the new exchange to send - * @return the builder - */ - public WireTapDefinition<Type> newExchangeRef(String ref) { - setNewExchangeProcessorRef(ref); - return this; - } - - /** - * Sends a <i>new</i> Exchange, instead of tapping an existing, using {@link ExchangePattern#InOnly} - * - * @param processor processor preparing the new exchange to send - * @return the builder - * @see #newExchangeHeader(String, org.apache.camel.Expression) - */ - public WireTapDefinition<Type> newExchange(Processor processor) { - setNewExchangeProcessor(processor); - return this; - } - - /** - * Sets a header on the <i>new</i> Exchange, instead of tapping an existing, using {@link ExchangePattern#InOnly}. - * <p/> - * Use this together with the {@link #newExchangeBody(org.apache.camel.Expression)} or - * {@link #newExchange(org.apache.camel.Processor)} methods. - * - * @param headerName the header name - * @param expression the expression setting the header value - * @return the builder - */ - public WireTapDefinition<Type> newExchangeHeader(String headerName, Expression expression) { - headers.add(new SetHeaderDefinition(headerName, expression)); - return this; - } - - /** * Uses the {@link Processor} when preparing the {@link org.apache.camel.Exchange} to be send. This can be used to * deep-clone messages that should be send, or any custom logic needed before the exchange is send. * @@ -337,39 +273,6 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T super.setUri(uri); } - public Processor getNewExchangeProcessor() { - return newExchangeProcessor; - } - - /** - * To use a Processor for creating a new body as the message to use for wire tapping - */ - public void setNewExchangeProcessor(Processor processor) { - this.newExchangeProcessor = processor; - } - - public String getNewExchangeProcessorRef() { - return newExchangeProcessorRef; - } - - /** - * Reference to a Processor to use for creating a new body as the message to use for wire tapping - */ - public void setNewExchangeProcessorRef(String ref) { - this.newExchangeProcessorRef = ref; - } - - public ExpressionSubElementDefinition getNewExchangeExpression() { - return newExchangeExpression; - } - - /** - * Uses the expression for creating a new body as the message to use for wire tapping - */ - public void setNewExchangeExpression(ExpressionSubElementDefinition newExchangeExpression) { - this.newExchangeExpression = newExchangeExpression; - } - @Override public ExecutorService getExecutorService() { return executorService; @@ -422,12 +325,4 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends T this.onPrepare = onPrepare; } - public List<SetHeaderDefinition> getHeaders() { - return headers; - } - - public void setHeaders(List<SetHeaderDefinition> headers) { - this.headers = headers; - } - } diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/WireTapProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/WireTapProcessor.java index 96e27fc..aa21610 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/WireTapProcessor.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/WireTapProcessor.java @@ -17,8 +17,6 @@ package org.apache.camel.processor; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.LongAdder; @@ -29,7 +27,6 @@ import org.apache.camel.CamelContextAware; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; import org.apache.camel.ExchangePropertyKey; -import org.apache.camel.Expression; import org.apache.camel.ExtendedCamelContext; import org.apache.camel.Message; import org.apache.camel.Processor; @@ -72,11 +69,6 @@ public class WireTapProcessor extends AsyncProcessorSupport private final LongAdder taskCount = new LongAdder(); private ProcessorExchangeFactory processorExchangeFactory; private PooledExchangeTaskFactory taskFactory; - - // expression or processor used for populating a new exchange to send - // as opposed to traditional wiretap that sends a copy of the original exchange - private Expression newExchangeExpression; - private List<Processor> newExchangeProcessors; private Processor onPrepare; public WireTapProcessor(SendDynamicProcessor dynamicSendProcessor, Processor processor, String uri, @@ -233,24 +225,6 @@ public class WireTapProcessor extends AsyncProcessorSupport answer = configureNewExchange(exchange); } - // prepare the exchange - if (newExchangeExpression != null) { - Object body = newExchangeExpression.evaluate(answer, Object.class); - if (body != null) { - answer.getIn().setBody(body); - } - } - - if (newExchangeProcessors != null) { - for (Processor processor : newExchangeProcessors) { - try { - processor.process(answer); - } catch (Exception e) { - throw RuntimeCamelException.wrapRuntimeCamelException(e); - } - } - } - // if the body is a stream cache we must use a copy of the stream in the wire tapped exchange Message msg = answer.getMessage(); if (msg.getBody() instanceof StreamCache) { @@ -294,29 +268,6 @@ public class WireTapProcessor extends AsyncProcessorSupport return processorExchangeFactory.create(exchange.getFromEndpoint(), ExchangePattern.InOnly); } - public List<Processor> getNewExchangeProcessors() { - return newExchangeProcessors; - } - - public void setNewExchangeProcessors(List<Processor> newExchangeProcessors) { - this.newExchangeProcessors = newExchangeProcessors; - } - - public Expression getNewExchangeExpression() { - return newExchangeExpression; - } - - public void setNewExchangeExpression(Expression newExchangeExpression) { - this.newExchangeExpression = newExchangeExpression; - } - - public void addNewExchangeProcessor(Processor processor) { - if (newExchangeProcessors == null) { - newExchangeProcessors = new ArrayList<>(); - } - newExchangeProcessors.add(processor); - } - public boolean isCopy() { return copy; } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java index 4c8bc70..7431efc 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java @@ -29,7 +29,6 @@ import org.apache.camel.Route; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.ProcessorDefinitionHelper; import org.apache.camel.model.RouteDefinition; -import org.apache.camel.model.SetHeaderDefinition; import org.apache.camel.model.WireTapDefinition; import org.apache.camel.processor.SendDynamicProcessor; import org.apache.camel.processor.SendProcessor; @@ -97,25 +96,8 @@ public class WireTapReifier extends ToDynamicReifier<WireTapDefinition<?>> { dynamicSendProcessor, target, uri, parse(ExchangePattern.class, definition.getPattern()), isCopy, threadPool, shutdownThreadPool, dynamic); - Processor newExchangeProcessor = definition.getNewExchangeProcessor(); - String ref = parseString(definition.getNewExchangeProcessorRef()); - if (ref != null) { - newExchangeProcessor = mandatoryLookup(ref, Processor.class); - } - if (newExchangeProcessor != null) { - answer.addNewExchangeProcessor(newExchangeProcessor); - } - if (definition.getNewExchangeExpression() != null) { - answer.setNewExchangeExpression(createExpression(definition.getNewExchangeExpression())); - } - if (definition.getHeaders() != null && !definition.getHeaders().isEmpty()) { - for (SetHeaderDefinition header : definition.getHeaders()) { - Processor processor = createProcessor(header); - answer.addNewExchangeProcessor(processor); - } - } Processor onPrepare = definition.getOnPrepare(); - ref = parseString(definition.getOnPrepareRef()); + String ref = parseString(definition.getOnPrepareRef()); if (ref != null) { onPrepare = mandatoryLookup(ref, Processor.class); } diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapNewExchangeTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/WireTapNewExchangeTest.java deleted file mode 100644 index 9623efc..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapNewExchangeTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.camel.ContextTestSupport; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -public class WireTapNewExchangeTest extends ContextTestSupport { - - @Test - public void testFireAndForgetUsingExpressions() throws Exception { - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("Hello World"); - - MockEndpoint tap = getMockEndpoint("mock:tap"); - tap.expectedBodiesReceived("Bye World"); - tap.expectedHeaderReceived("id", 123); - String today = new SimpleDateFormat("yyyyMMdd").format(new Date()); - tap.expectedHeaderReceived("date", today); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - // START SNIPPET: e1 - from("direct:start") - // tap a new message and send it to direct:tap - // the new message should be Bye World with 2 headers - .wireTap("direct:tap") - // create the new tap message body and headers - .newExchangeBody(constant("Bye World")).newExchangeHeader("id", constant(123)) - .newExchangeHeader("date", simple("${date:now:yyyyMMdd}")).end() - // here we continue routing the original messages - .to("mock:result"); - - // this is the tapped route - from("direct:tap").to("mock:tap"); - // END SNIPPET: e1 - } - }; - } -} diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java index 93907b3..c074c0a 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/WireTapOnPrepareTest.java @@ -54,7 +54,7 @@ public class WireTapOnPrepareTest extends ContextTestSupport { @Override public void configure() throws Exception { // START SNIPPET: e1 - from("direct:start").wireTap("direct:a").copy().newExchange(new AnimalDeepClonePrepare()).to("direct:b"); + from("direct:start").wireTap("direct:a").copy().onPrepare(new AnimalDeepClonePrepare()).to("direct:b"); // END SNIPPET: e1 from("direct:a").process(new ProcessorA()).to("mock:a"); diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyAsDefaultTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyAsDefaultTest.java deleted file mode 100644 index 0b2d169..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyAsDefaultTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -public class WireTapUsingFireAndForgetCopyAsDefaultTest extends ContextTestSupport { - - @Override - public boolean isUseRouteBuilder() { - return false; - } - - @Test - public void testFireAndForgetUsingProcessor() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - // START SNIPPET: e1 - from("direct:start").wireTap("direct:foo").copy().newExchange(exchange -> { - String body = exchange.getIn().getBody(String.class); - exchange.getIn().setBody("Bye " + body); - exchange.getIn().setHeader("foo", "bar"); - }).to("mock:result"); - - from("direct:foo").to("mock:foo"); - // END SNIPPET: e1 - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - foo.expectedHeaderReceived("foo", "bar"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingProcessor2() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").wireTap("direct:foo").copy().newExchange(exchange -> { - String body = exchange.getIn().getBody(String.class); - exchange.getIn().setBody("Bye " + body); - exchange.getIn().setHeader("foo", "bar"); - }).to("mock:result"); - - from("direct:foo").to("mock:foo"); - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - foo.expectedHeaderReceived("foo", "bar"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingExpression() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - // START SNIPPET: e2 - from("direct:start").wireTap("direct:foo").copy().newExchangeBody(simple("Bye ${body}")).to("mock:result"); - - from("direct:foo").to("mock:foo"); - // END SNIPPET: e2 - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingExpression2() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").wireTap("direct:foo").copy().newExchangeBody(simple("Bye ${body}")).to("mock:result"); - - from("direct:foo").to("mock:foo"); - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - -} diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyTest.java deleted file mode 100644 index 68bbd2a..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetCopyTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -public class WireTapUsingFireAndForgetCopyTest extends ContextTestSupport { - - @Override - public boolean isUseRouteBuilder() { - return false; - } - - @Test - public void testFireAndForgetUsingProcessor() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - // START SNIPPET: e1 - from("direct:start").wireTap("direct:foo").copy().newExchange(exchange -> { - String body = exchange.getIn().getBody(String.class); - exchange.getIn().setBody("Bye " + body); - exchange.getIn().setHeader("foo", "bar"); - }).to("mock:result"); - - from("direct:foo").to("mock:foo"); - // END SNIPPET: e1 - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - foo.expectedHeaderReceived("foo", "bar"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingProcessor2() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").wireTap("direct:foo").copy().newExchange(exchange -> { - String body = exchange.getIn().getBody(String.class); - exchange.getIn().setBody("Bye " + body); - exchange.getIn().setHeader("foo", "bar"); - }).to("mock:result"); - - from("direct:foo").to("mock:foo"); - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - foo.expectedHeaderReceived("foo", "bar"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingExpression() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - // START SNIPPET: e2 - from("direct:start").wireTap("direct:foo").copy(true).newExchangeBody(simple("Bye ${body}")).to("mock:result"); - - from("direct:foo").to("mock:foo"); - // END SNIPPET: e2 - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingExpression2() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:start").wireTap("direct:foo").copy(true).newExchangeBody(simple("Bye ${body}")).to("mock:result"); - - from("direct:foo").to("mock:foo"); - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - -} diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetTest.java deleted file mode 100644 index f4d5461..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/processor/WireTapUsingFireAndForgetTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -public class WireTapUsingFireAndForgetTest extends ContextTestSupport { - - @Override - public boolean isUseRouteBuilder() { - return false; - } - - @Test - public void testFireAndForgetUsingProcessor() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - // START SNIPPET: e1 - from("direct:start").wireTap("direct:foo").copy(false).newExchange(exchange -> { - exchange.getIn().setBody("Bye World"); - exchange.getIn().setHeader("foo", "bar"); - }).to("mock:result"); - - from("direct:foo").to("mock:foo"); - // END SNIPPET: e1 - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("Hello World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - foo.expectedHeaderReceived("foo", "bar"); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - - @Test - public void testFireAndForgetUsingExpression() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - // START SNIPPET: e2 - from("direct:start").wireTap("direct:foo").copy(false).newExchangeBody(constant("Bye World")).to("mock:result"); - - from("direct:foo").to("mock:foo"); - // END SNIPPET: e2 - } - }); - context.start(); - - MockEndpoint result = getMockEndpoint("mock:result"); - result.expectedBodiesReceived("Hello World"); - - MockEndpoint foo = getMockEndpoint("mock:foo"); - foo.expectedBodiesReceived("Bye World"); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - - // should be different exchange instances - Exchange e1 = result.getReceivedExchanges().get(0); - Exchange e2 = foo.getReceivedExchanges().get(0); - assertNotSame(e1, e2, "Should not be same Exchange"); - - // should have same from endpoint - assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); - assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); - } - -} diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWireTapNewExchangeBodyTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWireTapNewExchangeBodyTest.java deleted file mode 100644 index d49a67b..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWireTapNewExchangeBodyTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.onexception; - -import org.apache.camel.ContextTestSupport; -import org.apache.camel.builder.RouteBuilder; -import org.junit.jupiter.api.Test; - -public class OnExceptionWireTapNewExchangeBodyTest extends ContextTestSupport { - - @Test - public void testOnExceptionWireTapNewExchangeBody() throws Exception { - getMockEndpoint("mock:tap").expectedBodiesReceived("Error due Forced"); - getMockEndpoint("mock:ignore").expectedMessageCount(1); - - template.sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - onException(IllegalArgumentException.class).wireTap("mock:tap") - .newExchangeBody(simple("Error due ${exception.message}")).end().handled(true).to("mock:ignore"); - - from("direct:start").throwException(new IllegalArgumentException("Forced")); - } - }; - } -} diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java index bf17d23..9df72d5 100644 --- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java +++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java @@ -1562,18 +1562,10 @@ public class ModelParser extends BaseParser { case "dynamicUri": def.setDynamicUri(val); break; case "executorServiceRef": def.setExecutorServiceRef(val); break; case "onPrepareRef": def.setOnPrepareRef(val); break; - case "processorRef": def.setNewExchangeProcessorRef(val); break; default: return toDynamicDefinitionAttributeHandler().accept(def, key, val); } return true; - }, (def, key) -> { - switch (key) { - case "setHeader": doAdd(doParseSetHeaderDefinition(), def.getHeaders(), def::setHeaders); break; - case "body": def.setNewExchangeExpression(doParseExpressionSubElementDefinition()); break; - default: return optionalIdentifiedDefinitionElementHandler().accept(def, key); - } - return true; - }, noValueHandler()); + }, optionalIdentifiedDefinitionElementHandler(), noValueHandler()); } protected BlacklistServiceCallServiceFilterConfiguration doParseBlacklistServiceCallServiceFilterConfiguration() throws IOException, XmlPullParserException { return doParse(new BlacklistServiceCallServiceFilterConfiguration(), diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc index 1fed0b8..04e8366 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc @@ -51,6 +51,10 @@ To: </saga> ---- +==== WireTap EIP + +Removed the _new message_ mode as this functionality is better done by using onPrepare processor in copy mode. + === camel-health The `HealthCheck` API has been simplified and removed the following configurations: diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java index 47f9b1c..c31e5f8 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java @@ -17852,7 +17852,6 @@ public final class ModelDeserializers extends YamlDeserializerSupport { properties = { @YamlProperty(name = "allow-optimised-components", type = "boolean"), @YamlProperty(name = "auto-start-components", type = "boolean"), - @YamlProperty(name = "body", type = "object:org.apache.camel.model.ExpressionSubElementDefinition"), @YamlProperty(name = "cache-size", type = "number"), @YamlProperty(name = "copy", type = "boolean"), @YamlProperty(name = "description", type = "string"), @@ -17864,8 +17863,6 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "on-prepare-ref", type = "string"), @YamlProperty(name = "parameters", type = "object"), @YamlProperty(name = "pattern", type = "string"), - @YamlProperty(name = "processor-ref", type = "string"), - @YamlProperty(name = "set-header", type = "array:org.apache.camel.model.SetHeaderDefinition"), @YamlProperty(name = "uri", type = "string", required = true) } ) @@ -17919,11 +17916,6 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setExecutorServiceRef(val); break; } - case "set-header": { - java.util.List<org.apache.camel.model.SetHeaderDefinition> val = asFlatList(node, org.apache.camel.model.SetHeaderDefinition.class); - target.setHeaders(val); - break; - } case "ignore-invalid-endpoint": { String val = asText(node); target.setIgnoreInvalidEndpoint(val); @@ -17934,16 +17926,6 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setInheritErrorHandler(java.lang.Boolean.valueOf(val)); break; } - case "body": { - org.apache.camel.model.ExpressionSubElementDefinition val = asType(node, org.apache.camel.model.ExpressionSubElementDefinition.class); - target.setNewExchangeExpression(val); - break; - } - case "processor-ref": { - String val = asText(node); - target.setNewExchangeProcessorRef(val); - break; - } case "on-prepare-ref": { String val = asText(node); target.setOnPrepareRef(val); diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json index cebf21a..11ec70d 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json @@ -3530,9 +3530,6 @@ "auto-start-components" : { "type" : "boolean" }, - "body" : { - "$ref" : "#/items/definitions/org.apache.camel.model.ExpressionSubElementDefinition" - }, "cache-size" : { "type" : "number" }, @@ -3566,15 +3563,6 @@ "pattern" : { "type" : "string" }, - "processor-ref" : { - "type" : "string" - }, - "set-header" : { - "type" : "array", - "items" : { - "$ref" : "#/items/definitions/org.apache.camel.model.SetHeaderDefinition" - } - }, "uri" : { "type" : "string" } diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camelYamlDsl.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camelYamlDsl.json index eba1f0c..23e16e1 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camelYamlDsl.json +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camelYamlDsl.json @@ -3431,9 +3431,6 @@ "autoStartComponents" : { "type" : "boolean" }, - "body" : { - "$ref" : "#/items/definitions/org.apache.camel.model.ExpressionSubElementDefinition" - }, "cacheSize" : { "type" : "number" }, @@ -3467,15 +3464,6 @@ "pattern" : { "type" : "string" }, - "processorRef" : { - "type" : "string" - }, - "setHeader" : { - "type" : "array", - "items" : { - "$ref" : "#/items/definitions/org.apache.camel.model.SetHeaderDefinition" - } - }, "uri" : { "type" : "string" }