Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
h2. Cometd Component

The *cometd:* component is a transport for working with the [jetty|http://www.mortbay.org/jetty] implementation of the [cometd/bayeux protocol|http://docs.codehaus.org/display/JETTY/Cometd+%28aka+Bayeux%29].
Using this component in combination with the dojo toolkit library it's possible to push Camel messages directly into the browser using an AJAX based mechanism.

Maven users will need to add the following dependency to their {{pom.xml}} for this component:
{code:xml}
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cometd</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
{code}

h3. URI format

{code}
cometd://host:port/channelName[?options]
{code}

The *channelName* represents a topic that can be subscribed to by the Camel endpoints.

h3. Examples
{noformat}
cometd://localhost:8080/service/mychannel
cometds://localhost:8443/service/mychannel
{noformat}
where {{cometds:}} represents an SSL configured endpoint.

See this [blog entry|http://www.davidgreco.it/MySite/Blog/Entries/2008/12/4_Camel,_Cometd_and_Bayeux_what_a_nice_combination.html] by David Greco who contributed this component to Apache Camel, for a full sample. 

h3. Options
{div:class=confluenceTableSmall}
|| Name         || Default Value || Description ||
| {{resourceBase}}  |                 | The root directory for the web resources or classpath. Use the protocol file: or classpath: depending if you want that the component loads the resource from file system or classpath. Classpath is required for OSGI deployment where the resources are packaged in the jar. Notice this option has been renamed to {{baseResource}} from *Camel 2.8* onwards. |
| {{baseResource}} | | *Camel 2.8:* The root directory for the web resources or classpath. Use the protocol file: or classpath: depending if you want that the component loads the resource from file system or classpath. Classpath is required for OSGI deployment where the resources are packaged in the jar |
| {{timeout}} | {{240000}} | The server side poll timeout in milliseconds. This is how long the server will hold a reconnect request before responding. |
| {{interval}} |      {{0}}          | The client side poll timeout in milliseconds. How long a client will wait between reconnects|
| {{maxInterval}} | {{30000}} | The max client side poll timeout in milliseconds. A client will be removed if a connection is not received in this time. |
| {{multiFrameInterval}}   | {{1500}} | The client side poll timeout, if multiple connections are detected from the same browser. |
| {{jsonCommented}} | {{true}} |  If {{true}}, the server will accept JSON wrapped in a comment and will generate JSON wrapped in a comment. This is a defence against Ajax Hijacking. |
| {{logLevel}} | {{1}} | {{0}}=none, {{1}}=info, {{2}}=debug. |
{div}

You can append query options to the URI in the following format, {{?option=value&option=value&...}}

Here is some examples on How to pass the parameters

For file (for webapp resources located in the Web Application directory --> cometd://localhost:8080?resourceBase=file./webapp
For classpath (when by example the web resources are packaged inside the webapp folder --> cometd://localhost:8080?resourceBase=classpath:webapp

h3. Authentication
*Available as of Camel 2.8*

You can configure custom {{SecurityPolicy}} and {{Extension}}'s to the {{CometdComponent}} which allows you to use authentication as [documented here|http://cometd.org/documentation/howtos/authentication]

{include:Endpoint See Also}