Chapter 129. Smooks component


Since Camel 4.7

Only producer is supported

The Camel Smooks component uses Smooks to break up the structured data (EDI, CSV, POJO, and so on) of a Camel message body into fragments. These fragments can be processed independently of one another from within Smooks.

Common applications of Smooks include:

  • transformation: EDI to CSV, POJO to EDI, POJO to XML, and so on.
  • scalable processing: process huge payloads while keeping a small memory footprint.
  • split, transform, and route fragments to destinations such as JMS queues, file systems, and databases.
  • enrichment: enrich fragments with data from a database or other data sources.
  • Java binding: populate POJOs from a source such as CSV, EDI, XML, and other POJOs.

Use the Smooks Data Format instead of this component when you are primarily interested in transformation and binding. This should be used for other Smooks features, like routing.

129.1. Dependencies

When using camel-smooks with Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration:

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-smooks-starter</artifactId>
</dependency>
Copy to Clipboard Toggle word wrap

129.2. URI Format

smooks://smooks-config-path[?options]
Copy to Clipboard Toggle word wrap

129.3. Configuring Options

Camel components are configured on two separate levels:

  • component level
  • endpoint level

129.3.1. Configuring component options

The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.

129.3.2. Configuring endpoint options

Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.

The following two sections lists all the options, firstly for the component followed by the endpoint.

129.4. Component Options

The Smooks component supports 3 options, which are listed below.

Expand
NameDescriptionDefaultType

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

smooksFactory (advanced)

Autowired To use a custom factory for creating Smooks.

 

SmooksFactory

129.5. Endpoint Options

The Smooks endpoint is configured using URI syntax:

smooks:smooksConfig
Copy to Clipboard Toggle word wrap

With the following path and query parameters:

129.5.1. Path Parameters (1 parameters)

Expand
NameDescriptionDefaultType

smooksConfig (producer)

Required Path to the Smooks configuration file.

 

String

129.5.2. Query Parameters (3 parameters)

Expand
NameDescriptionDefaultType

reportPath (producer)

File path to place the generated HTML execution report. The report is a useful tool in the developers arsenal for diagnosing issues or comprehending a transformation. Do not set in production since this is a major performance drain.

 

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

allowExecutionContextFromHeader (advanced)

Allow execution context to be set from the CamelSmooksExecutionContext header.

false

Boolean

129.6. Message Headers

The Smooks component supports 1 message header(s), which is/are listed below:

Expand
NameDescriptionDefaultType

CamelSmooksExecutionContext (advanced)

Constant: SMOOKS_EXECUTION_CONTEXT

The Smooks execution context.

 

ExecutionContext

129.7. Usage

Using the Smooks component lets you leverage all the features of Smooks, such as transformation and fragment-driven routing, from within Camel. You can take an existing Smooks configuration and reference it from your Camel routes as shown below:

Java

from("file:inputDir?noop=true")
    .to("smooks:smooks-config.xml")
    .to("jms:queue:order");
Copy to Clipboard Toggle word wrap

YAML

- from:
    uri: file:inputDir?noop=true
    steps:
      - to: smooks:smooks-config.xml
      - to: jms:queue:order
Copy to Clipboard Toggle word wrap

The Smooks component is configured with a mandatory configuration file, which is smooks-config.xml in the example above. It is not clear what type of output the component is producing from looking at the above route. By default, the message body output is a stream but the type of output can be changed by configuring {https://www.smooks.org/xsd/smooks/smooks-core-1.6.xsd}exports in the Smooks configuration as shown next:

smooks-config.xml

<smooks-resource-list xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd"
        xmlns:edi="https://www.smooks.org/xsd/smooks/edi-2.0.xsd"
        xmlns:core="https://www.smooks.org/xsd/smooks/smooks-core-1.6.xsd">

    <core:exports>
        <core:result type="org.smooks.io.sink.StringSink"/>
    </core:exports>

    <edi:parser schemaUri="/edi-mapping-model.dfdl.xsd" segmentTerminator="%NL;" dataElementSeparator="*"
                compositeDataElementSeparator="^"/>

</smooks-resource-list>
Copy to Clipboard Toggle word wrap

The {https://www.smooks.org/xsd/smooks/smooks-core-1.6.xsd}exports element in this example configures Smooks to export the execution result to Camel as a string. Keep in mind that exporting the result as string means that the whole result will be kept in-memory which could cause unexpected performance issues for large payloads.

129.7.1. Bean routing

Smooks is capable of routing fragments to Camel endpoints using the {https://www.smooks.org/xsd/smooks/camel-1.5.xsd}route element from the Smooks configuration. As an example, you can route to an endpoint by declaring the following in your Smooks configuration:

smooks-config.xml

<smooks-resource-list xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd"
                      xmlns:jb="https://www.smooks.org/xsd/smooks/javabean-1.6.xsd"
                      xmlns:camel="https://www.smooks.org/xsd/smooks/camel-1.5.xsd">

  <!-- Create some bean instances from the input source... -->
  <jb:bean beanId="orderItem"  ...>
    <!-- etc... See Smooks Java Binding docs -->
  </jb:bean>

  <!-- Route bean to camel endpoints... -->
  <camel:route beanId="orderItem">
    <camel:to endpoint="direct:slow" if="orderItem.priority = 'Normal'"/>
    <camel:to endpoint="direct:express" if="orderItem.priority = 'High'"/>
  </camel:route>

</smooks-resource-list>
Copy to Clipboard Toggle word wrap

The file above configures Smooks to route the Java bean orderItem in the bean context to the endpoints direct:slow and direct:express, depending on whether the priority field of the orderItem instance is equal to Normal or High. It is possible to route based on an event selector rather than a condition thanks to the routeOnElement XML attribute:

smooks-config.xml

<smooks-resource-list xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd"
                      xmlns:jb="https://www.smooks.org/xsd/smooks/javabean-1.6.xsd"
                      xmlns:camel="https://www.smooks.org/xsd/smooks/camel-1.5.xsd">

  <!-- Create some bean instances from the input source... -->
  <jb:bean beanId="orderItem"  ...>
    <!-- etc... See Smooks Java Binding docs -->
  </jb:bean>

  <!-- Route bean to camel endpoints... -->
  <camel:route beanId="orderItem" routeOnElement="order">
    <camel:to endpoint="direct:all"/>
  </camel:route>

</smooks-resource-list>
Copy to Clipboard Toggle word wrap

Note

Instead of routing complex objects to Camel, a pipeline allows you to have a template (e.g., FreeMarker) reference the beans and then route the evaluated template as string (e.g., XML, CSV, etc.) to Camel.

Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat
Back to top