Hi Daniel:

Thanks for your reply.

Currently, my solution is exactly same your said, wrapped the
ConfiguredBeanLocator by a OSGIBeanLocator:

        private CxfEndpoint getCxfEndpoint(String uri) {
                CxfEndpoint cxfEndpoint =
(org.apache.camel.component.cxf.CxfEndpoint) endpoint(uri);
                if (null != bundleContext) {
                        Bus bus = cxfEndpoint.getBus();
                        ConfiguredBeanLocator cbl = bus == null ? null:
bus.getExtension(ConfiguredBeanLocator.class);
                        if (cbl != null) {
                                bus.setExtension(new
OSGiBeanLocator(cbl,bundleContext), ConfiguredBeanLocator.class);
                        }
                }
                return cxfEndpoint;
        }

It resolved my problem, but it looks not so nice, I just want to know if
there's any better solution. 

Or if we can change the method registerConfiguredBeanLocator() of
OSGIBusListener a little bit?

From:

    private void registerConfiguredBeanLocator() {
        final ConfiguredBeanLocator cbl =
bus.getExtension(ConfiguredBeanLocator.class);
        if (cbl instanceof ExtensionManagerImpl) {
            // wire in the OSGi things
            bus.setExtension(new OSGiBeanLocator(cbl, defaultContext), 
                             ConfiguredBeanLocator.class);
        }
    }

To:

    private void registerConfiguredBeanLocator() {
        final ConfiguredBeanLocator cbl =
bus.getExtension(ConfiguredBeanLocator.class);
        if (cbl != null ) {
            // wire in the OSGi things
            bus.setExtension(new OSGiBeanLocator(cbl, defaultContext),
ConfiguredBeanLocator.class);
        }
    }

In OSGI ENV,  Wrapped the Configured ConfiguredBeanLocator by an
OSGIBeanLocation, No matter it's an instanceof ExtensionManagerImpl or not.

How do you think?

Thanks very much.
GangLiu

-----Original Message-----
From: Daniel Kulp [mailto:[email protected]] 
Sent: Thursday, March 07, 2013 3:38 AM
To: [email protected]; liugang
Subject: Re: Question about SpringBus


Honestly, this isn't a use case we've ever really needed/considered.   In
the OSGi cases, we've always expected the container to pretty much create
the appropriate context (Spring or Blueprint) and the Bus would be created
and loaded by that context.

Most likely, you'd need to do something like create the Bus, grab the
ConfiguredBeanLocator extension, wrapper it with a new one (likely use the
Blueprint one as a starting point) that would delegate to the original
instance as well as check the context, and set that back on the Bus. 

Dan



On Mar 4, 2013, at 2:05 AM, liugang <[email protected]> wrote:

> When I developed a camel route with spring configuration and cxf component
> inside , and deployed into Karaf.
> 
> 
> 
> I always got some exceptions when I'm trying to get some extensions, for
> example, bus.getExtension(**Extension.class)
> 
> 
> 
> I checked the code , the problem is caused by
> org.apache.cxf.bus.spring.SpringBeanLocator.
> 
> 
> 
> I'm not sure, this class should be improved or not. In below method:
> 
> 
> 
>    private void loadOSGIContext(Bus b) {
> 
>        try {
> 
>            //use a little reflection to allow this to work without the
> spring-dm jars
> 
>            //for the non-osgi cases
> 
>            Method m = context.getClass().getMethod("getBundleContext");
> 
>            bundleContext = m.invoke(context);
> 
>            if (b != null) {
> 
>                @SuppressWarnings("unchecked")
> 
>                Class<Object> cls = (Class<Object>)m.getReturnType();
> 
>                b.setExtension(bundleContext, cls);
> 
>            }
> 
>        } catch (Throwable t) {
> 
>            //ignore
> 
>            osgi = false;
> 
>        }
> 
> }
> 
> 
> 
> The context object is always a BusApplicationContext, and it doen's have
the
> getBundleContext() method.
> 
> 
> 
> And also in setApplicationContext() method of SpringBus class:
> 
> 
> 
>        ConfiguredBeanLocator loc =
> getExtension(ConfiguredBeanLocator.class);
> 
>        if (!(loc instanceof SpringBeanLocator)) {
> 
>            setExtension(new SpringBeanLocator(applicationContext, this),
> ConfiguredBeanLocator.class);
> 
>        }
> 
> 
> 
> But in BluePrintBus, it's:
> 
>        setExtension(new
> BlueprintBeanLocator(getExtension(ConfiguredBeanLocator.class), container,
> context),
> 
>                           ConfiguredBeanLocator.class);
> 
> This one is ok for me.
> 
> 
> 
> So I'd like to know it's a problem of SpringBus? Or I lost some
> configuration?
> 
> 
> 
> Thanks
> 
> GangLiu
> 

-- 
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply via email to