Flatten the component doc structure out a bit so that we have a better chance of cross page links working.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f6fea27a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f6fea27a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f6fea27a Branch: refs/heads/master Commit: f6fea27ac6b4510708814cff8e50a28dd4c847b9 Parents: d5fc6d6 Author: Hiram Chirino <hi...@hiramchirino.com> Authored: Mon Jan 25 12:30:29 2016 -0500 Committer: Hiram Chirino <hi...@hiramchirino.com> Committed: Mon Jan 25 12:30:29 2016 -0500 ---------------------------------------------------------------------- camel-website/pom.xml | 2 +- .../camel-ahc-ws/src/main/docs/ahc-ws.adoc | 114 ++ .../camel-ahc-ws/src/main/docs/readme.adoc | 114 -- components/camel-ahc/src/main/docs/ahc.adoc | 468 +++++ components/camel-ahc/src/main/docs/readme.adoc | 468 ----- components/camel-amqp/src/main/docs/readme.adoc | 168 -- components/camel-atom/src/main/docs/amqp.adoc | 168 ++ components/camel-atom/src/main/docs/atom.adoc | 144 ++ components/camel-atom/src/main/docs/readme.adoc | 144 -- components/camel-cdi/src/main/docs/cdi.adoc | 141 ++ components/camel-cdi/src/main/docs/readme.adoc | 141 -- components/camel-jms/src/main/docs/jms.adoc | 1700 ++++++++++++++++++ components/camel-jms/src/main/docs/readme.adoc | 1700 ------------------ docs/user-manual/en/SUMMARY.md | 12 +- 14 files changed, 2742 insertions(+), 2742 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/camel-website/pom.xml ---------------------------------------------------------------------- diff --git a/camel-website/pom.xml b/camel-website/pom.xml index a3d4379..7d4ca04 100644 --- a/camel-website/pom.xml +++ b/camel-website/pom.xml @@ -80,7 +80,7 @@ <copy todir="${basedir}/target/docs/user-manual" > <fileset dir="${basedir}/../docs/user-manual/en"/> </copy> - <copy todir="${basedir}/target/docs/user-manual/components"> + <copy todir="${basedir}/target/docs/user-manual" flatten="true"> <fileset dir="{basedir}/../../components"> <include name="**/src/main/docs/**"/> </fileset> http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/components/camel-ahc-ws/src/main/docs/ahc-ws.adoc ---------------------------------------------------------------------- diff --git a/components/camel-ahc-ws/src/main/docs/ahc-ws.adoc b/components/camel-ahc-ws/src/main/docs/ahc-ws.adoc new file mode 100644 index 0000000..0476bfb --- /dev/null +++ b/components/camel-ahc-ws/src/main/docs/ahc-ws.adoc @@ -0,0 +1,114 @@ +[[AHC-WS-AsyncHttpClientWebsocketClientComponent]] +Async Http Client (AHC) Websocket Client Component +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +*Available as of Camel 2.14* + +The *ahc-ws* component provides Websocket +based link:endpoint.html[endpoints] for a client communicating with +external servers over Websocket (as a client opening a websocket +connection to an external server). + +The component uses the link:ahc.html[AHC] component that in turn uses +the https://github.com/AsyncHttpClient/async-http-client[Async Http +Client] library. + +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-ahc-ws</artifactId> + <version>x.x.x</version> + <!-- use the same version as your Camel core version --> +</dependency> +------------------------------------------------------------ + +[[AHC-WS-URIFormat]] +URI Format +^^^^^^^^^^ + +[source,java] +------------------------------------------------- +ahc-ws://hostname[:port][/resourceUri][?options] +ahc-wss://hostname[:port][/resourceUri][?options] +------------------------------------------------- + +Will by default use port 80 for ahc-ws and 443 for ahc-wss. + +[[AHC-WS-AHC-WSOptions]] +AHC-WS Options +^^^^^^^^^^^^^^ + +As the AHC-WS component is based on the AHC component, you can use the +various configuration options of the AHC component. + +[[AHC-WS-WritingandReadingDataoverWebsocket]] +Writing and Reading Data over Websocket +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +An ahc-ws endpoint can either write data to the socket or read from the +socket, depending on whether the endpoint is configured as the producer +or the consumer, respectively. + +[[AHC-WS-ConfiguringURItoWriteorReadData]] +Configuring URI to Write or Read Data +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In the route below, Camel will write to the specified websocket +connection. + +[source,java] +----------------------------------- +from("direct:start") + .to("ahc-ws://targethost"); +----------------------------------- + +And the equivalent Spring sample: + +[source,xml] +------------------------------------------------------------ +<camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <to uri="ahc-ws://targethost"/> + </route> +</camelContext> +------------------------------------------------------------ + +In the route below, Camel will read from the specified websocket +connection. + +[source,java] +--------------------------- +from("ahc-ws://targethost") + .to("direct:next"); +--------------------------- + +And the equivalent Spring sample: + +[source,xml] +------------------------------------------------------------ +<camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="ahc-ws://targethost"/> + <to uri="direct:next"/> + </route> +</camelContext> +------------------------------------------------------------ + + + +[[AHC-WS-SeeAlso]] +See Also +^^^^^^^^ + +* link:configuring-camel.html[Configuring Camel] +* link:component.html[Component] +* link:endpoint.html[Endpoint] +* link:getting-started.html[Getting Started] + +* link:../../../../camel-ahc/src/main/docs/readme.html[AHC] +* link:atmosphere-websocket.html[Atmosphere-Websocket] + http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/components/camel-ahc-ws/src/main/docs/readme.adoc ---------------------------------------------------------------------- diff --git a/components/camel-ahc-ws/src/main/docs/readme.adoc b/components/camel-ahc-ws/src/main/docs/readme.adoc deleted file mode 100644 index 0476bfb..0000000 --- a/components/camel-ahc-ws/src/main/docs/readme.adoc +++ /dev/null @@ -1,114 +0,0 @@ -[[AHC-WS-AsyncHttpClientWebsocketClientComponent]] -Async Http Client (AHC) Websocket Client Component -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*Available as of Camel 2.14* - -The *ahc-ws* component provides Websocket -based link:endpoint.html[endpoints] for a client communicating with -external servers over Websocket (as a client opening a websocket -connection to an external server). + -The component uses the link:ahc.html[AHC] component that in turn uses -the https://github.com/AsyncHttpClient/async-http-client[Async Http -Client] library. - -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-ahc-ws</artifactId> - <version>x.x.x</version> - <!-- use the same version as your Camel core version --> -</dependency> ------------------------------------------------------------- - -[[AHC-WS-URIFormat]] -URI Format -^^^^^^^^^^ - -[source,java] -------------------------------------------------- -ahc-ws://hostname[:port][/resourceUri][?options] -ahc-wss://hostname[:port][/resourceUri][?options] -------------------------------------------------- - -Will by default use port 80 for ahc-ws and 443 for ahc-wss. - -[[AHC-WS-AHC-WSOptions]] -AHC-WS Options -^^^^^^^^^^^^^^ - -As the AHC-WS component is based on the AHC component, you can use the -various configuration options of the AHC component. - -[[AHC-WS-WritingandReadingDataoverWebsocket]] -Writing and Reading Data over Websocket -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -An ahc-ws endpoint can either write data to the socket or read from the -socket, depending on whether the endpoint is configured as the producer -or the consumer, respectively. - -[[AHC-WS-ConfiguringURItoWriteorReadData]] -Configuring URI to Write or Read Data -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -In the route below, Camel will write to the specified websocket -connection. - -[source,java] ------------------------------------ -from("direct:start") - .to("ahc-ws://targethost"); ------------------------------------ - -And the equivalent Spring sample: - -[source,xml] ------------------------------------------------------------- -<camelContext xmlns="http://camel.apache.org/schema/spring"> - <route> - <from uri="direct:start"/> - <to uri="ahc-ws://targethost"/> - </route> -</camelContext> ------------------------------------------------------------- - -In the route below, Camel will read from the specified websocket -connection. - -[source,java] ---------------------------- -from("ahc-ws://targethost") - .to("direct:next"); ---------------------------- - -And the equivalent Spring sample: - -[source,xml] ------------------------------------------------------------- -<camelContext xmlns="http://camel.apache.org/schema/spring"> - <route> - <from uri="ahc-ws://targethost"/> - <to uri="direct:next"/> - </route> -</camelContext> ------------------------------------------------------------- - - - -[[AHC-WS-SeeAlso]] -See Also -^^^^^^^^ - -* link:configuring-camel.html[Configuring Camel] -* link:component.html[Component] -* link:endpoint.html[Endpoint] -* link:getting-started.html[Getting Started] - -* link:../../../../camel-ahc/src/main/docs/readme.html[AHC] -* link:atmosphere-websocket.html[Atmosphere-Websocket] - http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/components/camel-ahc/src/main/docs/ahc.adoc ---------------------------------------------------------------------- diff --git a/components/camel-ahc/src/main/docs/ahc.adoc b/components/camel-ahc/src/main/docs/ahc.adoc new file mode 100644 index 0000000..e5c1b14 --- /dev/null +++ b/components/camel-ahc/src/main/docs/ahc.adoc @@ -0,0 +1,468 @@ +[[AHC-AsyncHttpClientComponent]] +Async Http Client Component +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +*Available as of Camel 2.8* + +The *ahc:* component provides HTTP based link:endpoint.html[endpoints] +for consuming external HTTP resources (as a client to call external +servers using HTTP). + + The component uses the +https://github.com/AsyncHttpClient/async-http-client[Async Http Client] +library. + +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-ahc</artifactId> + <version>x.x.x</version> + <!-- use the same version as your Camel core version --> +</dependency> +------------------------------------------------------------ + +[[AHC-URIformat]] +URI format +^^^^^^^^^^ + +[source,java] +--------------------------------------------------- +ahc:http://hostname[:port][/resourceUri][?options] +ahc:https://hostname[:port][/resourceUri][?options] +--------------------------------------------------- + +Will by default use port 80 for HTTP and 443 for HTTPS. + +You can append query options to the URI in the following format, +`?option=value&option=value&...` + +[[AHC-AhcEndpointOptions]] +AhcEndpoint Options +^^^^^^^^^^^^^^^^^^^ + +[width="100%",cols="10%,10%,80%",options="header",] +|======================================================================= +|Name |Default Value |Description +|`throwExceptionOnFailure` |`true` |Option to disable throwing the `AhcOperationFailedException` in case of +failed responses from the remote server. This allows you to get all +responses regardless of the HTTP status code. + +|`bridgeEndpoint` |`false` |If the option is true, then the Exchange.HTTP_URI header is ignored, and +use the endpoint's URI for request. You may also set the +*throwExcpetionOnFailure* to be false to let the AhcProducer send all +the fault response back. + +|`transferException` |`false` |If enabled and an link:exchange.html[Exchange] failed processing on the +consumer side, and if the caused `Exception` was send back serialized in +the response as a `application/x-java-serialized-object` content type +(for example using link:jetty.html[Jetty] or link:servlet.html[Servlet] +Camel components). On the producer side the exception will be +deserialized and thrown as is, instead of the +`AhcOperationFailedException`. The caused exception is required to be +serialized. + +|`client` |`null` |To use a custom `com.ning.http.client.AsyncHttpClient`. + +|`clientConfig` |`null` |To configure the `AsyncHttpClient` to use a custom +`com.ning.http.client.AsyncHttpClientConfig` instance. This instance +replaces any instance configured at the component level. + +|`clientConfig.x` |`null` |To configure additional properties of the +`com.ning.http.client.AsyncHttpClientConfig` instance used by the +endpoint. Note that configuration options set using this parameter will +be merged with those set using the `clientConfig` parameter or the +instance set at the component level with properties set using this +parameter taking priority. + +|`clientConfig.realm.x` |`null` |*Camel 2.11:* To configure realm properties of the +`com.ning.http.client.AsyncHttpClientConfig` The options which can be +used are the options from `com.ning.http.client.Realm.RealmBuilder`. eg +to set scheme, you can configure `"clientConfig.realm.scheme=DIGEST"` + +|`binding` |`null` |To use a custom `org.apache.camel.component.ahc.AhcBinding`. + +|`sslContextParameters` |`null` | *Camel 2.9:* Reference to a +`org.apache.camel.util.jsse.SSLContextParameters` in the +link:registry.html[Registry]. This reference overrides any configured +SSLContextParameters at the component level. See link:ahc.html[Using +the JSSE Configuration Utility]. Note that configuring this option will +override any SSL/TLS configuration options provided through the +clientConfig option at the endpoint or component level. + +|`bufferSize` |`4096` | *Camel 2.10.3:* The initial in-memory buffer size used when transferring +data between Camel and AHC Client. +|======================================================================= + +[[AHC-AhcComponentOptions]] +AhcComponent Options +^^^^^^^^^^^^^^^^^^^^ + +[width="100%",cols="10%,10%,80%",options="header",] +|======================================================================= +|Name |Default Value |Description +|`client` |`null` |To use a custom `com.ning.http.client.AsyncHttpClient`. + +|`clientConfig` |`null` |To configure the `AsyncHttpClient` to use a custom +`com.ning.http.client.AsyncHttpClientConfig`. + +|`binding` |`null` |To use a custom `org.apache.camel.component.ahc.AhcBinding`. + +|`sslContextParameters` |`null` |*Camel 2.9:* To configure custom SSL/TLS configuration options at the +component level. See link:ahc.html[Using the JSSE Configuration +Utility] for more details. Note that configuring this option will +override any SSL/TLS configuration options provided through the +clientConfig option at the endpoint or component level. +|======================================================================= + + +Notice that setting any of the options on the `AhcComponent` will +propagate those options to +`AhcEndpoints` being created. However the `AhcEndpoint` can also +configure/override a custom option. Options set on endpoints will always +take precedence over options from the `AhcComponent`. + +[[AHC-MessageHeaders]] +Message Headers +^^^^^^^^^^^^^^^ + +[width="100%",cols="10%,10%,80%",options="header",] +|======================================================================= +|Name |Type |Description +|`Exchange.HTTP_URI` |`String` |URI to call. Will override existing URI set directly on the endpoint. + +|`Exchange.HTTP_PATH` |`String` |Request URI's path, the header will be used to build the request URI +with the HTTP_URI. If the path is start with "/", http producer will try +to find the relative path based on the Exchange.HTTP_BASE_URI header or +the `exchange.getFromEndpoint().getEndpointUri();` + +|`Exchange.HTTP_QUERY` |`String` |*Camel 2.11 onwards:* URI parameters. Will override existing URI +parameters set directly on the endpoint. + +|`Exchange.HTTP_RESPONSE_CODE` |`int` |The HTTP response code from the external server. Is 200 for OK. + +|`Exchange.HTTP_CHARACTER_ENCODING` |`String` |Character encoding. + +|`Exchange.CONTENT_TYPE` |`String` |The HTTP content type. Is set on both the IN and OUT message to provide +a content type, such as `text/html`. + +|`Exchange.CONTENT_ENCODING` |`String` |The HTTP content encoding. Is set on both the IN and OUT message to +provide a content encoding, such as `gzip`. +|======================================================================= + +[[AHC-MessageBody]] +Message Body +^^^^^^^^^^^^ + +Camel will store the HTTP response from the external server on the OUT +body. All headers from the IN message will be copied to the OUT message, +so headers are preserved during routing. Additionally Camel will add the +HTTP response headers as well to the OUT message headers. + +[[AHC-Responsecode]] +Response code +^^^^^^^^^^^^^ + +Camel will handle according to the HTTP response code: + +* Response code is in the range 100..299, Camel regards it as a success +response. +* Response code is in the range 300..399, Camel regards it as a +redirection response and will throw a `AhcOperationFailedException` with +the information. +* Response code is 400+, Camel regards it as an external server failure +and will throw a `AhcOperationFailedException` with the information. ++ +throwExceptionOnFailure ++ +The option, `throwExceptionOnFailure`, can be set to `false` to prevent +the `AhcOperationFailedException` from being thrown for failed response +codes. This allows you to get any response from the remote server. + +[[AHC-AhcOperationFailedException]] +AhcOperationFailedException +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This exception contains the following information: + +* The HTTP status code +* The HTTP status line (text of the status code) +* Redirect location, if server returned a redirect +* Response body as a `java.lang.String`, if server provided a body as +response + +[[AHC-CallingusingGETorPOST]] +Calling using GET or POST +^^^^^^^^^^^^^^^^^^^^^^^^^ + +The following algorithm is used to determine if either `GET` or `POST` +HTTP method should be used: + + 1. Use method provided in header. + + 2. `GET` if query string is provided in header. + + 3. `GET` if endpoint is configured with a query string. + + 4. `POST` if there is data to send (body is not null). + + 5. `GET` otherwise. + +[[AHC-ConfiguringURItocall]] +Configuring URI to call +^^^^^^^^^^^^^^^^^^^^^^^ + +You can set the HTTP producer's URI directly form the endpoint URI. In +the route below, Camel will call out to the external server, `oldhost`, +using HTTP. + +[source,java] +---------------------------------- +from("direct:start") + .to("ahc:http://oldhost"); +---------------------------------- + +And the equivalent Spring sample: + +[source,xml] +--------------------------------------------------------------------- +<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> + <route> + <from uri="direct:start"/> + <to uri="ahc:http://oldhost"/> + </route> +</camelContext> +--------------------------------------------------------------------- + +You can override the HTTP endpoint URI by adding a header with the key, +`Exchange.HTTP_URI`, on the message. + +[source,java] +------------------------------------------------------------- +from("direct:start") + .setHeader(Exchange.HTTP_URI, constant("http://newhost")) + .to("ahc:http://oldhost"); +------------------------------------------------------------- + +[[AHC-ConfiguringURIParameters]] +Configuring URI Parameters +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The *ahc* producer supports URI parameters to be sent to the HTTP +server. The URI parameters can either be set directly on the endpoint +URI or as a header with the key `Exchange.HTTP_QUERY` on the message. + +[source,java] +--------------------------------------------------------- +from("direct:start") + .to("ahc:http://oldhost?order=123&detail=short"); +--------------------------------------------------------- + +Or options provided in a header: + +[source,java] +------------------------------------------------------------------------------- +from("direct:start") + .setHeader(Exchange.HTTP_QUERY, constant("order=123&detail=short")) + .to("ahc:http://oldhost"); +------------------------------------------------------------------------------- + +[[AHC-HowtosetthehttpmethodtotheHTTPproducer]] +How to set the http method to the HTTP producer +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The HTTP component provides a way to set the HTTP request method by +setting the message header. Here is an example; + +[source,java] +-------------------------------------------------------------- +from("direct:start") + .setHeader(Exchange.HTTP_METHOD, constant("POST")) + .to("ahc:http://www.google.com") + .to("mock:results"); +-------------------------------------------------------------- + +And the equivalent Spring sample: + +[source,xml] +--------------------------------------------------------------------- +<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> + <route> + <from uri="direct:start"/> + <setHeader headerName="CamelHttpMethod"> + <constant>POST</constant> + </setHeader> + <to uri="ahc:http://www.google.com"/> + <to uri="mock:results"/> + </route> +</camelContext> +--------------------------------------------------------------------- + +[[AHC-Configuringcharset]] +Configuring charset +^^^^^^^^^^^^^^^^^^^ + +If you are using `POST` to send data you can configure the `charset` +using the `Exchange` property: + +[source,java] +---------------------------------------------------------- +exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1"); +---------------------------------------------------------- + +[[AHC-URIParametersfromtheendpointURI]] +URI Parameters from the endpoint URI +++++++++++++++++++++++++++++++++++++ + +In this sample we have the complete URI endpoint that is just what you +would have typed in a web browser. Multiple URI parameters can of course +be set using the `&` character as separator, just as you would in the +web browser. Camel does no tricks here. + +[source,java] +-------------------------------------------------------------------- +// we query for Camel at the Google page +template.sendBody("ahc:http://www.google.com/search?q=Camel", null); +-------------------------------------------------------------------- + +[[AHC-URIParametersfromtheMessage]] +URI Parameters from the Message ++++++++++++++++++++++++++++++++ + +[source,java] +--------------------------------------------------------------------- +Map headers = new HashMap(); +headers.put(Exchange.HTTP_QUERY, "q=Camel&lr=lang_en"); +// we query for Camel and English language at Google +template.sendBody("ahc:http://www.google.com/search", null, headers); +--------------------------------------------------------------------- + +In the header value above notice that it should *not* be prefixed with +`?` and you can separate parameters as usual with the `&` char. + +[[AHC-GettingtheResponseCode]] +Getting the Response Code ++++++++++++++++++++++++++ + +You can get the HTTP response code from the AHC component by getting the +value from the Out message header with `Exchange.HTTP_RESPONSE_CODE`. + +[source,java] +---------------------------------------------------------------------------------------------- +Exchange exchange = template.send("ahc:http://www.google.com/search", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(Exchange.HTTP_QUERY, constant("hl=en&q=activemq")); + } + }); + Message out = exchange.getOut(); + int responseCode = out.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class); +---------------------------------------------------------------------------------------------- + +[[AHC-ConfiguringAsyncHttpClient]] +Configuring AsyncHttpClient +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The `AsyncHttpClient` client uses a `AsyncHttpClientConfig` to configure +the client. See the documentation at + + http://github.com/sonatype/async-http-client[Async Http Client] for +more details. + +In Camel *2.8*, configuration is limited to using the builder pattern +provided by `AsyncHttpClientConfig.Builder`. In Camel 2.8, the +`AsyncHttpClientConfig` doesn't support getters/setters so its not easy +to create/configure using a Spring bean style (eg the <bean> tag in the +XML file). + +The example below shows how to use a builder to create the +`AsyncHttpClientConfig` which we configure on the `AhcComponent`. + +In Camel *2.9*, the AHC component uses Async HTTP library 1.6.4. This +newer version provides added support for plain bean style configuration. +The `AsyncHttpClientConfigBean` class provides getters and setters for +the configuration options available in `AsyncHttpClientConfig`. An +instance of `AsyncHttpClientConfigBean` may be passed directly to the +AHC component or referenced in an endpoint URI using the `clientConfig` +URI parameter. + +Also available in Camel *2.9* is the ability to set configuration +options directly in the URI. URI parameters starting with +"clientConfig." can be used to set the various configurable properties +of `AsyncHttpClientConfig`. The properties specified in the endpoint URI +are merged with those specified in the configuration referenced by the +"clientConfig" URI parameter with those being set using the +"clientConfig." parameter taking priority. The `AsyncHttpClientConfig` +instance referenced is always copied for each endpoint such that +settings on one endpoint will remain independent of settings on any +previously created endpoints. The example below shows how to configure +the AHC component using the "clientConfig." type URI parameters. + +[source,java] +--------------------------------------------------------------------------------------------------------- +from("direct:start") + .to("ahc:http://localhost:8080/foo?clientConfig.maxRequestRetry=3&clientConfig.followRedirects=true") +--------------------------------------------------------------------------------------------------------- + +[[AHC-SSLSupport]] +SSL Support (HTTPS) +^^^^^^^^^^^^^^^^^^^ + +[[AHC-UsingtheJSSEConfigurationUtility]] +Using the JSSE Configuration Utility + +As of Camel 2.9, the AHC component supports SSL/TLS configuration +through the link:camel-configuration-utilities.html[Camel JSSE +Configuration Utility]. This utility greatly decreases the amount of +component specific code you need to write and is configurable at the +endpoint and component levels. The following examples demonstrate how +to use the utility with the AHC component. + +[[AHC-Programmaticconfigurationofthecomponent]] +Programmatic configuration of the component + +[source,java] +------------------------------------------------------------------------- +KeyStoreParameters ksp = new KeyStoreParameters(); +ksp.setResource("/users/home/server/keystore.jks"); +ksp.setPassword("keystorePassword"); + +KeyManagersParameters kmp = new KeyManagersParameters(); +kmp.setKeyStore(ksp); +kmp.setKeyPassword("keyPassword"); + +SSLContextParameters scp = new SSLContextParameters(); +scp.setKeyManagers(kmp); + +AhcComponent component = context.getComponent("ahc", AhcComponent.class); +component.setSslContextParameters(scp)); +------------------------------------------------------------------------- + +[[AHC-SpringDSLbasedconfigurationofendpoint]] +Spring DSL based configuration of endpoint + +[source,xml] +---------------------------------------------------------------------------------- +... + <camel:sslContextParameters + id="sslContextParameters"> + <camel:keyManagers + keyPassword="keyPassword"> + <camel:keyStore + resource="/users/home/server/keystore.jks" + password="keystorePassword"/> + </camel:keyManagers> + </camel:sslContextParameters>... +... + <to uri="ahc:https://localhost/foo?sslContextParameters=#sslContextParameters"/> +... +---------------------------------------------------------------------------------- + +[[AHC-SeeAlso]] +See Also +^^^^^^^^ + +* link:configuring-camel.html[Configuring Camel] +* link:component.html[Component] +* link:endpoint.html[Endpoint] +* link:getting-started.html[Getting Started] + +* link:jetty.html[Jetty] +* link:http.html[HTTP] +* link:http4.html[HTTP4] + http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/components/camel-ahc/src/main/docs/readme.adoc ---------------------------------------------------------------------- diff --git a/components/camel-ahc/src/main/docs/readme.adoc b/components/camel-ahc/src/main/docs/readme.adoc deleted file mode 100644 index e5c1b14..0000000 --- a/components/camel-ahc/src/main/docs/readme.adoc +++ /dev/null @@ -1,468 +0,0 @@ -[[AHC-AsyncHttpClientComponent]] -Async Http Client Component -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*Available as of Camel 2.8* - -The *ahc:* component provides HTTP based link:endpoint.html[endpoints] -for consuming external HTTP resources (as a client to call external -servers using HTTP). + - The component uses the -https://github.com/AsyncHttpClient/async-http-client[Async Http Client] -library. - -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-ahc</artifactId> - <version>x.x.x</version> - <!-- use the same version as your Camel core version --> -</dependency> ------------------------------------------------------------- - -[[AHC-URIformat]] -URI format -^^^^^^^^^^ - -[source,java] ---------------------------------------------------- -ahc:http://hostname[:port][/resourceUri][?options] -ahc:https://hostname[:port][/resourceUri][?options] ---------------------------------------------------- - -Will by default use port 80 for HTTP and 443 for HTTPS. - -You can append query options to the URI in the following format, -`?option=value&option=value&...` - -[[AHC-AhcEndpointOptions]] -AhcEndpoint Options -^^^^^^^^^^^^^^^^^^^ - -[width="100%",cols="10%,10%,80%",options="header",] -|======================================================================= -|Name |Default Value |Description -|`throwExceptionOnFailure` |`true` |Option to disable throwing the `AhcOperationFailedException` in case of -failed responses from the remote server. This allows you to get all -responses regardless of the HTTP status code. - -|`bridgeEndpoint` |`false` |If the option is true, then the Exchange.HTTP_URI header is ignored, and -use the endpoint's URI for request. You may also set the -*throwExcpetionOnFailure* to be false to let the AhcProducer send all -the fault response back. - -|`transferException` |`false` |If enabled and an link:exchange.html[Exchange] failed processing on the -consumer side, and if the caused `Exception` was send back serialized in -the response as a `application/x-java-serialized-object` content type -(for example using link:jetty.html[Jetty] or link:servlet.html[Servlet] -Camel components). On the producer side the exception will be -deserialized and thrown as is, instead of the -`AhcOperationFailedException`. The caused exception is required to be -serialized. - -|`client` |`null` |To use a custom `com.ning.http.client.AsyncHttpClient`. - -|`clientConfig` |`null` |To configure the `AsyncHttpClient` to use a custom -`com.ning.http.client.AsyncHttpClientConfig` instance. This instance -replaces any instance configured at the component level. - -|`clientConfig.x` |`null` |To configure additional properties of the -`com.ning.http.client.AsyncHttpClientConfig` instance used by the -endpoint. Note that configuration options set using this parameter will -be merged with those set using the `clientConfig` parameter or the -instance set at the component level with properties set using this -parameter taking priority. - -|`clientConfig.realm.x` |`null` |*Camel 2.11:* To configure realm properties of the -`com.ning.http.client.AsyncHttpClientConfig` The options which can be -used are the options from `com.ning.http.client.Realm.RealmBuilder`. eg -to set scheme, you can configure `"clientConfig.realm.scheme=DIGEST"` - -|`binding` |`null` |To use a custom `org.apache.camel.component.ahc.AhcBinding`. - -|`sslContextParameters` |`null` | *Camel 2.9:* Reference to a -`org.apache.camel.util.jsse.SSLContextParameters` in the -link:registry.html[Registry]. This reference overrides any configured -SSLContextParameters at the component level. See link:ahc.html[Using -the JSSE Configuration Utility]. Note that configuring this option will -override any SSL/TLS configuration options provided through the -clientConfig option at the endpoint or component level. - -|`bufferSize` |`4096` | *Camel 2.10.3:* The initial in-memory buffer size used when transferring -data between Camel and AHC Client. -|======================================================================= - -[[AHC-AhcComponentOptions]] -AhcComponent Options -^^^^^^^^^^^^^^^^^^^^ - -[width="100%",cols="10%,10%,80%",options="header",] -|======================================================================= -|Name |Default Value |Description -|`client` |`null` |To use a custom `com.ning.http.client.AsyncHttpClient`. - -|`clientConfig` |`null` |To configure the `AsyncHttpClient` to use a custom -`com.ning.http.client.AsyncHttpClientConfig`. - -|`binding` |`null` |To use a custom `org.apache.camel.component.ahc.AhcBinding`. - -|`sslContextParameters` |`null` |*Camel 2.9:* To configure custom SSL/TLS configuration options at the -component level. See link:ahc.html[Using the JSSE Configuration -Utility] for more details. Note that configuring this option will -override any SSL/TLS configuration options provided through the -clientConfig option at the endpoint or component level. -|======================================================================= - - -Notice that setting any of the options on the `AhcComponent` will -propagate those options to -`AhcEndpoints` being created. However the `AhcEndpoint` can also -configure/override a custom option. Options set on endpoints will always -take precedence over options from the `AhcComponent`. - -[[AHC-MessageHeaders]] -Message Headers -^^^^^^^^^^^^^^^ - -[width="100%",cols="10%,10%,80%",options="header",] -|======================================================================= -|Name |Type |Description -|`Exchange.HTTP_URI` |`String` |URI to call. Will override existing URI set directly on the endpoint. - -|`Exchange.HTTP_PATH` |`String` |Request URI's path, the header will be used to build the request URI -with the HTTP_URI. If the path is start with "/", http producer will try -to find the relative path based on the Exchange.HTTP_BASE_URI header or -the `exchange.getFromEndpoint().getEndpointUri();` - -|`Exchange.HTTP_QUERY` |`String` |*Camel 2.11 onwards:* URI parameters. Will override existing URI -parameters set directly on the endpoint. - -|`Exchange.HTTP_RESPONSE_CODE` |`int` |The HTTP response code from the external server. Is 200 for OK. - -|`Exchange.HTTP_CHARACTER_ENCODING` |`String` |Character encoding. - -|`Exchange.CONTENT_TYPE` |`String` |The HTTP content type. Is set on both the IN and OUT message to provide -a content type, such as `text/html`. - -|`Exchange.CONTENT_ENCODING` |`String` |The HTTP content encoding. Is set on both the IN and OUT message to -provide a content encoding, such as `gzip`. -|======================================================================= - -[[AHC-MessageBody]] -Message Body -^^^^^^^^^^^^ - -Camel will store the HTTP response from the external server on the OUT -body. All headers from the IN message will be copied to the OUT message, -so headers are preserved during routing. Additionally Camel will add the -HTTP response headers as well to the OUT message headers. - -[[AHC-Responsecode]] -Response code -^^^^^^^^^^^^^ - -Camel will handle according to the HTTP response code: - -* Response code is in the range 100..299, Camel regards it as a success -response. -* Response code is in the range 300..399, Camel regards it as a -redirection response and will throw a `AhcOperationFailedException` with -the information. -* Response code is 400+, Camel regards it as an external server failure -and will throw a `AhcOperationFailedException` with the information. -+ -throwExceptionOnFailure -+ -The option, `throwExceptionOnFailure`, can be set to `false` to prevent -the `AhcOperationFailedException` from being thrown for failed response -codes. This allows you to get any response from the remote server. - -[[AHC-AhcOperationFailedException]] -AhcOperationFailedException -^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -This exception contains the following information: - -* The HTTP status code -* The HTTP status line (text of the status code) -* Redirect location, if server returned a redirect -* Response body as a `java.lang.String`, if server provided a body as -response - -[[AHC-CallingusingGETorPOST]] -Calling using GET or POST -^^^^^^^^^^^^^^^^^^^^^^^^^ - -The following algorithm is used to determine if either `GET` or `POST` -HTTP method should be used: + - 1. Use method provided in header. + - 2. `GET` if query string is provided in header. + - 3. `GET` if endpoint is configured with a query string. + - 4. `POST` if there is data to send (body is not null). + - 5. `GET` otherwise. - -[[AHC-ConfiguringURItocall]] -Configuring URI to call -^^^^^^^^^^^^^^^^^^^^^^^ - -You can set the HTTP producer's URI directly form the endpoint URI. In -the route below, Camel will call out to the external server, `oldhost`, -using HTTP. - -[source,java] ----------------------------------- -from("direct:start") - .to("ahc:http://oldhost"); ----------------------------------- - -And the equivalent Spring sample: - -[source,xml] ---------------------------------------------------------------------- -<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> - <route> - <from uri="direct:start"/> - <to uri="ahc:http://oldhost"/> - </route> -</camelContext> ---------------------------------------------------------------------- - -You can override the HTTP endpoint URI by adding a header with the key, -`Exchange.HTTP_URI`, on the message. - -[source,java] -------------------------------------------------------------- -from("direct:start") - .setHeader(Exchange.HTTP_URI, constant("http://newhost")) - .to("ahc:http://oldhost"); -------------------------------------------------------------- - -[[AHC-ConfiguringURIParameters]] -Configuring URI Parameters -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The *ahc* producer supports URI parameters to be sent to the HTTP -server. The URI parameters can either be set directly on the endpoint -URI or as a header with the key `Exchange.HTTP_QUERY` on the message. - -[source,java] ---------------------------------------------------------- -from("direct:start") - .to("ahc:http://oldhost?order=123&detail=short"); ---------------------------------------------------------- - -Or options provided in a header: - -[source,java] -------------------------------------------------------------------------------- -from("direct:start") - .setHeader(Exchange.HTTP_QUERY, constant("order=123&detail=short")) - .to("ahc:http://oldhost"); -------------------------------------------------------------------------------- - -[[AHC-HowtosetthehttpmethodtotheHTTPproducer]] -How to set the http method to the HTTP producer -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The HTTP component provides a way to set the HTTP request method by -setting the message header. Here is an example; - -[source,java] --------------------------------------------------------------- -from("direct:start") - .setHeader(Exchange.HTTP_METHOD, constant("POST")) - .to("ahc:http://www.google.com") - .to("mock:results"); --------------------------------------------------------------- - -And the equivalent Spring sample: - -[source,xml] ---------------------------------------------------------------------- -<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> - <route> - <from uri="direct:start"/> - <setHeader headerName="CamelHttpMethod"> - <constant>POST</constant> - </setHeader> - <to uri="ahc:http://www.google.com"/> - <to uri="mock:results"/> - </route> -</camelContext> ---------------------------------------------------------------------- - -[[AHC-Configuringcharset]] -Configuring charset -^^^^^^^^^^^^^^^^^^^ - -If you are using `POST` to send data you can configure the `charset` -using the `Exchange` property: - -[source,java] ----------------------------------------------------------- -exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1"); ----------------------------------------------------------- - -[[AHC-URIParametersfromtheendpointURI]] -URI Parameters from the endpoint URI -++++++++++++++++++++++++++++++++++++ - -In this sample we have the complete URI endpoint that is just what you -would have typed in a web browser. Multiple URI parameters can of course -be set using the `&` character as separator, just as you would in the -web browser. Camel does no tricks here. - -[source,java] --------------------------------------------------------------------- -// we query for Camel at the Google page -template.sendBody("ahc:http://www.google.com/search?q=Camel", null); --------------------------------------------------------------------- - -[[AHC-URIParametersfromtheMessage]] -URI Parameters from the Message -+++++++++++++++++++++++++++++++ - -[source,java] ---------------------------------------------------------------------- -Map headers = new HashMap(); -headers.put(Exchange.HTTP_QUERY, "q=Camel&lr=lang_en"); -// we query for Camel and English language at Google -template.sendBody("ahc:http://www.google.com/search", null, headers); ---------------------------------------------------------------------- - -In the header value above notice that it should *not* be prefixed with -`?` and you can separate parameters as usual with the `&` char. - -[[AHC-GettingtheResponseCode]] -Getting the Response Code -+++++++++++++++++++++++++ - -You can get the HTTP response code from the AHC component by getting the -value from the Out message header with `Exchange.HTTP_RESPONSE_CODE`. - -[source,java] ----------------------------------------------------------------------------------------------- -Exchange exchange = template.send("ahc:http://www.google.com/search", new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setHeader(Exchange.HTTP_QUERY, constant("hl=en&q=activemq")); - } - }); - Message out = exchange.getOut(); - int responseCode = out.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class); ----------------------------------------------------------------------------------------------- - -[[AHC-ConfiguringAsyncHttpClient]] -Configuring AsyncHttpClient -^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The `AsyncHttpClient` client uses a `AsyncHttpClientConfig` to configure -the client. See the documentation at + - http://github.com/sonatype/async-http-client[Async Http Client] for -more details. - -In Camel *2.8*, configuration is limited to using the builder pattern -provided by `AsyncHttpClientConfig.Builder`. In Camel 2.8, the -`AsyncHttpClientConfig` doesn't support getters/setters so its not easy -to create/configure using a Spring bean style (eg the <bean> tag in the -XML file). - -The example below shows how to use a builder to create the -`AsyncHttpClientConfig` which we configure on the `AhcComponent`. - -In Camel *2.9*, the AHC component uses Async HTTP library 1.6.4. This -newer version provides added support for plain bean style configuration. -The `AsyncHttpClientConfigBean` class provides getters and setters for -the configuration options available in `AsyncHttpClientConfig`. An -instance of `AsyncHttpClientConfigBean` may be passed directly to the -AHC component or referenced in an endpoint URI using the `clientConfig` -URI parameter. - -Also available in Camel *2.9* is the ability to set configuration -options directly in the URI. URI parameters starting with -"clientConfig." can be used to set the various configurable properties -of `AsyncHttpClientConfig`. The properties specified in the endpoint URI -are merged with those specified in the configuration referenced by the -"clientConfig" URI parameter with those being set using the -"clientConfig." parameter taking priority. The `AsyncHttpClientConfig` -instance referenced is always copied for each endpoint such that -settings on one endpoint will remain independent of settings on any -previously created endpoints. The example below shows how to configure -the AHC component using the "clientConfig." type URI parameters. - -[source,java] ---------------------------------------------------------------------------------------------------------- -from("direct:start") - .to("ahc:http://localhost:8080/foo?clientConfig.maxRequestRetry=3&clientConfig.followRedirects=true") ---------------------------------------------------------------------------------------------------------- - -[[AHC-SSLSupport]] -SSL Support (HTTPS) -^^^^^^^^^^^^^^^^^^^ - -[[AHC-UsingtheJSSEConfigurationUtility]] -Using the JSSE Configuration Utility - -As of Camel 2.9, the AHC component supports SSL/TLS configuration -through the link:camel-configuration-utilities.html[Camel JSSE -Configuration Utility]. This utility greatly decreases the amount of -component specific code you need to write and is configurable at the -endpoint and component levels. The following examples demonstrate how -to use the utility with the AHC component. - -[[AHC-Programmaticconfigurationofthecomponent]] -Programmatic configuration of the component - -[source,java] -------------------------------------------------------------------------- -KeyStoreParameters ksp = new KeyStoreParameters(); -ksp.setResource("/users/home/server/keystore.jks"); -ksp.setPassword("keystorePassword"); - -KeyManagersParameters kmp = new KeyManagersParameters(); -kmp.setKeyStore(ksp); -kmp.setKeyPassword("keyPassword"); - -SSLContextParameters scp = new SSLContextParameters(); -scp.setKeyManagers(kmp); - -AhcComponent component = context.getComponent("ahc", AhcComponent.class); -component.setSslContextParameters(scp)); -------------------------------------------------------------------------- - -[[AHC-SpringDSLbasedconfigurationofendpoint]] -Spring DSL based configuration of endpoint - -[source,xml] ----------------------------------------------------------------------------------- -... - <camel:sslContextParameters - id="sslContextParameters"> - <camel:keyManagers - keyPassword="keyPassword"> - <camel:keyStore - resource="/users/home/server/keystore.jks" - password="keystorePassword"/> - </camel:keyManagers> - </camel:sslContextParameters>... -... - <to uri="ahc:https://localhost/foo?sslContextParameters=#sslContextParameters"/> -... ----------------------------------------------------------------------------------- - -[[AHC-SeeAlso]] -See Also -^^^^^^^^ - -* link:configuring-camel.html[Configuring Camel] -* link:component.html[Component] -* link:endpoint.html[Endpoint] -* link:getting-started.html[Getting Started] - -* link:jetty.html[Jetty] -* link:http.html[HTTP] -* link:http4.html[HTTP4] - http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/components/camel-amqp/src/main/docs/readme.adoc ---------------------------------------------------------------------- diff --git a/components/camel-amqp/src/main/docs/readme.adoc b/components/camel-amqp/src/main/docs/readme.adoc deleted file mode 100644 index 5526dce..0000000 --- a/components/camel-amqp/src/main/docs/readme.adoc +++ /dev/null @@ -1,168 +0,0 @@ -[[AMQP-AMQP]] -AMQP -~~~~ - -The *amqp:* component supports the http://www.amqp.org/[AMQP 1.0 -protocol] using the JMS Client API of the http://qpid.apache.org/[Qpid] -project. In case you want to use AMQP 0.9 (in particular RabbitMQ) you -might also be interested in the link:rabbitmq.html[Camel RabbitMQ] -component. Please keep in mind that prior to the Camel 2.17.0 AMQP -component supported AMQP 0.9 and above, however since Camel 2.17.0 it -supports only AMQP 1.0. - -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-amqp</artifactId> - <version>${camel.version}</version> <!-- use the same version as your Camel core version --> -</dependency> ------------------------------------------------------------------------------------------------- - -[[AMQP-URIformat]] -URI format -^^^^^^^^^^ - -[source,java] ---------------------------------------------- -amqp:[queue:|topic:]destinationName[?options] ---------------------------------------------- - -[[AMQP-AMQPOptions]] -AMQP Options -^^^^^^^^^^^^ - -You can specify all of the various configuration options of the -link:../../../../camel-jms/src/main/docs/readme.html[JMS] component after the destination name. - -[[AMQP-Usage]] -Usage -^^^^^ - -As AMQP component is inherited from JMS component, the usage of the -former is almost identical to the latter: - -*Using AMQP component* - -[source,java] ------------------------------------- -// Consuming from AMQP queue -from("amqp:queue:incoming"). - to(...); - -// Sending message to the AMQP topic -from(...). - to("amqp:topic:notify"); ------------------------------------- - -[[AMQP-ConfiguringAMQPcomponent]] -Configuring AMQP component -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Starting from the Camel 2.16.1 you can also use the -`AMQPComponent#amqp10Component(String connectionURI)` factory method to -return the AMQP 1.0 component with the pre-configured topic prefix: - -*Creating AMQP 1.0 component* - -[source,java] ------------------------------------------------------------------------------------------ - AMQPComponent amqp = AMQPComponent.amqp10Component("amqp://guest:guest@localhost:5672"); ------------------------------------------------------------------------------------------ - -Keep in mind that starting from the -Camel 2.17 the `AMQPComponent#amqp10Component(String connectionURI)` factory -method has been deprecated on the behalf of the -`AMQPComponent#amqpComponent(String connectionURI)`: - -*Creating AMQP 1.0 component* - -[source,java] --------------------------------------------------------------------------------------------------------- -AMQPComponent amqp = AMQPComponent.amqpComponent("amqp://localhost:5672"); - -AMQPComponent authorizedAmqp = AMQPComponent.amqpComponent("amqp://localhost:5672", "user", "password"); --------------------------------------------------------------------------------------------------------- - -Starting from Camel 2.17, in order to automatically configure the AMQP -component, you can also add an instance -of `org.apache.camel.component.amqp.AMQPConnectionDetails` to the -registry. For example for Spring Boot you just have to define bean: - -*AMQP connection details auto-configuration* - -[source,java] -------------------------------------------------------------------------------------- -@Bean -AMQPConnectionDetails amqpConnection() { - return new AMQPConnectionDetails("amqp://lcoalhost:5672"); -} - -@Bean -AMQPConnectionDetails securedAmqpConnection() { - return new AMQPConnectionDetails("amqp://lcoalhost:5672", "username", "password"); -} -------------------------------------------------------------------------------------- - - - -You can also rely on the link:properties.html[Camel properties] to read -the AMQP connection details. Factory -method `AMQPConnectionDetails.discoverAMQP()` attempts to read Camel -properties in a Kubernetes-like convention, just as demonstrated on the -snippet below: - - - -*AMQP connection details auto-configuration* - -[source,java] ------------------------------------------------ -export AMQP_SERVICE_HOST = "mybroker.com" -export AMQP_SERVICE_PORT = "6666" -export AMQP_SERVICE_USERNAME = "username" -export AMQP_SERVICE_PASSWORD = "password" - -... - -@Bean -AMQPConnectionDetails amqpConnection() { - return AMQPConnectionDetails.discoverAMQP(); -} ------------------------------------------------ - -[[AMQP-Usingtopics]] -Using topics -^^^^^^^^^^^^ - -To have using topics working with `camel-amqp` you need to configure the -component to use `topic://` as topic prefix, as shown below: - -[source,java] -------------------------------------------------------------------------------------------------------------------------------- - <bean id="amqp" class="org.apache.camel.component.amqp.AmqpComponent"> - <property name="connectionFactory"> - <bean class="org.apache.qpid.amqp_1_0.jms.impl.ConnectionFactoryImpl" factory-method="createFromURL"> - <constructor-arg index="0" type="java.lang.String" value="amqp://localhost:5672" /> - <property name="topicPrefix" value="topic://" /> <!-- only necessary when connecting to ActiveMQ over AMQP 1.0 --> - </bean> - </property> - </bean> -------------------------------------------------------------------------------------------------------------------------------- - -Keep in mind that both  `AMQPComponent#amqpComponent()` methods and -`AMQPConnectionDetails` pre-configure the component with the topic -prefix, so you don't have to configure it explicitly. - -[[AMQP-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/f6fea27a/components/camel-atom/src/main/docs/amqp.adoc ---------------------------------------------------------------------- diff --git a/components/camel-atom/src/main/docs/amqp.adoc b/components/camel-atom/src/main/docs/amqp.adoc new file mode 100644 index 0000000..5526dce --- /dev/null +++ b/components/camel-atom/src/main/docs/amqp.adoc @@ -0,0 +1,168 @@ +[[AMQP-AMQP]] +AMQP +~~~~ + +The *amqp:* component supports the http://www.amqp.org/[AMQP 1.0 +protocol] using the JMS Client API of the http://qpid.apache.org/[Qpid] +project. In case you want to use AMQP 0.9 (in particular RabbitMQ) you +might also be interested in the link:rabbitmq.html[Camel RabbitMQ] +component. Please keep in mind that prior to the Camel 2.17.0 AMQP +component supported AMQP 0.9 and above, however since Camel 2.17.0 it +supports only AMQP 1.0. + +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-amqp</artifactId> + <version>${camel.version}</version> <!-- use the same version as your Camel core version --> +</dependency> +------------------------------------------------------------------------------------------------ + +[[AMQP-URIformat]] +URI format +^^^^^^^^^^ + +[source,java] +--------------------------------------------- +amqp:[queue:|topic:]destinationName[?options] +--------------------------------------------- + +[[AMQP-AMQPOptions]] +AMQP Options +^^^^^^^^^^^^ + +You can specify all of the various configuration options of the +link:../../../../camel-jms/src/main/docs/readme.html[JMS] component after the destination name. + +[[AMQP-Usage]] +Usage +^^^^^ + +As AMQP component is inherited from JMS component, the usage of the +former is almost identical to the latter: + +*Using AMQP component* + +[source,java] +------------------------------------ +// Consuming from AMQP queue +from("amqp:queue:incoming"). + to(...); + +// Sending message to the AMQP topic +from(...). + to("amqp:topic:notify"); +------------------------------------ + +[[AMQP-ConfiguringAMQPcomponent]] +Configuring AMQP component +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Starting from the Camel 2.16.1 you can also use the +`AMQPComponent#amqp10Component(String connectionURI)` factory method to +return the AMQP 1.0 component with the pre-configured topic prefix: + +*Creating AMQP 1.0 component* + +[source,java] +----------------------------------------------------------------------------------------- + AMQPComponent amqp = AMQPComponent.amqp10Component("amqp://guest:guest@localhost:5672"); +----------------------------------------------------------------------------------------- + +Keep in mind that starting from the +Camel 2.17 the `AMQPComponent#amqp10Component(String connectionURI)` factory +method has been deprecated on the behalf of the +`AMQPComponent#amqpComponent(String connectionURI)`: + +*Creating AMQP 1.0 component* + +[source,java] +-------------------------------------------------------------------------------------------------------- +AMQPComponent amqp = AMQPComponent.amqpComponent("amqp://localhost:5672"); + +AMQPComponent authorizedAmqp = AMQPComponent.amqpComponent("amqp://localhost:5672", "user", "password"); +-------------------------------------------------------------------------------------------------------- + +Starting from Camel 2.17, in order to automatically configure the AMQP +component, you can also add an instance +of `org.apache.camel.component.amqp.AMQPConnectionDetails` to the +registry. For example for Spring Boot you just have to define bean: + +*AMQP connection details auto-configuration* + +[source,java] +------------------------------------------------------------------------------------- +@Bean +AMQPConnectionDetails amqpConnection() { + return new AMQPConnectionDetails("amqp://lcoalhost:5672"); +} + +@Bean +AMQPConnectionDetails securedAmqpConnection() { + return new AMQPConnectionDetails("amqp://lcoalhost:5672", "username", "password"); +} +------------------------------------------------------------------------------------- + + + +You can also rely on the link:properties.html[Camel properties] to read +the AMQP connection details. Factory +method `AMQPConnectionDetails.discoverAMQP()` attempts to read Camel +properties in a Kubernetes-like convention, just as demonstrated on the +snippet below: + + + +*AMQP connection details auto-configuration* + +[source,java] +----------------------------------------------- +export AMQP_SERVICE_HOST = "mybroker.com" +export AMQP_SERVICE_PORT = "6666" +export AMQP_SERVICE_USERNAME = "username" +export AMQP_SERVICE_PASSWORD = "password" + +... + +@Bean +AMQPConnectionDetails amqpConnection() { + return AMQPConnectionDetails.discoverAMQP(); +} +----------------------------------------------- + +[[AMQP-Usingtopics]] +Using topics +^^^^^^^^^^^^ + +To have using topics working with `camel-amqp` you need to configure the +component to use `topic://` as topic prefix, as shown below: + +[source,java] +------------------------------------------------------------------------------------------------------------------------------- + <bean id="amqp" class="org.apache.camel.component.amqp.AmqpComponent"> + <property name="connectionFactory"> + <bean class="org.apache.qpid.amqp_1_0.jms.impl.ConnectionFactoryImpl" factory-method="createFromURL"> + <constructor-arg index="0" type="java.lang.String" value="amqp://localhost:5672" /> + <property name="topicPrefix" value="topic://" /> <!-- only necessary when connecting to ActiveMQ over AMQP 1.0 --> + </bean> + </property> + </bean> +------------------------------------------------------------------------------------------------------------------------------- + +Keep in mind that both  `AMQPComponent#amqpComponent()` methods and +`AMQPConnectionDetails` pre-configure the component with the topic +prefix, so you don't have to configure it explicitly. + +[[AMQP-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/f6fea27a/components/camel-atom/src/main/docs/atom.adoc ---------------------------------------------------------------------- diff --git a/components/camel-atom/src/main/docs/atom.adoc b/components/camel-atom/src/main/docs/atom.adoc new file mode 100644 index 0000000..26f7cf7 --- /dev/null +++ b/components/camel-atom/src/main/docs/atom.adoc @@ -0,0 +1,144 @@ +[[Atom-AtomComponent]] +Atom Component +~~~~~~~~~~~~~~ + +The *atom:* component is used for polling Atom feeds. + +Camel will poll the feed every 60 seconds by default. + + *Note:* The component currently only supports polling (consuming) +feeds. + +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-atom</artifactId> + <version>x.x.x</version> + <!-- use the same version as your Camel core version --> +</dependency> +------------------------------------------------------------ + +[[Atom-URIformat]] +URI format +^^^^^^^^^^ + +[source,java] +------------------------ +atom://atomUri[?options] +------------------------ + +Where *atomUri* is the URI to the Atom feed to poll. + +[[Atom-Options]] +Options +^^^^^^^ + +[width="100%",cols="10%,10%,80%",options="header",] +|======================================================================= +|Property |Default |Description +|`splitEntries` |`true` |If `true` Camel will poll the feed and for the subsequent polls return +each entry poll by poll. If the feed contains 7 entries then Camel will +return the first entry on the first poll, the 2nd entry on the next +poll, until no more entries where as Camel will do a new update on the +feed. If `false` then Camel will poll a fresh feed on every invocation. + +|`filter` |`true` |Is only used by the split entries to filter the entries to return. Camel +will default use the `UpdateDateFilter` that only return new entries +from the feed. So the client consuming from the feed never receives the +same entry more than once. The filter will return the entries ordered by +the newest last. + +|`lastUpdate` |`null` |Is only used by the filter, as the starting timestamp for selection +never entries (uses the `entry.updated` timestamp). Syntax format is: +`yyyy-MM-ddTHH:MM:ss`. Example: `2007-12-24T17:45:59`. + +|`throttleEntries` |`true` |*Camel 2.5:* Sets whether all entries identified in a single feed poll +should be delivered immediately. If `true`, only one entry is processed +per `consumer.delay`. Only applicable when `splitEntries` is set to +`true`. + +|`feedHeader` |`true` |Sets whether to add the Abdera Feed object as a header. + +|`sortEntries` |`false` |If `splitEntries` is `true`, this sets whether to sort those entries by +updated date. + +|`consumer.delay` |`500` |Delay in millis between each poll. + +|`consumer.initialDelay` |`1000` |Millis before polling starts. + +|`consumer.userFixedDelay` |`false` |If `true`, use fixed delay between pools, otherwise fixed rate is used. +See +http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html[ScheduledExecutorService] +in JDK for details. + +|`username` | | *Camel 2.16:* For basic authentication when polling from a HTTP feed + +|`password` | | *Camel 2.16:* For basic authentication when polling from a HTTP feed +|======================================================================= + +You can append query options to the URI in the following format, +`?option=value&option=value&...` + +[[Atom-Exchangedataformat]] +Exchange data format +^^^^^^^^^^^^^^^^^^^^ + +Camel will set the In body on the returned `Exchange` with the entries. +Depending on the `splitEntries` flag Camel will either return one +`Entry` or a `List<Entry>`. + +[width="100%",cols="10%,10%,80%",options="header",] +|======================================================================= +|Option |Value |Behavior +|`splitEntries` |`true` |Only a single entry from the currently being processed feed is set: +`exchange.in.body(Entry)` + +|`splitEntries` |`false` |The entire list of entries from the feed is set: +`exchange.in.body(List<Entry>)` +|======================================================================= + +Camel can set the `Feed` object on the In header (see `feedHeader` +option to disable this): + +[[Atom-MessageHeaders]] +Message Headers +^^^^^^^^^^^^^^^ + +Camel atom uses these headers. + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Header |Description +|`CamelAtomFeed` |When consuming the `org.apache.abdera.model.Feed` object is set to this +header. +|======================================================================= + +[[Atom-Samples]] +Samples +^^^^^^^ + +In this sample we poll James Strachan's blog. + +[source,java] +--------------------------------------------------------------------------------- +from("atom://http://macstrac.blogspot.com/feeds/posts/default").to("seda:feeds"); +--------------------------------------------------------------------------------- + +In this sample we want to filter only good blogs we like to a SEDA +queue. The sample also shows how to setup Camel standalone, not running +in any Container or using Spring. + +[[Atom-SeeAlso]] +See Also +^^^^^^^^ + +* link:configuring-camel.html[Configuring Camel] +* link:component.html[Component] +* link:endpoint.html[Endpoint] +* link:getting-started.html[Getting Started] + +* link:rss.html[RSS] + http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/components/camel-atom/src/main/docs/readme.adoc ---------------------------------------------------------------------- diff --git a/components/camel-atom/src/main/docs/readme.adoc b/components/camel-atom/src/main/docs/readme.adoc deleted file mode 100644 index 26f7cf7..0000000 --- a/components/camel-atom/src/main/docs/readme.adoc +++ /dev/null @@ -1,144 +0,0 @@ -[[Atom-AtomComponent]] -Atom Component -~~~~~~~~~~~~~~ - -The *atom:* component is used for polling Atom feeds. - -Camel will poll the feed every 60 seconds by default. + - *Note:* The component currently only supports polling (consuming) -feeds. - -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-atom</artifactId> - <version>x.x.x</version> - <!-- use the same version as your Camel core version --> -</dependency> ------------------------------------------------------------- - -[[Atom-URIformat]] -URI format -^^^^^^^^^^ - -[source,java] ------------------------- -atom://atomUri[?options] ------------------------- - -Where *atomUri* is the URI to the Atom feed to poll. - -[[Atom-Options]] -Options -^^^^^^^ - -[width="100%",cols="10%,10%,80%",options="header",] -|======================================================================= -|Property |Default |Description -|`splitEntries` |`true` |If `true` Camel will poll the feed and for the subsequent polls return -each entry poll by poll. If the feed contains 7 entries then Camel will -return the first entry on the first poll, the 2nd entry on the next -poll, until no more entries where as Camel will do a new update on the -feed. If `false` then Camel will poll a fresh feed on every invocation. - -|`filter` |`true` |Is only used by the split entries to filter the entries to return. Camel -will default use the `UpdateDateFilter` that only return new entries -from the feed. So the client consuming from the feed never receives the -same entry more than once. The filter will return the entries ordered by -the newest last. - -|`lastUpdate` |`null` |Is only used by the filter, as the starting timestamp for selection -never entries (uses the `entry.updated` timestamp). Syntax format is: -`yyyy-MM-ddTHH:MM:ss`. Example: `2007-12-24T17:45:59`. - -|`throttleEntries` |`true` |*Camel 2.5:* Sets whether all entries identified in a single feed poll -should be delivered immediately. If `true`, only one entry is processed -per `consumer.delay`. Only applicable when `splitEntries` is set to -`true`. - -|`feedHeader` |`true` |Sets whether to add the Abdera Feed object as a header. - -|`sortEntries` |`false` |If `splitEntries` is `true`, this sets whether to sort those entries by -updated date. - -|`consumer.delay` |`500` |Delay in millis between each poll. - -|`consumer.initialDelay` |`1000` |Millis before polling starts. - -|`consumer.userFixedDelay` |`false` |If `true`, use fixed delay between pools, otherwise fixed rate is used. -See -http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html[ScheduledExecutorService] -in JDK for details. - -|`username` | | *Camel 2.16:* For basic authentication when polling from a HTTP feed - -|`password` | | *Camel 2.16:* For basic authentication when polling from a HTTP feed -|======================================================================= - -You can append query options to the URI in the following format, -`?option=value&option=value&...` - -[[Atom-Exchangedataformat]] -Exchange data format -^^^^^^^^^^^^^^^^^^^^ - -Camel will set the In body on the returned `Exchange` with the entries. -Depending on the `splitEntries` flag Camel will either return one -`Entry` or a `List<Entry>`. - -[width="100%",cols="10%,10%,80%",options="header",] -|======================================================================= -|Option |Value |Behavior -|`splitEntries` |`true` |Only a single entry from the currently being processed feed is set: -`exchange.in.body(Entry)` - -|`splitEntries` |`false` |The entire list of entries from the feed is set: -`exchange.in.body(List<Entry>)` -|======================================================================= - -Camel can set the `Feed` object on the In header (see `feedHeader` -option to disable this): - -[[Atom-MessageHeaders]] -Message Headers -^^^^^^^^^^^^^^^ - -Camel atom uses these headers. - -[width="100%",cols="10%,90%",options="header",] -|======================================================================= -|Header |Description -|`CamelAtomFeed` |When consuming the `org.apache.abdera.model.Feed` object is set to this -header. -|======================================================================= - -[[Atom-Samples]] -Samples -^^^^^^^ - -In this sample we poll James Strachan's blog. - -[source,java] ---------------------------------------------------------------------------------- -from("atom://http://macstrac.blogspot.com/feeds/posts/default").to("seda:feeds"); ---------------------------------------------------------------------------------- - -In this sample we want to filter only good blogs we like to a SEDA -queue. The sample also shows how to setup Camel standalone, not running -in any Container or using Spring. - -[[Atom-SeeAlso]] -See Also -^^^^^^^^ - -* link:configuring-camel.html[Configuring Camel] -* link:component.html[Component] -* link:endpoint.html[Endpoint] -* link:getting-started.html[Getting Started] - -* link:rss.html[RSS] - http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/components/camel-cdi/src/main/docs/cdi.adoc ---------------------------------------------------------------------- diff --git a/components/camel-cdi/src/main/docs/cdi.adoc b/components/camel-cdi/src/main/docs/cdi.adoc new file mode 100644 index 0000000..6a2aece --- /dev/null +++ b/components/camel-cdi/src/main/docs/cdi.adoc @@ -0,0 +1,141 @@ +[[CDI-CamelCDI]] +Camel CDI +~~~~~~~~~ + +As of 2.10 we now have support +http://jcp.org/en/jsr/detail?id=299[Contexts and Dependency Injection - +JSR299] and http://jcp.org/en/jsr/detail?id=330[Dependency Injection for +Java - JSR330] as a dependency injection framework. This offers new +opportunities to develop and deploy Apache Camel projects in +http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition[Java EE 6 +containers] but also in standalone Java SE or +http://openwebbeans.apache.org[CDI container] + +The current project is under active development and does not provide all +the features that we have with injection frameworks like Spring or +Blueprint + +[[CDI-DependencyInjectingCamelwithCDI]] +Dependency Injecting Camel with CDI +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Basically, two things should be done to use Apache Camel in a CDI +environment. First, we just need to create a +https://github.com/cmoulliard/cdi-camel/blob/master/src/main/java/com/fusesource/cdi/camel/simple/BootStrap.java[BootStrap] +class which will be use by the Java EE 6 container or Java SE to start +the Camel Context. The +https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java;h=0d863bc8f5aa521b15955c26a512cdec09e366e9;hb=HEAD[CdiCamelContext] +when instantiated will add a CDI +http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html[Bean +Registry]. That will allow Camel to perform lookup of beans injected and +registered in CDI container. Next, we must add CDI annotated beans +(@inject, @named, ...) to use them from the Apache Camel routes. + +[[CDI-BootstrappingCamelwithCDIcontainer]] +Bootstrapping Camel with CDI container +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The following example shows how we can bootstrap an Apache Camel Context +in a Boot Strap class. This class contains important annotations like +the +http://docs.oracle.com/javaee/6/api/javax/ejb/Singleton.html[javax.ejb.Singleton]. +This annotation will tell the container to create a Singleton instance +of the BootStrapClass class. This mechanism is similar to Bean instance +creation that we have with Spring framework. By combining this +annotation with +http://docs.oracle.com/javaee/6/api/javax/ejb/Startup.html[javax.ejb.Startup], +the container will start the camel context at the startup of the CDI +container. + +[source,java] +---- + @Singleton + @Startup + public class BootStrap { + ... +---- + +When the @PreConstruct annotation is called, then we inject a +CdiCamelContext objet, register a SimpleCamelRoute using @Inject +annotation and starts the Camel Route. + +[source,java] +---- + @PostConstruct + public void init() throws Exception { + logger.info(">> Create CamelContext and register Camel Route."); + + // Define Timer URI + simpleRoute.setTimerUri("timer://simple?fixedRate=true&period=10s"); + + // Add Camel Route + camelCtx.addRoutes(simpleRoute); + + // Start Camel Context + camelCtx.start(); +---- + +When you look to the following Camel Route code, you can see that we do +a lookup to find a bean "helloWorld" which has been injected. This is +possible because the CdiCamelContext registers a Camel Registry +containing a reference to a CDI BeanManager. + +[source,java] +---- + @Override + public void configure() throws Exception { + + from(timerUri) + .setBody() + .simple("Bean Injected") + + // Lookup for bean injected by CDI container + // The HellowWorld class is annotated using @Named + .beanRef("helloWorld", "sayHello") + + .log(">> Response : ${body}"); + + } +---- + +Here is the code of the HelloWorld Bean + +[source,java] +---- +@Named +public class HelloWorld { + + public String sayHello(@Body String message) { + return ">> Hello " + message + " user."; + } +} +---- + +This project is started using the +http://embedded-glassfish.java.net/nonav/plugindocs/3.1/plugin-info.html[GlassFish +maven plugin] but alternatively, you can deploy the war file produced in +any Java EE 6 servers : Glassfish, JBoss AS 7, OpenEJB, Apache TomEE or +Apache KarafEE or using a +http://agoncal.wordpress.com/2011/01/12/bootstrapping-cdi-in-several-environments/[Java +SE]. + +[[CDI-SeeAlso]] +See Also +^^^^^^^^ + +* Simple https://github.com/cmoulliard/cdi-camel-example/[Camel CDI BootStrap project] +* http://docs.jboss.org/weld/reference/1.1.5.Final/en-US/html_single/[JSR299] + and http://openwebbeans.apache.org/owb/jsr330.html[JSR330] reference documentations +* http://deltaspike.apache.org[Apache DeltaSpike project] - CDI + extensions and JavaSE BootStrap +* CDI revealed by Antonio Goncalves - + https://agoncal.wordpress.com/2011/04/07/injection-with-cdi-part-i/[part 1], + https://agoncal.wordpress.com/2011/05/03/injection-with-cdi-part-ii/[part 2], + https://agoncal.wordpress.com/2011/09/25/injection-with-cdi-part-iii/[part 3] + and OpenEJB team - see http://openejb.apache.org/examples-trunk/index.html[examples] +* Apache implementation of the specs JSR299, 330 - + http://openwebbeans.apache.org[OpenWebbeans] and Apache + http://openejb.apache.org/[OpenEJB] which provide the container to + deploy CDI projects +* Apache Karaf featured with OpenEJB and CDI - + https://svn.apache.org/repos/asf/openejb/trunk/openejb/osgi/[Apache KarafEE] http://git-wip-us.apache.org/repos/asf/camel/blob/f6fea27a/components/camel-cdi/src/main/docs/readme.adoc ---------------------------------------------------------------------- diff --git a/components/camel-cdi/src/main/docs/readme.adoc b/components/camel-cdi/src/main/docs/readme.adoc deleted file mode 100644 index 6a2aece..0000000 --- a/components/camel-cdi/src/main/docs/readme.adoc +++ /dev/null @@ -1,141 +0,0 @@ -[[CDI-CamelCDI]] -Camel CDI -~~~~~~~~~ - -As of 2.10 we now have support -http://jcp.org/en/jsr/detail?id=299[Contexts and Dependency Injection - -JSR299] and http://jcp.org/en/jsr/detail?id=330[Dependency Injection for -Java - JSR330] as a dependency injection framework. This offers new -opportunities to develop and deploy Apache Camel projects in -http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition[Java EE 6 -containers] but also in standalone Java SE or -http://openwebbeans.apache.org[CDI container] - -The current project is under active development and does not provide all -the features that we have with injection frameworks like Spring or -Blueprint - -[[CDI-DependencyInjectingCamelwithCDI]] -Dependency Injecting Camel with CDI -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Basically, two things should be done to use Apache Camel in a CDI -environment. First, we just need to create a -https://github.com/cmoulliard/cdi-camel/blob/master/src/main/java/com/fusesource/cdi/camel/simple/BootStrap.java[BootStrap] -class which will be use by the Java EE 6 container or Java SE to start -the Camel Context. The -https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java;h=0d863bc8f5aa521b15955c26a512cdec09e366e9;hb=HEAD[CdiCamelContext] -when instantiated will add a CDI -http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html[Bean -Registry]. That will allow Camel to perform lookup of beans injected and -registered in CDI container. Next, we must add CDI annotated beans -(@inject, @named, ...) to use them from the Apache Camel routes. - -[[CDI-BootstrappingCamelwithCDIcontainer]] -Bootstrapping Camel with CDI container -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The following example shows how we can bootstrap an Apache Camel Context -in a Boot Strap class. This class contains important annotations like -the -http://docs.oracle.com/javaee/6/api/javax/ejb/Singleton.html[javax.ejb.Singleton]. -This annotation will tell the container to create a Singleton instance -of the BootStrapClass class. This mechanism is similar to Bean instance -creation that we have with Spring framework. By combining this -annotation with -http://docs.oracle.com/javaee/6/api/javax/ejb/Startup.html[javax.ejb.Startup], -the container will start the camel context at the startup of the CDI -container. - -[source,java] ----- - @Singleton - @Startup - public class BootStrap { - ... ----- - -When the @PreConstruct annotation is called, then we inject a -CdiCamelContext objet, register a SimpleCamelRoute using @Inject -annotation and starts the Camel Route. - -[source,java] ----- - @PostConstruct - public void init() throws Exception { - logger.info(">> Create CamelContext and register Camel Route."); - - // Define Timer URI - simpleRoute.setTimerUri("timer://simple?fixedRate=true&period=10s"); - - // Add Camel Route - camelCtx.addRoutes(simpleRoute); - - // Start Camel Context - camelCtx.start(); ----- - -When you look to the following Camel Route code, you can see that we do -a lookup to find a bean "helloWorld" which has been injected. This is -possible because the CdiCamelContext registers a Camel Registry -containing a reference to a CDI BeanManager. - -[source,java] ----- - @Override - public void configure() throws Exception { - - from(timerUri) - .setBody() - .simple("Bean Injected") - - // Lookup for bean injected by CDI container - // The HellowWorld class is annotated using @Named - .beanRef("helloWorld", "sayHello") - - .log(">> Response : ${body}"); - - } ----- - -Here is the code of the HelloWorld Bean - -[source,java] ----- -@Named -public class HelloWorld { - - public String sayHello(@Body String message) { - return ">> Hello " + message + " user."; - } -} ----- - -This project is started using the -http://embedded-glassfish.java.net/nonav/plugindocs/3.1/plugin-info.html[GlassFish -maven plugin] but alternatively, you can deploy the war file produced in -any Java EE 6 servers : Glassfish, JBoss AS 7, OpenEJB, Apache TomEE or -Apache KarafEE or using a -http://agoncal.wordpress.com/2011/01/12/bootstrapping-cdi-in-several-environments/[Java -SE]. - -[[CDI-SeeAlso]] -See Also -^^^^^^^^ - -* Simple https://github.com/cmoulliard/cdi-camel-example/[Camel CDI BootStrap project] -* http://docs.jboss.org/weld/reference/1.1.5.Final/en-US/html_single/[JSR299] - and http://openwebbeans.apache.org/owb/jsr330.html[JSR330] reference documentations -* http://deltaspike.apache.org[Apache DeltaSpike project] - CDI - extensions and JavaSE BootStrap -* CDI revealed by Antonio Goncalves - - https://agoncal.wordpress.com/2011/04/07/injection-with-cdi-part-i/[part 1], - https://agoncal.wordpress.com/2011/05/03/injection-with-cdi-part-ii/[part 2], - https://agoncal.wordpress.com/2011/09/25/injection-with-cdi-part-iii/[part 3] - and OpenEJB team - see http://openejb.apache.org/examples-trunk/index.html[examples] -* Apache implementation of the specs JSR299, 330 - - http://openwebbeans.apache.org[OpenWebbeans] and Apache - http://openejb.apache.org/[OpenEJB] which provide the container to - deploy CDI projects -* Apache Karaf featured with OpenEJB and CDI - - https://svn.apache.org/repos/asf/openejb/trunk/openejb/osgi/[Apache KarafEE]