You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2012/04/26 14:09:32 UTC

OSGi resource loading question

Hi

I was looking into
https://issues.apache.org/jira/browse/CAMEL-5223

And that leads me to the camel-core-osgi component where we have our
OSGi empowered Camel stuff.
And the class org.apache.camel.core.osgi.OsgiClassResolver is used for
loading resources and classes from OSGi.

Now I got a bit baffled that the method to load a resource from the
classpath, such as a .xslt file, or what ever the user wants is
implemented as:

    public URL loadResourceAsURL(String uri) {
        ObjectHelper.notEmpty(uri, "uri");
        return bundleContext.getBundle().getEntry(uri);
    }

Now reading the javadoc for getEntry it seems that it doesnt use
classloader at all, but some other means of loading the resource.
There is another method called getResource.

So I wonder if it should have been implemented as

    public URL loadResourceAsURL(String uri) {
        ObjectHelper.notEmpty(uri, "uri");
        return bundleContext.getBundle().getResource(uri);
    }

Guillaume in case you read this. The code was developed by you. So
maybe you have a thought about this?



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: OSGi resource loading question

Posted by Claus Ibsen <cl...@gmail.com>.
2012/4/26 Leonardo Gonçalves da Silva <le...@gmail.com>:
> Hi folks,
>
> According to my research, getEntry() only ever looks in the specific bundle
> regardless of dependencies. Instead, getResource() will follow the
> classpath in order to find some resource, so it can examine dependencies
> too.
>

Thanks I came to the same conclusions reading the javadoc of these methods.

Just wondering why getResource wasn't used in the first place.


> Regards,
>
> Leonardo
>
> On Thu, Apr 26, 2012 at 9:09 AM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> Hi
>>
>> I was looking into
>> https://issues.apache.org/jira/browse/CAMEL-5223
>>
>> And that leads me to the camel-core-osgi component where we have our
>> OSGi empowered Camel stuff.
>> And the class org.apache.camel.core.osgi.OsgiClassResolver is used for
>> loading resources and classes from OSGi.
>>
>> Now I got a bit baffled that the method to load a resource from the
>> classpath, such as a .xslt file, or what ever the user wants is
>> implemented as:
>>
>>    public URL loadResourceAsURL(String uri) {
>>        ObjectHelper.notEmpty(uri, "uri");
>>        return bundleContext.getBundle().getEntry(uri);
>>    }
>>
>> Now reading the javadoc for getEntry it seems that it doesnt use
>> classloader at all, but some other means of loading the resource.
>> There is another method called getResource.
>>
>> So I wonder if it should have been implemented as
>>
>>    public URL loadResourceAsURL(String uri) {
>>        ObjectHelper.notEmpty(uri, "uri");
>>        return bundleContext.getBundle().getResource(uri);
>>    }
>>
>> Guillaume in case you read this. The code was developed by you. So
>> maybe you have a thought about this?
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
>> FuseSource
>> Email: cibsen@fusesource.com
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>
>
>
> --
> ---==========================---
> The goal of all theory is to make the basic elements as simple and as
> few as possible without having to surrender the adequate representation
> of experience
> —Albert Einstein, physicist
> ---==========================---



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: OSGi resource loading question

Posted by Leonardo Gonçalves da Silva <le...@gmail.com>.
Hi folks,

According to my research, getEntry() only ever looks in the specific bundle
regardless of dependencies. Instead, getResource() will follow the
classpath in order to find some resource, so it can examine dependencies
too.

Regards,

Leonardo

On Thu, Apr 26, 2012 at 9:09 AM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> I was looking into
> https://issues.apache.org/jira/browse/CAMEL-5223
>
> And that leads me to the camel-core-osgi component where we have our
> OSGi empowered Camel stuff.
> And the class org.apache.camel.core.osgi.OsgiClassResolver is used for
> loading resources and classes from OSGi.
>
> Now I got a bit baffled that the method to load a resource from the
> classpath, such as a .xslt file, or what ever the user wants is
> implemented as:
>
>    public URL loadResourceAsURL(String uri) {
>        ObjectHelper.notEmpty(uri, "uri");
>        return bundleContext.getBundle().getEntry(uri);
>    }
>
> Now reading the javadoc for getEntry it seems that it doesnt use
> classloader at all, but some other means of loading the resource.
> There is another method called getResource.
>
> So I wonder if it should have been implemented as
>
>    public URL loadResourceAsURL(String uri) {
>        ObjectHelper.notEmpty(uri, "uri");
>        return bundleContext.getBundle().getResource(uri);
>    }
>
> Guillaume in case you read this. The code was developed by you. So
> maybe you have a thought about this?
>
>
>
> --
> Claus Ibsen
> -----------------
> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>



-- 
---==========================---
The goal of all theory is to make the basic elements as simple and as
few as possible without having to surrender the adequate representation
of experience
—Albert Einstein, physicist
---==========================---