Versions Compared

Key

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

...

The jcr component allows you to add nodes to a JCR compliant content repository (for example, Apache Jackrabbit).

Maven users will need to add the following dependency to their pom.xml for this component:

Code Block


The *{{jcr}}* component allows you to add/read nodes to/from a JCR compliant content repository (for example, [Apache Jackrabbit|http://jackrabbit.apache.org/]) using a producer, or listen for changes with a consumer.

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

URI format

Code Block

{code}

h3. URI format

{code}
jcr://user:password@repository/path/to/node
{code}

{tip:title=Consumer added}
From *Camel 2.10* onwards you can use consumer as an EventListener in JCR or a producer to read a node

Usage

The repository element of the URI is used to look up the JCR Repository object in the Camel context registry.

If a message is sent to a JCR producer endpoint:

  • A new node is created in the content repository,
  • All the message properties of the IN message are transformed to JCR Value instances and added to the new node,
  • The node's UUID is returned in the OUT message.

Message properties

All message properties are converted to node properties, except for the CamelJcrNodeName property (you can refer to JcrConstants.NODE_NAME in your code), which is used to determine the node name.

Example

The snippet below creates a node named node under the /home/test node in the content repository. One additional attribute is added to the node as well: my.contents.property which will contain the body of the message being sent.

Wiki Markup
 by identifier.
{tip}

h3. Usage
The {{repository}} element of the URI is used to look up the JCR {{Repository}} object in the Camel context registry.

h4. Producer

{div:class=confluenceTableSmall}
|| Name || Default Value || Description ||
| {{CamelJcrOperation}} | {{CamelJcrInsert}} | CamelJcrInsert or CamelJcrGetById operation to use |
| {{CamelJcrNodeName}} | {{null}} | Used to determine the node name to use. |
{div}

When a message is sent to a JCR producer endpoint:
*If the operation is CamelJcrInsert: A new node is created in the content repository, all the message properties of the IN message are transformed to JCR {{Value}} instances and added to the new node and the node's UUID is returned in the OUT message.
*If the operation is CamelJcrGetById: A new node is retrieved from the repository using the message body as node identifier.

h4. Consumer
{div:class=confluenceTableSmall}
|| Name || Default Value || Description ||
| {{eventTypes}} | {{0}} | A combination of one or more event types encoded as a bit mask value such as javax.jcr.observation.Event.NODE_ADDED, javax.jcr.observation.Event.NODE_REMOVED, etc. |
| {{deep}} | {{false}} | When it is true, events whose associated parent node is at current path or within its subgraph are received. |
| {{uuids}} | {{null}} | Only events whose associated parent node has one of the identifiers in the comma separated uuid list will be received.|
| {{nodeTypeNames}} | {{null}} | Only events whose associated parent node has one of the node types (or a subtype of one of the node types) in this list will be received. |
| {{noLocal}} | {{false}} | If {{noLocal}} is {{true}}, then events generated by the session through which the listener was registered are ignored. Otherwise, they are not ignored| 
{div}

h3. Example
The snippet below creates a node named {{node}} under the {{/home/test}} node in the content repository. One additional attribute is added to the node as well: {{my.contents.property}} which will contain the body of the message being sent.
{snippet:id=jcr|lang=java|url=camel/trunk/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrRouteTest.java}

...

JcrProducerTest.java}

The following code will register an EventListener under the path import-application/inbox for Event.NODE_ADDED and Event.NODE_REMOVED events (event types 1 and 2, both masked as 3) and listening deep for all the children.
{code:xml}
<route>
    <from uri="jcr://user:pass@repository/import-application/inbox?eventTypes=3&deep=true" />
    <to uri="direct:execute-import-application" />
</route>
{code}

{include:Endpoint See Also}