Repository: camel Updated Branches: refs/heads/master 34eb77f2c -> 9f618a28a
Added camel-grape docs to gitbook Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c7c55108 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c7c55108 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c7c55108 Branch: refs/heads/master Commit: c7c551084819553975299910653c18ce1ded56ac Parents: 34eb77f Author: Andrea Cosentino <anco...@gmail.com> Authored: Sat Apr 2 14:11:43 2016 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Sat Apr 2 14:11:43 2016 +0200 ---------------------------------------------------------------------- components/camel-grape/src/main/docs/grape.adoc | 246 +++++++++++++++++++ docs/user-manual/en/SUMMARY.md | 1 + 2 files changed, 247 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c7c55108/components/camel-grape/src/main/docs/grape.adoc ---------------------------------------------------------------------- diff --git a/components/camel-grape/src/main/docs/grape.adoc b/components/camel-grape/src/main/docs/grape.adoc new file mode 100644 index 0000000..1e9efbe --- /dev/null +++ b/components/camel-grape/src/main/docs/grape.adoc @@ -0,0 +1,246 @@ +[[Grape-GrapeComponent]] +Grape Component +~~~~~~~~~~~~~~~ + +Available as of Camel 2.16 + +http://docs.groovy-lang.org/latest/html/documentation/grape.html[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. + + +[[Grape-Options]] +Grape options +^^^^^^^^^^^^^ + +// component options: START +The Grape component has no options. +// component options: END + +// endpoint options: START +The Grape component supports 3 endpoint options which are listed below: + +[width="100%",cols="2s,1,1m,1m,5",options="header"] +|======================================================================= +| Name | Group | Default | Java Type | Description +| defaultCoordinates | | | String | *Required* Maven coordinates to use as default to grab if the message body is empty. +| exchangePattern | | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange. +| synchronous | | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). +|======================================================================= +// endpoint options: END + + +[[Grape-Settingupclassloader]] +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: + +[source,java] +-------------------------------------------------------------------------------- +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: + +[source,java] +------------------------------------------------------------------------------------ +camelContext.setApplicationContextClassLoader(new GroovyClassLoader(myClassLoader)); +------------------------------------------------------------------------------------ + +[[Grape-URIformat]] +URI format +^^^^^^^^^^ + +Grape component supports only producer endpoints. + +[source,java] +----------------------------- +grape:defaultMavenCoordinates +----------------------------- + +For example the following snippet loads Camel FTP component: + +[source,java] +------------------------------------------------ +from("direct:loadCamelFTP"). + to("grape:org.apache.camel/camel-ftp/2.15.2"); +------------------------------------------------ + +You can also specify the Maven coordinates by sending them to the +endpoint as the exchange body: + +[source,java] +---------------------------------------------------------- +from("direct:loadCamelFTP"). + setBody().constant("org.apache.camel/camel-ftp/2.15.2"). + to("grape:defaultMavenCoordinates"); +---------------------------------------------------------- + +[[Grape-AddingtheGrapecomponenttotheproject]] +Adding the Grape component to the project +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Maven users will need to add the following dependency to their `pom.xml` +for this component: + +[source,xml] +------------------------------------------------------------ +<dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-grape</artifactId> + <version>x.y.z</version> + <!-- use the same version as your Camel core version --> +</dependency> +------------------------------------------------------------ + +[[Grape-Defaultpayloadtype]] +Default payload type +^^^^^^^^^^^^^^^^^^^^ + +By default Camel Grape component operates on the String payloads: + +[source,java] +------------------------------------------------------------------------------------------------ +producerTemplate.sendBody("grape:defaultMavenCoordinates", "org.apache.camel/camel-ftp/2.15.2"); +------------------------------------------------------------------------------------------------ + +But of course Camel build-in link:type-converter.html[type conversion +API] can perform the automatic data type transformations for you. In the +example below Camel automatically converts binary payload into the +String: + + + +[source,java] +----------------------------------------------------------------------------------------------------------- +producerTemplate.sendBody("grape:defaultMavenCoordinates", "org.apache.camel/camel-ftp/2.15.2".getBytes()); +----------------------------------------------------------------------------------------------------------- + +[[Grape-Headers]] +Headers +^^^^^^^ + +The following headers are recognized by the Grape component: + +[width="100%",cols="10%,10%,10%,10%,60%",options="header",] +|======================================================================= +|Header |Java constant |Endpoint type |Value type |Description + +|`CamelGrapeCommand` |`GrapeConstants.GRAPE_COMMAND` |Producer |`org.apache.camel.component.grape.GrapeCommand` |The command to be performed by the Grape endpoint. Default to `grab`. +|======================================================================= + +[[Grape-Loadingcomponentsatruntime]] +Loading components at runtime +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In order to load the new component at the router runtime, just grab the +jar containing the given component: + +[source,java] +------------------------------------------------------------------------- +ProducerTemplate template = camelContext.createProducerTemplate(); +template.sendBody("grape:grape", "org.apache.camel/camel-stream/2.15.2"); +template.sendBody("stream:out", "msg"); +------------------------------------------------------------------------- + +[[Grape-Loadingprocessorsbeanatruntime]] +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: + +[source,java] +----------------------------------------------------------------------------------------------------------------- +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) +----------------------------------------------------------------------------------------------------------------- + + + +[[Grape-LoadingdeployedjarsafterCamelcontextrestart]] +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: + + + +[source,java] +------------------------------------------------------------------------- +import static org.apache.camel.component.grape.GrapeEndpoint.loadPatches; + +... +camelContext.addRoutes( + new RouteBuilder() { + @Override + public void configure() throws Exception { + loadPatches(camelContext); + + from("direct:loadCamelFTP"). + to("grape:org.apache.camel/camel-ftp/2.15.2"); + } + }); +------------------------------------------------------------------------- + + + +[[Grape-Managingtheinstalledjars]] +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`: + +[source,java] +---------------------------------------------------------------------------------------- + from("netty-http4:http://0.0.0.0:80/patches"). + setHeader(GrapeConstats.GRAPE_COMMAND, constant(CamelGrapeCommand.listPatches)). + to("grape:list"); +---------------------------------------------------------------------------------------- + +Connecting the to the route defined above using the HTTP client returns +the list of the jars installed by Grape component: + +[source,java] +--------------------------------------- +$ curl http://my-router.com/patches +grape:org.apache.camel/camel-ftp/2.15.2 +grape:org.apache.camel/camel-jms/2.15.2 +--------------------------------------- + +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: + +[source,java] +----------------------------------------------------------------------------------------- + from("netty-http4:http://0.0.0.0:80/patches"). + setHeader(GrapeConstats.GRAPE_COMMAND, constant(CamelGrapeCommand.clearPatches)). + setBody().constant("Installed patches have been deleted."); +----------------------------------------------------------------------------------------- + +[[Grape-SeeAlso]] +See Also +^^^^^^^^ + +* link:configuring-camel.html[Configuring Camel] +* link:component.html[Component] +* link:endpoint.html[Endpoint] +* link:getting-started.html[Getting Started] + http://git-wip-us.apache.org/repos/asf/camel/blob/c7c55108/docs/user-manual/en/SUMMARY.md ---------------------------------------------------------------------- diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md index abae3ea..22118b3 100644 --- a/docs/user-manual/en/SUMMARY.md +++ b/docs/user-manual/en/SUMMARY.md @@ -140,6 +140,7 @@ * [Google Drive](google-drive.adoc) * [Google Mail](google-mail.adoc) * [Gora](gora.adoc) + * [Grape](grape.adoc) * [Ironmq](ironmq.adoc) * [JMS](jms.adoc) * [JMX](jmx.adoc)