Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smooks/smooks-camel-cartridge
Smooks Camel Cartridge
https://github.com/smooks/smooks-camel-cartridge
apache-camel camel smooks-cartridge
Last synced: about 2 months ago
JSON representation
Smooks Camel Cartridge
- Host: GitHub
- URL: https://github.com/smooks/smooks-camel-cartridge
- Owner: smooks
- License: other
- Created: 2020-03-26T23:12:17.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-12T14:20:33.000Z (3 months ago)
- Last Synced: 2024-11-12T14:35:24.335Z (3 months ago)
- Topics: apache-camel, camel, smooks-cartridge
- Language: Java
- Homepage: https://www.smooks.org/documentation/#apache_camel
- Size: 289 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Smooks Camel Cartridge
image:https://img.shields.io/maven-central/v/org.smooks.cartridges/smooks-camel-cartridge[Maven Central]
image:https://img.shields.io/nexus/s/org.smooks.cartridges/smooks-camel-cartridge?server=https%3A%2F%2Foss.sonatype.org[Sonatype Nexus (Snapshots)]
image:https://github.com/smooks/smooks-camel-cartridge/workflows/CI/badge.svg[Build Status]== Requirements
* Java 17 or higher
* Apache Camel 4.x// tag::smooks-camel-cartridge[]
It is possible to route fragments to Apache Camel endpoints using the `++` configuration from the `+https://www.smooks.org/xsd/smooks/camel-1.5.xsd+` configuration namespace.For example, you can route to Camel endpoint by specifying the following in your Smooks configuration:
.smooks-config.xml
[source,xml]
----
----
In the above example, we route Java Beans from Smooks's `+BeanContext+` to the Camel Endpoints. Note that you can also apply templates (e.g., FreeMarker) to these same beans and route the templating result instead of beans (e.g., as XML, CSV or other).
The above configuration shows routing using the `+beanId+` attribute. It is also possible to route using an attribute named `+routeOnElement+`.
== Apache Camel Integration
Integrating Smooks from Apache Camel lets you access all the features of Smooks from within Camel. You can take an existing Smooks configuration and use this in your Camel routes using one of the options that are described in this chapter.
Using Smooks in Camel can be done in three ways:
=== SmooksComponent
WARNING: SmooksComponent is removed in v4 of the cartridge and superseded by the https://camel.apache.org/components/next/smooks-component.html[Camel Smooks Component].
The `+SmooksComponent+` is a Camel https://camel.apache.org/component.html[Component] which can used when you want to process the Camel Message Body using Smooks. You can do this by adding a route in your Camel route configuration:
[source,java]
----
from("file://inputDir?noop=true")
.to("smooks://smooks-config.xml")
.to("jms:queue:order")
----The Smooks Component is configured with a mandatory configuration file, which is _smooks-config-xml_ in the example above. By just looking at the above route definition it is not clear what type of output that the SmooksComponent is producing. This is actually expressed in the Smooks configuration using the https://www.smooks.org/documentation/#exporting_results[exports] element.
If you prefer/require programmatic configuration of Smooks you can use the link:#smooksprocessor[`+SmooksProcessor+`] to achieve this.
==== Options
An Apache Component can take options that are specified after the Smooks configuration file. Currently only one option is available for the SmooksComponent:
. `+reportPath+` which is path (including the file name) to the Smooks Execution Report to be generated.
=== SmooksDataFormat
WARNING: SmooksDataFormat is removed in v4 of the cartridge and superseded by the https://camel.apache.org/components/next/dataformats/smooks-dataformat.html[Camel Smooks Data Format].
`+SmooksDataFormat+` is a Camel DataFormat which is capable of transforming from one data format to another and back again. You would use this when you are only interested in transforming from one format to another and not interested in other Smooks features.
Below is an example of using `+SmooksDataFormat+` to transform a comma separated value string into a `+java.util.List+` of Customer object instances:
[source,java]
----
SmooksDataFormat sdf = new SmooksDataFormat("csv-smooks-unmarshal-config.xml");
from("direct:unmarshal")
.unmarshal(sdf)
.convertBodyTo(List.class)
.to("mock:result");
----=== SmooksProcessor
WARNING: SmooksProcessor is removed in v4 of the cartridge and superseded by the https://camel.apache.org/components/next/smooks-component.html[Camel Smooks Component].
Using `+SmooksProcessor+` gives you full control over Smooks, for example if you want to programmatically create the underlying Smooks instance you’d use `+SmooksProcessor+`. When using `+SmooksProcessor+`, you can pass a Smooks instance to its constructor and prior to that programmatically configure Smooks.
Below is an example of using the `+SmooksProcessor+` in a Camel route:
[source,java]
----
Smooks smooks = new Smooks("edi-to-xml-smooks-config.xml");
ExecutionContext context = smooks.createExecutionContext();
...
SmooksProcessor processor = new SmooksProcessor(smooks, context);from("file://input?noop=true")
.process(processor)
.to("mock:result");
----Similar to the `+SmooksComponent+` we have not specified the result type that Smooks produces (if any that is). Instead this is expressed in the Smooks configuration using the https://www.smooks.org/documentation/#exporting_results[exports] element, or you can do the same programmatically like this:
[source,java]
----
Smooks smooks = new Smooks();
ExecutionContext context = smooks.createExecutionContext();
smooks.setExports(new Exports(StringResult.class));
SmooksProcessor processor = new SmooksProcessor(smooks, context);
...
from("file://input?noop=true")
.process(processor)
.to("mock:result");
----TIP: See the https://github.com/smooks/smooks-examples/tree/v4/camel[Apache Camel examples] in the examples page.
== Maven Coordinates
.pom.xml
[source,xml]
----org.smooks.cartridges
smooks-camel-cartridge
4.0.0----
// end::smooks-camel-cartridge[]== License
Smooks Camel Cartridge is open source and licensed under the terms of the Apache License Version 2.0, or the GNU Lesser General Public License version 3.0 or later. You may use Smooks Camel Cartridge according to either of these licenses as is most appropriate for your project.
`+SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later+`