You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Josh Holtzman <jh...@berkeley.edu> on 2008/11/20 22:38:52 UTC
JAX-RS in an OSGI bundle
I'm trying to publish a rest-style web service from an OSGI bundle.
I've installed the cxf-bundle-2.2-SNAPSHOT.jar bundle (built from the
trunk today) into apache felix. Here's the code, copied directly from
the cxf documentation.
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(SampleRestServiceImpl.class);
sf.setAddress("http://localhost:8000/");
sf.create();
The stack trace I'm getting is this:
Nov 20, 2008 12:57:31 PM org.apache.cxf.BusFactory newInstance
SEVERE: Failed to instantiate bus factory.
java.lang.ClassCastException: class
org.apache.cxf.bus.spring.SpringBusFactory
at java.lang.Class.asSubclass(Class.java:2979)
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:164)
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:140)
at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:69)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:106)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:97)
at
org.apache.cxf.endpoint.AbstractEndpointFactory.getBus(AbstractEndpointFactory.java:73)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.createEndpointInfo(JAXRSServerFactoryBean.java:180)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.createEndpoint(JAXRSServerFactoryBean.java:146)
at
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:88)
Publishing wsdl-based web services using Endpoint.publish(address,
webService) works just fine.
Any ideas what's up with my JAX-RS code / configuration?
Thanks,
Josh
Re: JAX-RS in an OSGI bundle
Posted by Sergey Beryozkin <se...@progress.com>.
Hi,
Another hurdle which might be lurking around, after you get past this one, is the whole FactoryFinder thing.
ServiceMix4 does some cool things in thi sregard, specifically Gui
----- Original Message -----
From: "Sergey Beryozkin" <se...@progress.com>
To: <us...@cxf.apache.org>
Sent: Friday, November 21, 2008 10:09 AM
Subject: Re: JAX-RS in an OSGI bundle
> Hi Josh
>
>
>> I'm trying to publish a rest-style web service from an OSGI bundle.
>
> You're ahead of us in trying to do it :-).
> I've not had time at all to look into publishing JAXRS endpoint into OSGI containers but I will.
> I'll definitely look into making sure CXF JAXRS-based endpoints play nice in the OSGI environment too. In fact I'd expect them to
> work and eventually be accessible in the Distributed OSGI environment too.
>
>> I've installed the cxf-bundle-2.2-SNAPSHOT.jar bundle (built from the trunk today) into apache felix. Here's the code, copied
>> directly from the cxf documentation.
>>
>> JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>> sf.setResourceClasses(SampleRestServiceImpl.class);
>> sf.setAddress("http://localhost:8000/");
>> sf.create();
>>
>
> I'll need to have a look and see what is that JAXRSServerFactoryBean is missing, as compared to Endpoint.publish. It's either
> setting the default bus or context loader is wrong.
>
> One hack I used to rely upon is to setting a thread context loader to the one which loaded say JAXRSServerFactoryBean.class just
> before the code you do above, this will be an OSGI container class loader and often it helped.
>
> Another thing to try is Spring OSGI. It works in most cases really. In this case you'd need to use jaxrs:server configuration and
> put it into META-INF/spring in your bundle.
> For ex, if you look at [1], you can see all the spring bundles which need to be installed (I think you can fine spring bundles
> which encompass all of them so you'd need to install up to 2-3 bundles max) :
>
> // the first 5 bundles are Spring bundles, we used a single Spring bundle (spring.jar or spring-all.jar ?) available from Spring
> repo earlier :
> start file:${maven.repo.local}/org/springframework/spring-core/${spring.version}/spring-core-${spring.version}.jar
> start file:${maven.repo.local}/org/springframework/spring-beans/${spring.version}/spring-beans-${spring.version}.jar
> start file:${maven.repo.local}/org/springframework/spring-context/${spring.version}/spring-context-${spring.version}.jar
> start file:${maven.repo.local}/org/aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar
> start file:${maven.repo.local}/org/springframework/spring-aop/${spring.version}/spring-aop-${spring.version}.jar
>
> // Spring OSGI bundles
>
> start
> file:${maven.repo.local}/org/springframework/osgi/spring-osgi-io/${spring.osgi.version}/spring-osgi-io-${spring.osgi.version}.jar
>
> start
> file:${maven.repo.local}/org/springframework/osgi/spring-osgi-core/${spring.osgi.version}/spring-osgi-core-${spring.osgi.version}.jar
>
> start
> file:${maven.repo.local}/org/springframework/osgi/spring-osgi-extender/${spring.osgi.version}/spring-osgi-extender-${spring.osgi.version}.jar
>
>
> So if you drop those ones into Felix and then deploy a JAXRS bundle with the Spring config involved then it might work just fine.
> You might want tosave yourself some time and quickly try a ServiceMix4 distribution which uses Felix and has all the Spring and
> Soring OSGI bundles preinstalled
>
> Let me know how it all goes please and in meantime I'll try to fix the direct endpoint publication
>
> Cheers, Sergey
>
>> The stack trace I'm getting is this:
>>
>> Nov 20, 2008 12:57:31 PM org.apache.cxf.BusFactory newInstance
>> SEVERE: Failed to instantiate bus factory.
>> java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
>> at java.lang.Class.asSubclass(Class.java:2979)
>> at org.apache.cxf.BusFactory.newInstance(BusFactory.java:164)
>> at org.apache.cxf.BusFactory.newInstance(BusFactory.java:140)
>> at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:69)
>> at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:106)
>> at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:97)
>> at org.apache.cxf.endpoint.AbstractEndpointFactory.getBus(AbstractEndpointFactory.java:73)
>> at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.createEndpointInfo(JAXRSServerFactoryBean.java:180)
>> at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.createEndpoint(JAXRSServerFactoryBean.java:146)
>> at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:88)
>>
>> Publishing wsdl-based web services using Endpoint.publish(address, webService) works just fine.
>>
>> Any ideas what's up with my JAX-RS code / configuration?
>>
>> Thanks,
>> Josh
>>
>>
>
>
>
Re: JAX-RS in an OSGI bundle
Posted by Sergey Beryozkin <se...@progress.com>.
Hi Josh
> I'm trying to publish a rest-style web service from an OSGI bundle.
You're ahead of us in trying to do it :-).
I've not had time at all to look into publishing JAXRS endpoint into OSGI containers but I will.
I'll definitely look into making sure CXF JAXRS-based endpoints play nice in the OSGI environment too. In fact I'd expect them to
work and eventually be accessible in the Distributed OSGI environment too.
> I've installed the cxf-bundle-2.2-SNAPSHOT.jar bundle (built from the trunk today) into apache felix. Here's the code, copied
> directly from the cxf documentation.
>
> JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
> sf.setResourceClasses(SampleRestServiceImpl.class);
> sf.setAddress("http://localhost:8000/");
> sf.create();
>
I'll need to have a look and see what is that JAXRSServerFactoryBean is missing, as compared to Endpoint.publish. It's either
setting the default bus or context loader is wrong.
One hack I used to rely upon is to setting a thread context loader to the one which loaded say JAXRSServerFactoryBean.class just
before the code you do above, this will be an OSGI container class loader and often it helped.
Another thing to try is Spring OSGI. It works in most cases really. In this case you'd need to use jaxrs:server configuration and
put it into META-INF/spring in your bundle.
For ex, if you look at [1], you can see all the spring bundles which need to be installed (I think you can fine spring bundles which
encompass all of them so you'd need to install up to 2-3 bundles max) :
// the first 5 bundles are Spring bundles, we used a single Spring bundle (spring.jar or spring-all.jar ?) available from Spring
repo earlier :
start file:${maven.repo.local}/org/springframework/spring-core/${spring.version}/spring-core-${spring.version}.jar
start file:${maven.repo.local}/org/springframework/spring-beans/${spring.version}/spring-beans-${spring.version}.jar
start file:${maven.repo.local}/org/springframework/spring-context/${spring.version}/spring-context-${spring.version}.jar
start file:${maven.repo.local}/org/aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar
start file:${maven.repo.local}/org/springframework/spring-aop/${spring.version}/spring-aop-${spring.version}.jar
// Spring OSGI bundles
start
file:${maven.repo.local}/org/springframework/osgi/spring-osgi-io/${spring.osgi.version}/spring-osgi-io-${spring.osgi.version}.jar
start
file:${maven.repo.local}/org/springframework/osgi/spring-osgi-core/${spring.osgi.version}/spring-osgi-core-${spring.osgi.version}.jar
start
file:${maven.repo.local}/org/springframework/osgi/spring-osgi-extender/${spring.osgi.version}/spring-osgi-extender-${spring.osgi.version}.jar
So if you drop those ones into Felix and then deploy a JAXRS bundle with the Spring config involved then it might work just fine.
You might want tosave yourself some time and quickly try a ServiceMix4 distribution which uses Felix and has all the Spring and
Soring OSGI bundles preinstalled
Let me know how it all goes please and in meantime I'll try to fix the direct endpoint publication
Cheers, Sergey
> The stack trace I'm getting is this:
>
> Nov 20, 2008 12:57:31 PM org.apache.cxf.BusFactory newInstance
> SEVERE: Failed to instantiate bus factory.
> java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
> at java.lang.Class.asSubclass(Class.java:2979)
> at org.apache.cxf.BusFactory.newInstance(BusFactory.java:164)
> at org.apache.cxf.BusFactory.newInstance(BusFactory.java:140)
> at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:69)
> at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:106)
> at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:97)
> at org.apache.cxf.endpoint.AbstractEndpointFactory.getBus(AbstractEndpointFactory.java:73)
> at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.createEndpointInfo(JAXRSServerFactoryBean.java:180)
> at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.createEndpoint(JAXRSServerFactoryBean.java:146)
> at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:88)
>
> Publishing wsdl-based web services using Endpoint.publish(address, webService) works just fine.
>
> Any ideas what's up with my JAX-RS code / configuration?
>
> Thanks,
> Josh
>
>
Re: JAX-RS in an OSGI bundle
Posted by Daniel Kulp <dk...@apache.org>.
Someone started some code around this at:
http://robertojrojas-free-code.googlecode.com/svn/trunk/RESTful-Services-SpringDM/RESTful-Services-SpringDM.txt
That might help.
Dan
On Thursday 20 November 2008 4:38:52 pm Josh Holtzman wrote:
> I'm trying to publish a rest-style web service from an OSGI bundle.
> I've installed the cxf-bundle-2.2-SNAPSHOT.jar bundle (built from the
> trunk today) into apache felix. Here's the code, copied directly from
> the cxf documentation.
>
> JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
> sf.setResourceClasses(SampleRestServiceImpl.class);
> sf.setAddress("http://localhost:8000/");
> sf.create();
>
> The stack trace I'm getting is this:
>
> Nov 20, 2008 12:57:31 PM org.apache.cxf.BusFactory newInstance
> SEVERE: Failed to instantiate bus factory.
> java.lang.ClassCastException: class
> org.apache.cxf.bus.spring.SpringBusFactory
> at java.lang.Class.asSubclass(Class.java:2979)
> at org.apache.cxf.BusFactory.newInstance(BusFactory.java:164)
> at org.apache.cxf.BusFactory.newInstance(BusFactory.java:140)
> at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:69)
> at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:106)
> at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:97)
> at
> org.apache.cxf.endpoint.AbstractEndpointFactory.getBus(AbstractEndpointFact
>ory.java:73) at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.createEndpointInfo(JAXRSServerF
>actoryBean.java:180) at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.createEndpoint(JAXRSServerFacto
>ryBean.java:146) at
> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.j
>ava:88)
>
> Publishing wsdl-based web services using Endpoint.publish(address,
> webService) works just fine.
>
> Any ideas what's up with my JAX-RS code / configuration?
>
> Thanks,
> Josh
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog