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:


import static org.apache.camel.component.grape.GrapeComponent.grapeCamelContext;
CamelContext camelContext = grapeCamelContext(new DefaultCamelContext());

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

camelContext.setApplicationContextClassLoader(new GroovyClassLoader(myClassLoader));

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:

    <!-- use the same version as your Camel core version -->

Default payload type

By default Camel Grape component operates on the String payloads:

producerTemplate.sendBody("grape:defaultMavenCoordinates", "org.apache.camel/camel-ftp/2.15.2");

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:


producerTemplate.sendBody("grape:defaultMavenCoordinates", "org.apache.camel/camel-ftp/2.15.2".getBytes());


The following headers are recognized by the Grape component:


Java constant

Endpoint typeValue type


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:

ProducerTemplate template = camelContext.createProducerTemplate();
template.sendBody("grape:grape", "org.apache.camel/camel-stream/2.15.2");
template.sendBody("stream:out", "msg");

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:

ProducerTemplate template = camelContext.createProducerTemplate();
template.sendBody("grape:grape", "com.example/my-business-processors/1.0");
int productId = 1;
int price = template.requestBody("bean:com.example.PricingBean?method=currentProductPrice", productId, int.class)


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: 


import static org.apache.camel.component.grape.GrapeEndpoint.loadPatches;

  new RouteBuilder() { 
    public void configure() throws Exception { 


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:

        setHeader(GrapeConstats.GRAPE_COMMAND, constant(CamelGrapeCommand.listPatches)).

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

$ curl

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:

        setHeader(GrapeConstats.GRAPE_COMMAND, constant(CamelGrapeCommand.clearPatches)).
        setBody().constant("Installed patches have been deleted."); 

  • No labels