...
Here is a custom factory which will alter the processor definitions.
Wiki Markup |
---|
{snippet:id=e3|lang=java|title=MyFactory|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CustomProcessorFactoryTest.java} |
The unit test and route is as follows:
Wiki Markup |
---|
{snippet:id=e2|lang=java|title=Unit test and route|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CustomProcessorFactoryTest.java} |
Now the idea is that the setBody
processors has been changed by the factory to set a different body.
Also the Splitter has one additional output where we send the splitted message to mock:extra
endpoint.
Notice we just return null
which instructs Camel to use its default implementation to create the Processor. After all we just wanted to manipulate the definition. However if you do return a Processor then Camel use the returned processor.
Java DSL
In Java DSL all you need to do is to configure the custom factory on the CamelContext as shown:e1 using the setProcessorFactory
method:
Code Block | ||
---|---|---|
| ||
CamelContext context ...
context.setProcessorFactory(new MyFactory());
|
Spring XML
In Spring XML all you have to do is just to declare a <bean> tag with the custom factory, and Camel will automatic lookup it up and use it.
Wiki Markup |
---|
{snippet:id=e1|lang=xml|title=Configuring ProcessorFactory in Spring|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/CustomProcessorFactoryTest.xml} |