[[jxpath-language]]
= JXPath Language (deprecated)
:page-source: components/camel-jxpath/src/main/docs/jxpath-language.adoc

*Available as of Camel version 1.3*


Camel supports http://commons.apache.org/jxpath/[JXPath] to allow
XPath expressions to be used on beans in an
Expression or Predicate to be
used in the DSL or xref:latest@manual::xml-configuration.adoc[Xml
Configuration]. For example you could use JXPath to create an
Predicate in a xref:latest@manual::filter-eip.adoc[Message
Filter] or as an Expression for a
Recipient List.

You can use XPath expressions directly using smart completion in your
IDE as follows

[source,java]
---------------------------
from("queue:foo").filter().
  jxpath("/in/body/foo").
  to("queue:bar")
---------------------------

== JXPath Options


// language options: START
The JXPath language supports 2 options, which are listed below.



[width="100%",cols="2,1m,1m,6",options="header"]
|===
| Name | Default | Java Type | Description
| lenient | false | Boolean | Allows to turn lenient on the JXPathContext. When turned on this allows the JXPath expression to evaluate against expressions and message bodies which may be invalid / missing data. This option is by default false
| trim | true | Boolean | Whether to trim the value to remove leading and trailing whitespaces and line breaks
|===
// language options: END
// spring-boot-auto-configure options: START
== Spring Boot Auto-Configuration

When using Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

[source,xml]
----
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-jxpath-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>
----


The component supports 3 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *camel.language.jxpath.enabled* | Enable jxpath language | true | Boolean
| *camel.language.jxpath.lenient* | Allows to turn lenient on the JXPathContext. When turned on this allows the JXPath expression to evaluate against expressions and message bodies which may be invalid / missing data. This option is by default false | false | Boolean
| *camel.language.jxpath.trim* | Whether to trim the value to remove leading and trailing whitespaces and line breaks | true | Boolean
|===
// spring-boot-auto-configure options: END




== Variables

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Variable |Type |Description

|*this* |Exchange |the Exchange object

|in |Message |the exchange.in message

|out |Message |the exchange.out message
|=======================================================================

== Options

[width="100%",cols="10%,10%,80%",options="header",]
|=======================================================================
|Option |Type |Description

|lenient |boolean |*Camel 2.11/2.10.5:* Allows to turn lenient on the JXPathContext. When
turned on this allows the JXPath expression to evaluate against
expressions and message bodies which may be invalid / missing data. See
more details at the
http://commons.apache.org/proper/commons-jxpath//users-guide.html#Lenient_Mode[JXPath
Documentation] This option is by default false.
|=======================================================================

== Using XML configuration

If you prefer to configure your routes in your Spring
XML file then you can use JXPath expressions as follows

[source,xml]
---------------------------------------------------------------------------------------------------------------
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
    <route>
      <from uri="activemq:MyQueue"/>
      <filter>
        <jxpath>in/body/name = 'James'</xpath>
        <to uri="mqseries:SomeOtherQueue"/>
      </filter>
    </route>
  </camelContext>
</beans>
---------------------------------------------------------------------------------------------------------------

== Examples

Here is a simple
http://svn.apache.org/repos/asf/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java[example]
using a JXPath expression as a predicate in a
Message Filter

== JXPath injection

You can use Bean Integration to invoke a
method on a bean and use various languages such as JXPath to extract a
value from the message and bind it to a method parameter.

For example

[source,java]
---------------------------------------------------------------------------------------------
public class Foo {
    
    @MessageDriven(uri = "activemq:my.queue")
    public void doSomething(@JXPath("in/body/foo") String correlationID, @Body String body) {
        // process the inbound message here
    }
}
---------------------------------------------------------------------------------------------

== Loading script from external resource

*Available as of Camel 2.11*

You can externalize the script and have Camel load it from a resource
such as `"classpath:"`, `"file:"`, or `"http:"`.

 This is done using the following syntax: `"resource:scheme:location"`,
eg to refer to a file on the classpath you can do:

[source,java]
----------------------------------------------------------------
.setHeader("myHeader").jxpath("resource:classpath:myjxpath.txt")
----------------------------------------------------------------

== Dependencies

To use JXpath in your camel routes you need to add the a dependency on
*camel-jxpath* which implements the JXpath language.

If you use maven you could just add the following to your pom.xml,
substituting the version number for the latest & greatest release (see
the download page for the latest versions).

[source,java]
---------------------------------------
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-jxpath</artifactId>
  <version>x.x.x</version>
</dependency>
---------------------------------------

Otherwise, you'll also need
http://repo2.maven.org/maven2/commons-jxpath/commons-jxpath/1.3/commons-jxpath-1.3.jar[Commons
JXPath].
