Hi,

I think for the interface Registry a method bind() should be defined. Here comes the explanation why:

Finally I managed to create a camel context component to put a route in a black box. But I want to put this context component into a library and hide it behind an API.

Starting point was the description in http://camel.apache.org/context.html and the detailed example in http://svn.apache.org/viewvc/camel/trunk/components/camel-context/src/test/java/org/apache/camel/component/context/JavaDslBlackBoxTest.java?revision=1069442&view=markup

In the given example, the blackbox is not put in a separate library. But if I put it in a library it looks this way:

public class ContextComponent {
    public static CamelContext createContext() throws Exception {
        DefaultCamelContext atsm_context = new DefaultCamelContext();
        atsm_context.setName("ATSM");
        atsm_context.addRoutes(new ContextRouteBuilder());
        atsm_context.start();
        return atsm_context;
    }
}

public class ATSMTest extends CamelTestSupport {

    @Override
    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry registry = super.createRegistry();
        CamelContext atsm_context = ContextComponent.createContext();
        registry.bind("atsm", atsm_context);
        return registry;
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                ...
            }
        };
    }

    @Test
    public void TestRoute() throws Exception {
        ...
    }
}

The drawback here is, that the registry binding has to be done in the application not in the library.

I tried to give the registry reference to the createContext( Registry registry), to call the bind() method. But then I have to cast the registry to JndiRegistry, to call bind(). So this would only work if the application uses a JndiRegistry. If the interface Registry would define a bind() method, this would work for all registry kinds.
(For SimpleRegistry the bind() method have to call put() internally).

Is my idea correct or would this lead to other problems?

Thanks, Sven

Reply via email to