此内容没有您所选择的语言版本。

Chapter 15. Apache Camel Integration


15.1. Apache Camel-Smooks Integration

The Camel-Smooks integration lets you to access all of Smooks' capabilities from within Apache Camel. You can take an existing Smooks configuration and use this in your Camel routes.

15.2. Methods of Using Smooks in Apache Camel

There are three ways in which you can use Smooks in Apache Camel:
  • SmooksComponent
  • SmooksDataformat
  • SmooksProcessor

15.3. SmooksComponent

The SmooksComponent is a Camel module which you can use when you want to process the Camel message body using Smooks.

15.4. Using the SmooksComponent

  1. Add a route to your Camel route configuration as shown below:
    from("file://inputDir?noop=true")
    .to("smooks://smooks-config.xml")
    .to("jms:queue:order")
    
    Copy to Clipboard Toggle word wrap
  2. Edit the values in the 'smooks-config-xml' file. You cannot tell what type of output the SmooksComponent is producing just by looking at the route configuration. Instead, this is expressed in the Smooks configuration via the exports element.

    Note

    If you would prefer to configure Smooks programmatically, you can set this using the SmooksProcessor

15.5. SmooksComponent Configuration

An Apache component can use any options that are specified after the Smooks configuration file. Currently only one option is available for the SmooksComponent:
  • reportPath: this is the path (including the file name) to the Smooks Execution Report that is to be generated.

15.6. SmooksDataFormat

SmooksDataFormat is an Apache Camel DataFormat. It is capable of transforming one data format to another and back again. Use this when you are only interested in transforming from one format to another and do not need to use any other Smooks features.

15.7. SmooksDataFormat Example

This example code demonstrates how to use SmooksDataFormat to transform a comma-separated value string into a java.util.List of Customer object instances:
SmooksDataFormat sdf = new SmooksDataFormat("csv-smooks-unmarshal-config.xml");
from("direct:unmarshal")
.unmarshal(sdf)
.convertBodyTo(List.class)
.to("mock:result");
Copy to Clipboard Toggle word wrap

15.8. SmooksProcessor

Using the SmooksProcessor gives you full control over Smooks. (If, for example, you want to programmatically create the underlying Smooks instance you would use this component.) When you are using the SmooksProcessor, you can programmatically configure Smooks and then pass a Smooks instance to its constructor.

15.9. SmooksProcessor Example

This example demonstrates how to use the SmooksProcessor in an Apache Camel route:
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 exports element or you can do the same programmatically like this:

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");
Copy to Clipboard Toggle word wrap

15.10. Camel Properties

Expand
Table 15.1. Camel Properties
Name Description
camel-dataformat
This example illustrates how to use the SmooksDataFormat. (A DataFormat is a class that implements Camel's org.apache.camel.spi.DataFormat.)
camel-integration
This example illustrates how to use the Camel SmooksComponent. ("smooks://file:./configs/smooks-config.xml")
splitting-camel
This example demonstrates how to use Smooks and Apache Camel to process a UN/EDIFACT message interchange, splitting the individual interchange messages out into Java and XML fragments and routing the fragments using Apache Camel.

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat