camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jyrki Ruuskanen (JIRA)" <>
Subject [jira] [Commented] (CAMEL-7875) Easier write access to Camel context registry
Date Mon, 29 Sep 2014 09:00:45 GMT


Jyrki Ruuskanen commented on CAMEL-7875:

Ended up creating a helper method as a temporary workaround:

    public static <T extends Registry> void addToRegistry(final T registry, final String
name, final Object bean) {
        Registry reg = registry;

        // Unwrap PropertyPlaceholderDelegateRegistry
        if (registry instanceof PropertyPlaceholderDelegateRegistry) {
            reg = ((PropertyPlaceholderDelegateRegistry) reg).getRegistry();

        if (reg instanceof CompositeRegistry) {
            // getRegistryList() not available in Camel 2.12
            SimpleRegistry r = new SimpleRegistry();
            r.put(name, bean);
            ((CompositeRegistry) reg).addRegistry(r);
        } else if (reg instanceof JndiRegistry) {
            ((JndiRegistry) reg).bind(name, bean);
        } else if (reg instanceof SimpleRegistry) {
            ((SimpleRegistry) reg).put(name, bean);
        } else {
            throw new IllegalArgumentException("Couldn't add bean. Unknown registry type:
" + reg.getClass());

        if (registry.lookupByName(name) != bean) {
            throw new IllegalArgumentException("Couldn't add bean. Bean not found from the

> Easier write access to Camel context registry
> ---------------------------------------------
>                 Key: CAMEL-7875
>                 URL:
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Jyrki Ruuskanen
>            Priority: Minor
> I haven't found a nice way to add beans to Camel context registry through Camel context
reference in plain Java. Some beans are only needed by a certain endpoint and it would make
sense to set the bean up with the endpoint in routebuilder configure method.
> If we added a reference to self in SimpleRegistry we could setup the Camel context by
DefaultCamelContext(new SimpleRegistry()) or OsgiDefaultCamelContext(bundleContext, new SimpleRegistry())
and easily access the registry from the routebuilder with SimpleRegistry registry = (SimpleRegistry)
> Then we can set up beans in routebuilder configure and simply add them with registry.put.
And the same routebuilder could be used in plain Java, in OSGi or elsewhere.
> All that is needed is this change in SimpleRegistry:
> {code}
> public static final String NAME;
> static {
>    NAME = java.util.UUID.randomUUID().tostring();
> }
> public SimpleRegistry() {
>    put.(NAME, this);
> }
> {code}

This message was sent by Atlassian JIRA

View raw message