Quantcast

Problems using a osgi bundle in a camel route

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problems using a osgi bundle in a camel route

Smith-John
Hi,
I have problems using a OSGI-Service/bundle in a camel route. Read tutorial-osgi-camel but didn't get it to work.

The setup:

    bundle 1 defines a Service interface (separate bundle for interface because there can be several implementations of it)
    bundle 2 implements this interface
    bundle 3 should use bundle 2 that provides interface from bundle 1

In bundle 2 (the implementation) are the two xmls, one with

<osgi:service ref="invokeService">
    <osgi:interfaces>
        <value>invoker.Invoker</value>
    </osgi:interfaces>
</osgi:service> 

and the other with

<bean id="invokeService" class="invokerImpl.InvokerImpl">
</bean>

Bundle 3 has a xml file with

 <osgi:reference id="invokeService" interface="invoker.Invoker"/>

in it. Bundle 3 and the CamelContext is started with

@Override
public void start(BundleContext bundleContext) throws Exception {
    OsgiDefaultCamelContext camelContext = new OsgiDefaultCamelContext(bundleContext);
    camelContext.addRoutes(new ExampleRoute());
    camelContext.start();
}

In my route I want to use the Service (from bundle 2) with

.to("bean:invokeService")

Exceptions I get:

19:14:39.953  TRACE  o.a.camel.core.osgi.OsgiClassResolver:42       Resolve class invokeService
19:14:39.969  TRACE  o.a.camel.core.osgi.OsgiClassResolver:84       Cannot load class: invokeService using classloader: CamleOSGIExample_1.0.0.qualifier [254]. This exception be ignored.
java.lang.ClassNotFoundException: invokeService
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513) ~[na:na]
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429) ~[na:na]
(...)

and

org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: invokeService
    at org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:68) ~[camel-core-2.10.3.jar:2.10.3]
    at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:83) ~[camel-core-2.10.3.jar:2.10.3]

I'm using Equinox. From reading I know that karaf would be the better choice, but unfortunately this isn't my decision.

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems using a osgi bundle in a camel route

Claus Ibsen-2
On Sun, Feb 24, 2013 at 5:06 PM, Smith-John <[hidden email]> wrote:

> Hi,
> I have problems using a OSGI-Service/bundle in a camel route. Read
> tutorial-osgi-camel but didn't get it to work.
>
> The setup:
>
>     bundle 1 defines a Service interface (separate bundle for interface
> because there can be several implementations of it)
>     bundle 2 implements this interface
>     bundle 3 should use bundle 2 that provides interface from bundle 1
>
> In bundle 2 (the implementation) are the two xmls, one with
>
> <osgi:service ref="invokeService">
>     <osgi:interfaces>
>         <value>invoker.Invoker</value>
>     </osgi:interfaces>
> </osgi:service>
>
> and the other with
>
> <bean id="invokeService" class="invokerImpl.InvokerImpl">
> </bean>
>
> Bundle 3 has a xml file with
>
>  <osgi:reference id="invokeService" interface="invoker.Invoker"/>
>
> in it. Bundle 3 and the CamelContext is started with
>
> @Override
> public void start(BundleContext bundleContext) throws Exception {
>     OsgiDefaultCamelContext camelContext = new
> OsgiDefaultCamelContext(bundleContext);
>     camelContext.addRoutes(new ExampleRoute());
>     camelContext.start();
> }
>
> In my route I want to use the Service (from bundle 2) with
>
> .to("bean:invokeService")
>
> Exceptions I get:
>
> 19:14:39.953  TRACE  o.a.camel.core.osgi.OsgiClassResolver:42       Resolve
> class invokeService
> 19:14:39.969  TRACE  o.a.camel.core.osgi.OsgiClassResolver:84       Cannot
> load class: invokeService using classloader:
> CamleOSGIExample_1.0.0.qualifier [254]. This exception be ignored.
> java.lang.ClassNotFoundException: invokeService
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
> ~[na:na]
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
> ~[na:na]
> (...)
>
> and
>
> org.apache.camel.NoSuchBeanException: No bean could be found in the registry
> for: invokeService
>     at
> org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:68)
> ~[camel-core-2.10.3.jar:2.10.3]
>     at
> org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:83)
> ~[camel-core-2.10.3.jar:2.10.3]
>
> I'm using Equinox. From reading I know that karaf would be the better
> choice, but unfortunately this isn't my decision.
>
> Thanks in advance.
>

Any exceptions logged at TRACE level is internal only and can be ignored.

So your problem is that you  cannot invoke the bean (impl in bundle 2)
from a Camel route in bundle 3?


>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problems-using-a-osgi-bundle-in-a-camel-route-tp5728064.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems using a osgi bundle in a camel route

Smith-John
So your problem is that you  cannot invoke the bean (impl in bundle 2)
from a Camel route in bundle 3?


yeah, right.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems using a osgi bundle in a camel route

Claus Ibsen-2
You most likely need to create a osgi registry and pass that into the
constructor of the osgi default camel context

OsgiServiceRegistry


On Mon, Feb 25, 2013 at 12:07 PM, Smith-John <[hidden email]> wrote:

> /So your problem is that you  cannot invoke the bean (impl in bundle 2)
> from a Camel route in bundle 3? /
>
> yeah, right.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Problems-using-a-osgi-bundle-in-a-camel-route-tp5728064p5728092.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems using a osgi bundle in a camel route

Smith-John
Changed it to

        OsgiServiceRegistry reg = new OsgiServiceRegistry(bundleContext);
        OsgiDefaultCamelContext camelContext = new OsgiDefaultCamelContext(bundleContext, reg);
        camelContext.addRoutes(new ExampleRoute());
        camelContext.start();

But still get "org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: invokeService"
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems using a osgi bundle in a camel route

Smith-John
This post was updated on .
Ok, changed .to("bean:invoker.Invoker") , now it works.
Thought it should be "bean:invokeService" because of defining <bean id="invokeService".
Thx for help.
Loading...