JNDI


This page presents how to interact with JNDI through the example of a JMS connection using JNDI. Retrieving a database connection or any other object from JNDI works the same way than JMS.

Library

First, create a single library with all the needed jars:

  • The ones for the JNDI connection (if any)
  • The ones for the JMS driver

JndiDirectory

Connector

First, create a new connector of type JNDI and select Internal class: JndiDirectory using the previously created library. Configure it using the available properties, you need to configure at least initialContextFactory and providerURL.

Available properties

Property Javadoc
initialContextFactory The initial context factory to use. (javadoc)
objectFactories The list of object factories to use. (javadoc)
stateFactories The list of state factories to use. (javadoc)
urlPkgPrefixes The list of package prefixes to use when loading in URL context factories. (javadoc)
providerURL Configuration information for the service provider to use. (javadoc)
dnsURL The DNS host and domain names to use for the JNDI URL context (for example, "dns://somehost/wiz.com"). (javadoc)
authoritative The authoritativeness of the service requested. (javadoc)
batchSize The batch size to use when returning data via the service's protocol. (javadoc)
referral How referrals encountered by the service provider are to be processed. (javadoc)
securityProtocol The security protocol to use. (javadoc)
securityAuthentication The security level to use. (javadoc)
securityPrincipal The identity of the principal for authenticating the caller to the service. (javadoc)
securityCredentials The credentials of the principal for authenticating the caller to the service. (javadoc)
language The preferred language to use with the service. (javadoc)

Routing Context

Now you can use it from the routing context. The connector name that you should use is ${CONNECTOR_NAME} + '/' + ${JNDI_LOOKUP}

Considering that the connector is named customJndiConnector and contains an ActiveMQ JMS connection named amq, the routing context definition will be:

 <?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
    <route>
        <from uri="jms:queue:test?connectionFactory=customJndiConnector/amq"/>
        <log message="${body}" />
    </route>
</routes>

JndiEnvironmentDirectory

In case JNDI properties need to be shared by multiple components (for example, to use destinationResolver property as describe in JMS documentation), you can instantiate JndiEnvironment internal class, that contains same properties describe in available properties.

Connectors

JndiEnvironment internal class

Create a new connector of type Other and set Class name com.systar.aluminium.engine.impl.util.JndiEnvironment, using the previously created library.

Configure it using the available properties, you need to configure at least initialContextFactory and providerURL.

JndiDestinationResolver

Create a new connector of type Other and set Class name org.springframework.jms.support.destination.JndiDestinationResolver, using default class loader.

Configure the property jndiTemplate: only one implementation should be available.

In jndiTemplate, configure the property environment using the reference to jndiEnvironment previously created.

JndiEnvironmentDirectory internal class

First, create a new connector of type JNDI and select Internal class: JndiEnvironmentDirectory using the previously created library.

Configure the property jndiEnvironment using the reference to jndiEnvironment previously created.

Routing Context

<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
    <route>
        <from uri="jms:queue:jndi/JMSQUEUE?destinationResolver=#jndiDestinationResolver&amp;connectionFactory=jndiConnectionFactory/jndi.JMSConnectionFactory"/>
        <log message="${body}"/>
    </route>
</routes>

In this example, we use:


In some cases, JNDI bean deserialization can be in error because some classes are not found in the routing context classpath.

To solve the problem, you need to extend the routing context classpath with the library that contains expected classes. See How to use libraries in a context route to link a library to your routing context.

 

 

Related Links