1

I'm using apache camel, and I will be needing the jndi registry so that I can bind an object to it.

How do I retrieve a JNDI registry from a RouteBuilder class? Can I also bind using xml? Thanks!

1
  • Is this for live code or test code? Since, in tests derived from CamelTestSupport you have CamelTestSupport.createRegistry() Feb 14, 2014 at 13:04

2 Answers 2

4

I was able to do it not within the RouteBuilder but before adding context to the camelMain.

JndiRegistry registry = new JndiRegistry();
...
registry.bind("myAntFilter", filter);

DefaultCamelContext context = new DefaultCamelContext(registry);
camelMain.getCamelContexts().add(context);

It is also important to note that you need to have a jndi.properties in your /resources with the following content:

java.naming.factory.initial = org.apache.camel.util.jndi.CamelInitialContextFactory

Without this, I'm getting an exception.

Hope it helps people who stumbled on the same problem

1
  • Thanks @yin03 for this. It was very helpful. Aug 10, 2016 at 18:00
0

Does CamelContext.getRegistry() suit your needs?

/**
 * Returns the registry used to lookup components by name and type such as the Spring ApplicationContext,
 * JNDI or the OSGi Service Registry
 *
 * @return the registry
 */
Registry getRegistry();

Otherwise, you can bind things (beans, service references, etc) into the registry via blueprint.xml or the spring context files located in META-INF.spring.

For testing purposes, you have CamelTestSupport.createRegistry().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.