...
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:
Code Block | ||
---|---|---|
| ||
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:
Code Block | ||
---|---|---|
| ||
camelContext.setApplicationContextClassLoader(new GroovyClassLoader(myClassLoader)); |
...
Code Block |
---|
grape:defaultMavenCoordinates[?options]
|
For example the following snippet loads Camel FTP component:
...
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:
Code Block | ||
---|---|---|
| ||
producerTemplate.sendBody("grape:defaultMavenCoordinates", "org.apache.camel/camel-ftp/2.15.2".getBytes()); |
...
In order to load the new component at the router runtime, just grab the jar containing the given component:
Code Block | ||
---|---|---|
| ||
ProducerTemplate template = camelContext.createProducerTemplate(); template.sendBody("grape:grape", "org.apache.camel/camel-stream/2.15.2"); template.sendBody("stream:out", "msg"); |
...
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:
Code Block |
---|
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) |
...
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:
...