This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit bc7ffb42b76d4098935e0fa8d04ab81be1a81de0 Author: Otavio R. Piske <angusyo...@gmail.com> AuthorDate: Sun Feb 25 15:01:45 2024 +0100 CAMEL-20459: minor documentation tweaks for the normalizer EIP. Signed-off-by: Otavio R. Piske <angusyo...@gmail.com> --- .../main/docs/modules/eips/pages/normalizer.adoc | 62 ++++++++++++---------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/normalizer.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/normalizer.adoc index 57fc2ff37f5..26742f62688 100644 --- a/core/camel-core-engine/src/main/docs/modules/eips/pages/normalizer.adoc +++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/normalizer.adoc @@ -9,8 +9,8 @@ but arrive in different formats. The normalizer transforms the incoming messages image::eip/NormalizerDetail.gif[image] -In Apache Camel, you can implement the normalizer pattern by combining a xref:choice-eip.adoc[Content Based Router], -which detects the incoming message's format, with a collection of different xref:message-translator.adoc[Message Translator]'s, +In Apache Camel, you can implement the normalizer pattern by combining a xref:choice-eip.adoc[Content-Based Router], +which detects the incoming message's format, with a collection of different xref:message-translator.adoc[Message Translators], which transform the different incoming formats into a common format. == Example @@ -18,6 +18,11 @@ which transform the different incoming formats into a common format. This example shows a Message Normalizer that converts two types of XML messages into a common format. Messages in this common format are then routed. +[tabs] +==== + +Java:: ++ [source,java] ---- // we need to normalize two types of incoming messages @@ -29,31 +34,9 @@ from("direct:start") .to("mock:result"); ---- -In this case we're using a Java xref:ROOT:bean-component.adoc[Bean] as the normalizer. - -The class looks like this: - -[source,java] ----- -// Java -public class MyNormalizer { - - public void employeeToPerson(Exchange exchange, @XPath("/employee/name/text()") String name) { - exchange.getMessage().setBody(createPerson(name)); - } - - public void customerToPerson(Exchange exchange, @XPath("/customer/@name") String name) { - exchange.getMessage().setBody(createPerson(name)); - } - - private String createPerson(String name) { - return "<person name=\" + name + \"/>"; - } -} ----- - -The same example in XML: +XML:: ++ [source,xml] ---- <camelContext xmlns="http://camel.apache.org/schema/spring"> @@ -76,7 +59,32 @@ The same example in XML: <bean id="normalizer" class="org.apache.camel.processor.MyNormalizer"/> ---- +==== + +In this case, we're using a Java xref:ROOT:bean-component.adoc[Bean] as the normalizer. + +The class looks like this: + +[source,java] +---- +// Java +public class MyNormalizer { + + public void employeeToPerson(Exchange exchange, @XPath("/employee/name/text()") String name) { + exchange.getMessage().setBody(createPerson(name)); + } + + public void customerToPerson(Exchange exchange, @XPath("/customer/@name") String name) { + exchange.getMessage().setBody(createPerson(name)); + } + + private String createPerson(String name) { + return "<person name=\" + name + \"/>"; + } +} +---- + In case there are many incoming formats, then the xref:choice-eip.adoc[Content Based Router] -may end up with too many choices. In this situation then an alternative is to use xref:toD-eip.adoc[Dynamic to] +may end up with too many choices. In this situation, then an alternative is to use xref:toD-eip.adoc[Dynamic to] that computes a xref:ROOT:bean-component.adoc[Bean] endpoint, to be called that acts as xref:message-translator.adoc[Message Translator].