Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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=RouteUnit 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 using the setProcessorFactory method:

Code Block
titleConfiguring ProcessorFactory in Java

  CamelContext context ...
  context.setProcessorFactory(new MyFactory());
Wiki Markup
{snippet:id=e1|lang=java|title=Configuring ProcessorFactory in Java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CustomProcessorFactoryTest.java}

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.

...