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 65aff78 CAMEL-16861: Cleanup and update EIP docs
65aff78 is described below
commit 65aff784280f466983dbf89356ba2e68009abbe8
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Sep 16 08:47:59 2021 +0200
CAMEL-16861: Cleanup and update EIP docs
---
.../docs/modules/eips/pages/content-enricher.adoc | 4 +-
.../modules/eips/pages/content-filter-eip.adoc | 80 ++++++++++++++--------
.../docs/modules/eips/pages/convertBodyTo-eip.adoc | 29 +++++++-
3 files changed, 81 insertions(+), 32 deletions(-)
diff --git
a/core/camel-core-engine/src/main/docs/modules/eips/pages/content-enricher.adoc
b/core/camel-core-engine/src/main/docs/modules/eips/pages/content-enricher.adoc
index cc62b0f..4d73a23 100644
---
a/core/camel-core-engine/src/main/docs/modules/eips/pages/content-enricher.adoc
+++
b/core/camel-core-engine/src/main/docs/modules/eips/pages/content-enricher.adoc
@@ -79,8 +79,8 @@ explicit Java to enrich the message:
from("direct:start")
.process(new Processor() {
public void process(Exchange exchange) {
- Message in = exchange.getIn();
- in.setBody(in.getBody(String.class) + " World!");
+ Message msg = exchange.getMessage();
+ msg.setBody(msg.getBody(String.class) + " World!");
}
})
.to("mock:result");
diff --git
a/core/camel-core-engine/src/main/docs/modules/eips/pages/content-filter-eip.adoc
b/core/camel-core-engine/src/main/docs/modules/eips/pages/content-filter-eip.adoc
index f437ef0..604e404 100644
---
a/core/camel-core-engine/src/main/docs/modules/eips/pages/content-filter-eip.adoc
+++
b/core/camel-core-engine/src/main/docs/modules/eips/pages/content-filter-eip.adoc
@@ -8,55 +8,77 @@ xref:enterprise-integration-patterns.adoc[EIP patterns]
using one of the following mechanisms in the routing logic to transform
content from the inbound message.
-* xref:message-translator.adoc[Message Translator]
-* invoking a xref:latest@manual:ROOT:bean-integration.adoc[Java bean]
-* xref:latest@manual:ROOT:processor.adoc[Processor] object
-
image::eip/ContentFilter.gif[image]
-A common way to filter messages is to use an
-xref:latest@manual:ROOT:expression.adoc[Expression] in the
xref:latest@manual:ROOT:dsl.adoc[DSL] like
-xref:components:languages:xquery-language.adoc[XQuery].
+* Using a xref:message-translator.adoc[Message Translator]
+* Invoking a xref:bean-eip.adoc[Bean] with the filtering programmed in Java
+* Using a xref:latest@manual:ROOT:processor.adoc[Processor] with the filtering
programmed in Java
+* Using an xref:latest@manual:ROOT:expression.adoc[Expression]
+
+== Message Content filtering using a Processor
-Here is a simple example using the xref:latest@manual:ROOT:dsl.adoc[DSL]
directly
+In this example we add our own
xref:latest@manual:ROOT:processor.adoc[Processor] using
+explicit Java to filter the message:
+
+[source,java]
+----
+from("direct:start")
+ .process(new Processor() {
+ public void process(Exchange exchange) {
+ String body = exchange.getMessage().getBody(String.class);
+ // do something with the body
+ // and replace it back
+ exchange.getMessage().setBody(body);
+ }
+ })
+ .to("mock:result");
+----
-In this example we add our own
xref:latest@manual:ROOT:processor.adoc[Processor]
+== Message Content filtering using a Bean EIP
-For further examples of this pattern in use you could look at one of the
-JUnit tests
+we can use xref:bean-eip.adoc[Bean EIP] to use any Java
+method on any bean to act as content filter:
-*
https://github.com/apache/camel/blob/main/core/camel-core/src/test/java/org/apache/camel/processor/TransformTest.java[TransformTest]
-*
https://github.com/apache/camel/blob/main/core/camel-core/src/test/java/org/apache/camel/processor/TransformViaDSLTest.java[TransformViaDSLTest]
+[source,java]
+----
+from("activemq:My.Queue")
+ .bean("myBeanName", "doFilter")
+ .to("activemq:Another.Queue");
+----
-== Using Spring XML
+And in XML DSL:
[source,xml]
----
<route>
- <from uri="activemq:Input"/>
- <bean ref="myBeanName" method="doTransform"/>
- <to uri="activemq:Output"/>
+ <from uri="activemq:Input"/>
+ <bean ref="myBeanName" method="doFilter"/>
+ <to uri="activemq:Output"/>
</route>
----
-You can also use XPath to filter out part of the message you are
-interested in:
+== Message Content filtering using expression
+
+Some languages like xref:components:languages:xpath-language.adoc[XPath], and
xref:components:languages:xquery-language.adoc[XQuery]
+can be used to transform and filter content from messages.
+
+In the example we use xpath to filter a XML message to select all the
`<foo><bar>` elements:
+
+[source,java]
+----
+from("activemq:Input")
+ .setBody().xpath("//foo:bar")
+ .to("activemq:Output");
+----
+
+And in XML DSL:
[source,xml]
----
<route>
<from uri="activemq:Input"/>
- <setBody><xpath resultType="org.w3c.dom.Document">//foo:bar</xpath></setBody>
+ <setBody><xpath>//foo:bar</xpath></setBody>
<to uri="activemq:Output"/>
</route>
----
-[[ContentFilter-UsingThisPattern]]
-== Using This Pattern
-
-If you would like to use this EIP Pattern then please read the
-xref:latest@manual:ROOT:getting-started.adoc[Getting Started], you may also
find the
-xref:latest@manual:ROOT:architecture.adoc[Architecture] useful particularly
the description
-of xref:latest@manual:ROOT:endpoint.adoc[Endpoint] and
xref:latest@manual:ROOT:uris.adoc[URIs]. Then you could
-try out some of the xref:latest@manual:ROOT:examples.adoc[Examples] first
before trying
-this pattern out.
diff --git
a/core/camel-core-engine/src/main/docs/modules/eips/pages/convertBodyTo-eip.adoc
b/core/camel-core-engine/src/main/docs/modules/eips/pages/convertBodyTo-eip.adoc
index 8e9a0e84..a1525cc 100644
---
a/core/camel-core-engine/src/main/docs/modules/eips/pages/convertBodyTo-eip.adoc
+++
b/core/camel-core-engine/src/main/docs/modules/eips/pages/convertBodyTo-eip.adoc
@@ -5,7 +5,7 @@
:since:
:supportLevel: Stable
-The ConvertBodyTo EIP allows you to transform your body to a different type.
+The ConvertBodyTo EIP allows you to transform the message body to a different
type.
// eip options: START
The Convert Body To EIP supports 3 options which are listed below:
@@ -18,3 +18,30 @@ The Convert Body To EIP supports 3 options which are listed
below:
| *charset* | To use a specific charset when converting | | String
|===
// eip options: END
+
+The type is a FQN classname (fully qualified), so for example
`java.lang.String`, `com.foo.MyBean` etc.
+However, Camel has shorthand for common Java types, most noticeable `String`
can be used instead of `java.lang.String`.
+You can also use `byte[]` for a byte array.
+
+== Example
+
+A common use-case is for converting the message body to a `String`:
+
+[source,java]
+----
+from("file:inbox")
+ .convertBodyTo(String.class)
+ .log("The file content: ${body}");
+----
+
+And in XML DSL:
+
+[source,xml]
+----
+<route>
+ <from uri="file:inbox"/>
+ <convertBodyTo type="String"/>
+ <log message="The file content: ${body}"/>
+</route>
+----
+