You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jens <sm...@dzbank.de> on 2016/03/30 16:16:38 UTC

Camel on OSGi - Get Bundle Name?

Hi,

I'm running Camel in an OSGi container (Karaf). I'd like to get hold of the
OSGi bundle (or bundle name) that the route (or the context) belongs to in
one of my processors.

Is there a way to get that information somehow?

Thanks,
Jens



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-on-OSGi-Get-Bundle-Name-tp5780045.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel on OSGi - Get Bundle Name?

Posted by Claus Ibsen <cl...@gmail.com>.
You can get the CamelContext and get that as BlueprintCamelContext and
OsgiDefaultCamelContext for either of them.

They have the bundle context. But it seems its maybe not exposed as a getter.

We could add those so they have it.

You can use the adapt method on camel context

BlueprintCamelContext blue = context.adapt(BlueprintCamelContext.class);
blue.getBundleContext().getBundle().getBundleId();

We could have a common interface for those osgi stuff so its

OsgiCamelContext osgi = ...

And then its the same for spring-dm and blueprint and scr.

Or add some bundle activator or listener or whatever and grab the
bundle id that way, and then your app can get it from that guy.



On Wed, Mar 30, 2016 at 5:43 PM, Jens <sm...@dzbank.de> wrote:
> Ranx wrote
>> There are a variety of ways to do that but what is it you are after
>> actually?  There may be easier ways to accomplish what you are after.  Are
>> you using Blueprint?  One mechanism is the BlueprintListener.  You can
>> also get the information and inject it during instantiation and I think
>> the FrameworkUtil will also let you get that information (don't quote me
>> on that one though).
>>
>> I find that when I'm trying to get the bundle for some reason there is
>> usually something else I'm trying to accomplish and that there's an
>> easier, different or better way to do it.
>
> I do need the bundle name for a centralized logging service. The processor
> may appear in both routes using Blueprint and routes using Spring. My
> question is, *how* do I get that information (the bundle name)? How do I
> find out which bundle a route or context is defined in (or, alternatively,
> run from)? I don't see how BlueprintListener or FrameworkUtil can help
> there.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-on-OSGi-Get-Bundle-Name-tp5780045p5780062.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Camel on OSGi - Get Bundle Name?

Posted by Jens <sm...@dzbank.de>.
Thanks, both of you.

I can't use the BlueprintBundleContext directly because I may not be running
under Blueprint, but I'll figure something out from these leads.

Claus, the common OsgiCamelContext idea sounds neat.

Jens



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-on-OSGi-Get-Bundle-Name-tp5780045p5780070.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel on OSGi - Get Bundle Name?

Posted by Ranx <br...@mediadriver.com>.
If you're trying to the get the bundle symbolic name when in  your processor
you can inject it at start up.

<bean id="myProcessor" class="com.FooProcessor">
    <property name="bundleContext" ref="blueprintBundleContext"></property>
 </bean>

The ref to the blueprintBundleContext is provided by default.  You can get
the bundle and symbolic name (and pretty much anything else) from it.  I'm
not sure if that's what you are after though.  Claus obviously mentions the
mechanics for getting it from the CamelContext.  As I rarely use processors
and just use pojos instead I don't generally grab information from Camel
directly.

I've never tried invoking a method on a pojo using the ref to the
blueprintBundleContext but would imagine that would work as well.

Note that that isn't really anything especially blueprint.  It just passes
in a standard OSGi BundleContext.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-on-OSGi-Get-Bundle-Name-tp5780045p5780069.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel on OSGi - Get Bundle Name?

Posted by Jens <sm...@dzbank.de>.
Ranx wrote
> There are a variety of ways to do that but what is it you are after
> actually?  There may be easier ways to accomplish what you are after.  Are
> you using Blueprint?  One mechanism is the BlueprintListener.  You can
> also get the information and inject it during instantiation and I think
> the FrameworkUtil will also let you get that information (don't quote me
> on that one though).
> 
> I find that when I'm trying to get the bundle for some reason there is
> usually something else I'm trying to accomplish and that there's an
> easier, different or better way to do it.

I do need the bundle name for a centralized logging service. The processor
may appear in both routes using Blueprint and routes using Spring. My
question is, *how* do I get that information (the bundle name)? How do I
find out which bundle a route or context is defined in (or, alternatively,
run from)? I don't see how BlueprintListener or FrameworkUtil can help
there.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-on-OSGi-Get-Bundle-Name-tp5780045p5780062.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel on OSGi - Get Bundle Name?

Posted by Ranx <br...@mediadriver.com>.
There are a variety of ways to do that but what is it you are after actually? 
There may be easier ways to accomplish what you are after.  Are you using
Blueprint?  One mechanism is the BlueprintListener.  You can also get the
information and inject it during instantiation and I think the FrameworkUtil
will also let you get that information (don't quote me on that one though).

I find that when I'm trying to get the bundle for some reason there is
usually something else I'm trying to accomplish and that there's an easier,
different or better way to do it.

Brad



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-on-OSGi-Get-Bundle-Name-tp5780045p5780048.html
Sent from the Camel - Users mailing list archive at Nabble.com.