## BeanShell

## Overview

BeanShell is a Java-based scripting language that allows quick parsing of object. The BeanShell support is part of the `camel-script` module.

| Important
You must use BeanShell 2.0b5 or greater.

## Adding the script module

To use BeanShell in your routes you need to add a dependency on `camel-script` to your project as shown in Example 1, “Adding the camel-script dependency”.

Example 1. Adding the camel-script dependency

    <!-- Maven POM File -->
    <properties>
      <camel-version>2.8.0-fuse-00-05</camel-version>
      ...
    </properties>

    <dependencies>
      ...
      <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-script</artifactId>
        <version>${camel-version}</version>
      </dependency>
      ...
    </dependencies>

## Built-in attributes

Table 2, “BeanShell attributes” lists the built-in attributes that are accessible when using BeanShell.

Table 2. BeanShell attributes

Attribute | Type | Value
--- | --- | ---
`context` | `org.apache.camel.CamelContext` | The Camel Context
`exchange` | `org.apache.camel.Exchange` | The current Exchange
`request` | `org.apache.camel.Message` | The IN message
`response` | `org.apache.camel.Message` | The OUT message

The attributes all set at `ENGINE_SCOPE`.

## Example

Example 2, “Routes using BeanShell” shows two routes that use BeanShell scripts.

Example 2. Routes using BeanShell

    <camelContext>
      <route>
        <from uri=""mock:mock0" />
        <filter>
          <language language="beanshell">request.getHeaders().get("Foo") == null</language>
          <to uri="mock:mock1" />
        </filter>
      </route>
      <route>
        <from uri="direct:in"/>
        <setHeader headerName="firstName">
          <expression language="beanshell">user.firstName</expression>
        </setHeader>
        <to uri="seda:users"/>
      </route>
    </camelContext>