Versions Compared

Key

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

...


*Available as of Camel 2.4

...

*

The *ejb:* component binds EJBs to Camel message exchanges.

h3.

...

 URI format

...



{code
}
ejb:ejbName[?options]

Where ejbName can be any string which is used to look up the EJB in the Application Server JNDI Registry

Options

Name

Type

Default

Description

method

String

null

The method name that bean will be invoked. If not provided, Camel will try to pick the method itself. In case of ambiguity an exception is thrown. See Bean Binding for more details.

multiParameterArray

boolean

false

How to treat the parameters which are passed from the message body; if it is true, the In message body should be an array of parameters.

...

{code}
Where *ejbName* can be any string which is used to look up the EJB in the Application Server JNDI [Registry]

h3. Options
{div:class=confluenceTableSmall}
|| Name || Type || Default || Description ||
| {{method}} | {{String}} | {{null}} | The method name that bean will be invoked. If not provided, Camel will try to pick the method itself. In case of ambiguity an exception is thrown. See [Bean Binding] for more details. |
| {{multiParameterArray}} | {{boolean}} | {{false}} | How to treat the parameters which are passed from the message body; if it is {{true}}, the In message body should be an array of parameters. |
{div}

You can append query options to the URI in the following format, {{?option=value&option=value&...

...

The EJB component extends the Bean component in which most of the details from the Bean component applies to this component as well.

Bean Binding

How bean methods to be invoked are chosen (if they are not specified explicitly through the method parameter) and how parameter values are constructed from the Message are all defined by the Bean Binding mechanism which is used throughout all of the various Bean Integration mechanisms in Camel.

Examples

In the following examples we use the Greater EJB which is defined as follows:

Wiki Markup
}}

The [EJB] component extends the [Bean] component in which most of the details from the [Bean] component applies to this component as well.

h3. Bean Binding

How bean methods to be invoked are chosen (if they are not specified explicitly through the *method* parameter) and how parameter values are constructed from the [Message] are all defined by the [Bean Binding] mechanism which is used throughout all of the various [Bean Integration] mechanisms in Camel.

h3. Examples

In the following examples we use the Greater EJB which is defined as follows:
{snippet:id=e1|lang=java|title=GreaterLocal.java|url=camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterLocal.java}

And the

...

Wiki Markup
 implementation
{snippet:id=e1|lang=java|title=GreaterImpl.java|url=camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterImpl.java}

h4. Using Java DSL

...



In this example we want to invoke the {{hello}} method on the EJB. Since this example is based on an unit test using Apache OpenEJB we have to set a {{JndiContext}} on the [EJB] component with the OpenEJB settings.

...

Wiki Markup


{snippet:id=e1|lang=java|url=camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterCamelEjbTest.java}

Then we are ready to use the EJB in the Camel route:

...

Wiki Markup


{snippet:id=e2|lang=java|url=camel/trunk/components/camel-ejb/src/test/java/org/apache/camel/component/ejb/GreaterCamelEjbTest.java}

{tip
Wiki Markup
:title
=In a real application server
}
In a real application server you most likely do not have to setup a {{JndiContext}} on the [EJB] component as it will create a default {{JndiContext}} on the same JVM as the application server, which usually allows it to access the JNDI registry and lookup the [EJB]s.


However if you need to access a application server on a remote JVM or the likes, you have to prepare the properties beforehand.

Using Spring XML

And this is the same example using Spring XML instead:

Again since this is based on an unit test we need to setup the EJB component:


{tip}

h4. Using Spring XML

And this is the same example using Spring XML instead:

Again since this is based on an unit test we need to setup the [EJB] component:

{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-ejb/src/test/resources/org/apache/camel/component/ejb/SpringGreaterCamelEjbTest.xml}

Before we are ready to use [EJB] in the Camel routes:

...

Wiki Markup


{snippet:id=e2|lang=xml|url=camel/trunk/components/camel-ejb/src/test/resources/org/apache/camel/component/ejb/SpringGreaterCamelEjbTest.xml}

...





{include:Endpoint See

...

 Also}
* [Bean]
* [Bean Binding]
* [Bean Integration]