You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by MarkS1900 <ma...@yahoo.com.au> on 2012/01/11 17:01:25 UTC

OSGi classpath getResources issue in ServiceMix 4.4.0

I have OSGi bundle that has configuration files in the META-INF/services/*
location. (Such as
resteasy-jaxrs-2.2.3.GA.jar/META-INF/services/javax.ws.rs.ext.Providers).

Now when another bundle attempts to access the resource with the following
code, this resource is not found:

Enumeration en =
Thread.currentThread().getContextClassLoader().getResources("META-INF/services/"
+ Providers.class.getName());

Of course if this resource exists in the current OSGi bundle, then it is
found.

More on this issue described here: 
https://issues.jboss.org/browse/RESTEASY-640

Is this expected behaviour?  Why?


--
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-classpath-getResources-issue-in-ServiceMix-4-4-0-tp5137185p5137185.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: OSGi classpath getResources issue in ServiceMix 4.4.0

Posted by MarkS1900 <ma...@yahoo.com.au>.
So you raised two points that have my attention.

Point 1:  .. you should let jaxrs-api  to load the jaxrs impl class, so in
your code you just use jaxrs api. 

Point 2:  Also servicemix specs implement a OSGiLocater, which do the trick
that make SPI works in OSGi world. 

-----------------------------
In regards to point 1
-----------------------------

I don't know how to achieve point 1 as I am using specific annotations that
relate to a resteasy provider (Jackson - JSON Provider).  I want to use
Jackson as I like the quality of the JSON it produces.  How am I to achieve
this?  Below is a brief outline of what I am doing.

I am attempting to integrate Reasteasy with OSGI (Via ServiceMix 4.4.0), and
the way Resteasy works it's providers via resource files in the
META-INF/services directory.

Resources required:

*   resteasy-jaxrs-2.2.3.GA.jar/META-INF/services/javax.ws.rs.ext.Providers
*  
resteasy-jaxrs-2.2.3.GA.jar/META-INF/services/javax.ws.rs.ext.RuntimeDelegate
*  
resteasy-jackson-provider-2.2.3.GA.jar/META-INF/services/javax.ws.rs.ext.Providers

Explained here:
* https://issues.jboss.org/browse/RESTEASY-640

My current integration efforts:
*  https://bitbucket.org/mark1900/resteasy-osgi-embedded
*  https://bitbucket.org/mark1900/resteasy-osgi-service


-----------------------------
In regards to point 2
-----------------------------

Do you have any sample code as to what this would look like?



--
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-classpath-getResources-issue-in-ServiceMix-4-4-0-tp5137185p5137796.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: OSGi classpath getResources issue in ServiceMix 4.4.0

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

The SMX spec project heavily use OSGiLocater class to retrieve impl  
class from  META-INF/services/*, it hack the FactoryLocator class in  
the spec api to let OSGiLocater kick in and load the  correct impl  
class from available impl bundle in OSGi container,  for an instance,  
take a look at [1] to get more details.

[1]https://svn.apache.org/repos/asf/servicemix/smx4/specs/trunk/stax-api-1.2/src/main/java/javax/xml/stream/FactoryLocator.java
Freeman
On 2012-2-2, at 上午12:47, MarkS1900 wrote:

>
> Can anyone direct me to sample code using this ServiceMix  
> OSGiLocater class
> to retrieve a META-INF/services/* resource?
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-classpath-getResources-issue-in-ServiceMix-4-4-0-tp5137185p5448070.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.

---------------------------------------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com










Re: OSGi classpath getResources issue in ServiceMix 4.4.0

Posted by MarkS1900 <ma...@yahoo.com.au>.
Can anyone direct me to sample code using this ServiceMix OSGiLocater class
to retrieve a META-INF/services/* resource? 

--
View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-classpath-getResources-issue-in-ServiceMix-4-4-0-tp5137185p5448070.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: OSGi classpath getResources issue in ServiceMix 4.4.0

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

Yeah, it's expected behavior in OSGi world.

Generally let's say bundleA has some resource in package x.y.z,  if  
bundleB want to use that resource, it must explicitly import that  
package, so that resource is available for bundleB.

But package like META-INF/services/ is a little bit different, as it's  
JAVA SPI mechanism, it exist in a lot of bundles, which means it cause  
split package issue, so you can't just simply import package META-INF/ 
services in bundleB.  There're several solutions to handle this issue,  
like make bundleA as a fragment bundle, attach to bundleB(bundleB as  
host bundle), so that all resource from BundleA is available in BundleB.

But IMO you shouldn't use code like

Enumeration en =
Thread.currentThread().getContextClassLoader().getResources("META-INF/ 
services/"
+ Providers.class.getName());
at all, as SPI mechanism is standard in java, you should let jaxrs-api  
to load the jaxrs impl class, so in your code you just use jaxrs api.
Also servicemix specs implement a OSGiLocater, which do the trick that  
make SPI works in OSGi world.

Freeman
On 2012-1-12, at 上午12:01, MarkS1900 wrote:

> I have OSGi bundle that has configuration files in the META-INF/ 
> services/*
> location. (Such as
> resteasy-jaxrs-2.2.3.GA.jar/META-INF/services/ 
> javax.ws.rs.ext.Providers).
>
> Now when another bundle attempts to access the resource with the  
> following
> code, this resource is not found:
>
> Enumeration en =
> Thread.currentThread().getContextClassLoader().getResources("META- 
> INF/services/"
> + Providers.class.getName());
>
> Of course if this resource exists in the current OSGi bundle, then  
> it is
> found.
>
> More on this issue described here:
> https://issues.jboss.org/browse/RESTEASY-640
>
> Is this expected behaviour?  Why?
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/OSGi-classpath-getResources-issue-in-ServiceMix-4-4-0-tp5137185p5137185.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.

---------------------------------------------
Freeman Fang

FuseSource
Email:ffang@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com