# JCR

## JCR Component

The `jcr` component allows you to add/read nodes to/from a JCR (JSR-170) compliant content repository (for example, Apache Jackrabbit) with the producer, or register an EventListener with the consumer.

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

    <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

    jcr://user:password@repository/path/to/node

| Note
As of Apache Camel 2.10, you can use a consumer as an EventListener in JCR, or a producer to read a node by identifier.

## Usage

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

## Producer

Name | Default | Description
--- | --- | ---
`CamelJcrOperation` | `CamelJcrInsert` | The operation—`CamelJcrInsert` or `CamelJcrGetById`—to use.
`CamelJcrNodeName` | `null` | Determines the node name to use.

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 in the IN message are transformed into `JCR value` instances and added to the new node, and the new 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 the node identifier.

## Consumer

The consumer will connect to JCR periodically and return a `List<jvax.jcr.observation.Event>` in the message body.

Name | Default | 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`, and so on.
`deep` | `false` | When `true`, events whose parent node is at the 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 subtype of one of the node types) in this list will be received.
`noLocal` | `false` | When `true`, events generated by the session through which the listener was registered are ignored. Otherwise, they are not ignored.
`sessionLiveCheckInterval` | `60000` | The interval, in milliseconds, to wait before performing a live check of each session.
`sessionLiveCheckIntervalOnStart` | `3000` | The interval, in milliseconds, to wait before performing a live check on the first session.

## Examples

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: `my.contents.property`, which will contain the body of the message being sent.

    from("direct:a").setProperty(JcrConstants.JCR_NODE_NAME, constant("node"))
        .setProperty("my.contents.property", body()).to("jcr://user:pass@repository/home/test");

The snippet below registers 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 children.

    <route>
       <from uri="jcr://user:pass@repository/import-application/inbox?eventTypes=3&deep=true" />
       <to uri="direct:execute-import-application" />
    </route>