Camel Components

JCR

Since Camel 1.3

Both producer and consumer are supported

The JCR component allows you to add/read nodes to/from a JCR compliant content repository, for example, Apache Jackrabbit, with its producer, or register an EventListener with the consumer.

You can use consumer as an EventListener in JCR or a producer to read a node by identifier.

Maven users will 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

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

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The JCR component supports the following options which are listed below.

Name Description Default Type

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

Endpoint Options

The JCR endpoint is configured using URI syntax:

jcr:host/base

With the following path and query parameters:

Path Parameters

Name Description Default Type

host (common)

Required The name of the javax.jcr.Repository to look up in the Camel registry.

String

base (common)

The path of the base node, relative to the root node of the workspace. The insert operation of the producer stores the nodes below it, and creates the nodes of this path that do not exist. The consumer listens for the events at this path. When not set, the root node is used.

String

Query Parameters

Name Description Default Type

deep (common)

Whether the consumer also receives the events of the whole subgraph below the base path. When false, it only receives the events whose associated parent node is the base node: the parent of an added, removed or moved node, or the node of a changed property.

false

boolean

eventTypes (common)

The types of the observation events the consumer receives, as a bit mask: the sum of the javax.jcr.observation.Event constants NODE_ADDED (1), NODE_REMOVED (2), PROPERTY_ADDED (4), PROPERTY_REMOVED (8), PROPERTY_CHANGED (16), NODE_MOVED (32) and PERSIST (64). For example 3 receives the added and removed nodes. The default 0 matches no event type, so the consumer receives no events until this is set.

int

nodeTypeNames (common)

A comma separated list of node type names, such as nt:folder. When set, the consumer only receives the events whose associated parent node has one of these node types, or a subtype of one. The entries are not trimmed, so do not put spaces around the commas.

String

noLocal (common)

Whether to ignore the events of the changes made through the session that the consumer registered its event listener with. The consumer makes no changes through that session, and the producer logs in with a new session for each message, so this does not filter out the changes of the producer or of other sessions.

false

boolean

sessionLiveCheckInterval (common)

The delay between the session checks of the consumer. When a check finds that the session is no longer live, the consumer logs in again and registers a new event listener. In milliseconds, or a duration such as 1m; must be positive.

60000

long

sessionLiveCheckIntervalOnStart (common)

The delay after the consumer starts before its first session check, which logs in and registers the event listener. The consumer receives no events before this check. In milliseconds, or a duration such as 3s; must be positive.

3000

long

username (common)

The user name of the javax.jcr.SimpleCredentials to log in with. The credentials are only used when a password is also set; otherwise the producer and the consumer log in with no credentials, and the repository authenticates by its own means.

String

uuids (common)

A comma separated list of node identifiers (UUIDs). When set, the consumer only receives the events whose associated parent node has one of these identifiers. The entries are not trimmed, so do not put spaces around the commas.

String

workspaceName (common)

The name of the workspace that the producer and the consumer log in to. When not set, the repository chooses the default workspace.

String

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

headerFilterStrategy (filter)

To use a custom HeaderFilterStrategy to choose which headers the insert operation stores as node properties, and which node properties the getById operation sets as headers. The default skips the names that start with Camel or camel.

HeaderFilterStrategy

password (security)

The password of the javax.jcr.SimpleCredentials to log in with, together with the username.

String

Message Headers

The JCR component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelJcrNodeName (producer)

Constant: JCR_NODE_NAME

The name of the node that the insert operation creates or updates below the base node. It can be a relative path such as a/b/node: the nodes of the path that do not exist are created. Characters that are not allowed in a JCR name are escaped.

The exchange id

String

CamelJcrOperation (producer)

Constant: JCR_OPERATION

The operation to perform: CamelJcrInsert stores the message headers as the properties of a node below the base node, adds the mix:referenceable mixin to it, and sets its identifier as the message body; CamelJcrGetById reads the node whose identifier is the message body, and sets its properties as message headers. Numbers are not converted: a header with a number value is not stored, and a LONG or DOUBLE property is set as a null header.

CamelJcrInsert

String

CamelJcrNodeType (producer)

Constant: JCR_NODE_TYPE

The primary node type, such as nt:folder, of the nodes that the insert operation creates for the node name, including the missing nodes of its path. An existing node keeps its type. When not set, the repository chooses the type from the definition of the parent node.

String

Message Body

The message body at each side of the JCR component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

list (java.util.List)

The JCR events received in one callback: a List of javax.jcr.observation.Event.

Producer input

any

Insert (the default) ignores the body and stores the headers as node properties; getById (CamelJcrOperation header) reads the node identifier from the body as a String.

Producer output

text or unchanged

Insert sets the identifier of the node, a String; getById leaves the body and sets the node properties as headers.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Example

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

  • Java

  • XML

  • YAML

from("direct:a").setHeader("CamelJcrNodeName", constant("node"))
    .setHeader("my.contents.property", body())
    .to("jcr://user:pass@repository/home/test");
<route>
    <from uri="direct:a"/>
    <setHeader name="CamelJcrNodeName">
        <constant>node</constant>
    </setHeader>
    <setHeader name="my.contents.property">
        <simple>${body}</simple>
    </setHeader>
    <to uri="jcr://user:pass@repository/home/test"/>
</route>
- route:
    from:
      uri: direct:a
      steps:
        - setHeader:
            name: CamelJcrNodeName
            expression:
              constant:
                expression: node
        - setHeader:
            name: my.contents.property
            expression:
              simple:
                expression: "${body}"
        - to:
            uri: jcr://user:pass@repository/home/test

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.

  • Java

  • XML

  • YAML

from("jcr://user:pass@repository/import-application/inbox?eventTypes=3&deep=true")
    .to("direct:execute-import-application");
<route>
    <from uri="jcr://user:pass@repository/import-application/inbox?eventTypes=3&amp;deep=true"/>
    <to uri="direct:execute-import-application"/>
</route>
- route:
    from:
      uri: jcr://user:pass@repository/import-application/inbox
      parameters:
        eventTypes: 3
        deep: true
      steps:
        - to:
            uri: direct:execute-import-application