Grape Component

 

Available as of Camel 2.16 

Grape component allows you to fetch, load and manage additional jars when CamelContext is running. In practice with Camel Grape component you can add new components, data formats and beans to your CamelContext without the restart of the router.

Setting up class loader

Grape requires using Groovy class loader with the CamelContext. You can enable Groovy class loading on the existing Camel Context using the GrapeComponent#grapeCamelContext() method:

 

 You can also set up the Groovy class loader used be Camel context by yourself:

URI format

Grape component supports only producer endpoints.

For example the following snippet loads Camel FTP component:

You can also specify the Maven coordinates by sending them to the endpoint as the exchange body:

Adding the Grape component to the project

Maven users will need to add the following dependency to their pom.xml for this component:

Default payload type

By default Camel Grape component operates on the String payloads:

But of course Camel build-in type conversion API can perform the automatic data type transformations for you. In the example below Camel automatically converts binary payload into the String:

 

Headers

The following headers are recognized by the Grape component:

Header

Java constant

Endpoint typeValue type

Description

CamelGrapeCommandGrapeConstants.GRAPE_COMMANDProducerorg.apache.camel.component.grape.GrapeCommandThe command to be performed by the Grape endpoint. Default to grab.

 

Loading components at runtime

In order to load the new component at the router runtime, just grab the jar containing the given component:

Loading processors bean at runtime

In order to load the new processor bean  with your custom business login at the router runtime, just grab the jar containing the required bean:

 

Loading deployed jars after Camel context restart

After you download new jar, you usually would like to have it loaded by the Camel again after the restart of the CamelContext. It is certainly possible, as Grape component keeps track of the jar files you have installed. In order to load again the installed jars on the context startup, use the GrapeEndpoint.loadPatches() method in your route: 

 

 

Managing the installed jars

If you would like to check what jars have been installed into the given CamelContext, send message to the grape endpoint with the CamelGrapeCommand header set to GrapeCommand.listPatches:

Connecting the to the route defined above using the HTTP client returns the list of the jars installed by Grape component:

If you would like to remove the installed jars, so these won't be loaded again after the context restart, use the GrapeCommand.clearPatches command:


See Also

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram