users@jersey.java.net

Re: [Jersey] Felix/Grizzly/Jersey

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 05 Jan 2010 15:54:23 +0100

On Tue, Jan 05, 2010 at 03:05:01PM +0100, Paul Sandoz wrote:
>
> On Dec 29, 2009, at 11:42 AM, Paul Sandoz wrote:
>
> >Hi David,
> >
> >Jakub, who is currently on holiday, is working on OSGi integration.
> >There is a branch:
> >
> > branches/jersey-osgi-fication/jersey

no, it is: branches/jersey-servicemix

i am sorry for not responding earlier. After fixing some minor issues,
i am going to merge the osgi stuff to the main trunk, so that people
could give it a test drive.

~Jakub

> >
>
> Wrong branch, it is
>
> branches/jersey-osgi-fication
>
> To build and test you need to use SE 6.
>
> Paul.
>
> >where some good progress has been made. Perhaps you can check out
> >that branch and have a look?
> >
> >We would like to have such support ready for Jersey 1.1.5 (scheduled
> >for middle of Jan) but i think we may require some help with testing
> >because we want to ensure we get this correct.
> >
> >There are some issues still left to resolve but we are getting
> >close. IIRC the main issue is one of scanning for resource and
> >provider classes, and instead a Jersey application bundle needs to
> >explicitly register such classes via an implementation of
> >javax.ws.rs.core.Application.
> >
> >
> >The main issue with Jersey integration is that Jersey utilizes META-
> >INF/services files [*] and we need a way of integrating support that
> >is OSGi friendly.
> >
> >Paul.
> >
> >[*] META-INF/services files are a very poor choice for dynamic
> >modules!
> >
> >On Dec 27, 2009, at 9:27 PM, David Tkaczyk wrote:
> >
> >>Hi,
> >>
> >>I'm really struggling (going on 2 or 3 days now) to get Felix to
> >>work with a
> >>Grizzly Http Service deploying Jersey. I've googled like crazy to
> >>try and resolve on my own, but no luck. I'm hoping that I'm
> >>overlooking
> >>something simple that someone can point out to me. Everything is
> >>ACTIVE/RESOLVED from an osgi perspective. My problem appears to be
> >>that
> >>Jersey cannot locate my resource file. Along with Jersey's
> >>inability to
> >>find my resource class there's also a stack trace
> >>(ServiceConfigurationError)
> >>that I'll post below. Also, I’ve posted this on the felix site as
> >>well, but
> >>haven’t received any help.
> >>
> >>Thanks,
> >>Dave
> >>
> >>package camiant.osgi.msr.rest;
> >>
> >>import java.util.Dictionary;
> >>import java.util.Hashtable;
> >>import org.osgi.framework.ServiceReference;
> >>import org.osgi.service.http.HttpService;
> >>import org.osgi.util.tracker.ServiceTrackerCustomizer;
> >>import org.slf4j.Logger;
> >>import org.slf4j.LoggerFactory;
> >>import com.sun.jersey.server.impl.container.servlet.ServletAdaptor;
> >>
> >>public class HttpServiceServiceTrackerCustomizer implements
> >>ServiceTrackerCustomizer {
> >>
> >> private static final Logger LOGGER =
> >>LoggerFactory.getLogger(HttpServiceServiceTrackerCustomizer.class);
> >>
> >> private static final Dictionary<String, String>
> >>JERSEY_INIT_PARAMS = new
> >>Hashtable<String, String>();
> >>
> >> static {
> >> // NOTE: I've tried several different ways to get Jersey to
> >>find my
> >>resource file, but no luck. package config/resource config/custom
> >>Application
> >> // Just about every different way that Jersey
> >>allows, I've
> >>tried
> >>
> >> JERSEY_INIT_PARAMS.put("com.sun.jersey.config.property.packages",
> >>"camiant.osgi.msr.rest.resource");
> >> }
> >>
> >> @Override
> >> public Object addingService(ServiceReference serviceRef) {
> >>
> >> LOGGER.info("Adding service: " +
> >>serviceRef.getBundle().getSymbolicName());
> >>
> >> HttpService grizzlyService =
> >>(HttpService
> >>)serviceRef.getBundle().getBundleContext().getService(serviceRef
> >>);
> >>
> >> try {
> >> // NOTE: as you see I've tried both ServletContainer and
> >>ServletAdaptor - both produce similar results
> >>
> >> //grizzlyService.registerServlet("/rs", new ServletContainer(),
> >>JERSEY_INIT_PARAMS, null);
> >>
> >> grizzlyService.registerServlet("/rs", new ServletAdaptor(),
> >>JERSEY_INIT_PARAMS, null);
> >> } catch (Exception e) {
> >> e.printStackTrace(); //TODO what is best here..
> >> grizzlyService = null;
> >> }
> >>
> >> return grizzlyService;
> >> }
> >>}
> >>
> >>package camiant.osgi.msr.rest.resource;
> >>
> >>import javax.ws.rs.GET;
> >>import javax.ws.rs.Path;
> >>import javax.ws.rs.Produces;
> >>import javax.ws.rs.core.Response;
> >>
> >>@Path("/msr")
> >>public class TestResource {
> >>
> >> @GET
> >> @Path("/keytypes")
> >> @Produces("text/xml")
> >> public Response getKeyTypes() {
> >> return Response.ok().entity("this is a cheap key
> >>type!!!!!!!!!").build();
> >> }
> >>}
> >>
> >>Welcome to Felix
> >>================
> >>
> >>2009-12-23 16:30:47,872-0500 INFO
> >>RestMSRCoreServiceTrackerCustomizer:16 -
> >>Adding service: camiant.osgi.msr.core
> >>
> >>Dec 23, 2009 4:30:48 PM com.sun.grizzly.Controller logVersion
> >>
> >>INFO: Starting Grizzly Framework 1.9.18-e - Wed Dec 23 16:30:48 EST
> >>2009
> >>
> >>2009-12-23 16:30:48,220-0500 INFO
> >>HttpServiceServiceTrackerCustomizer:65 -
> >>Adding service: com.sun.grizzly.osgi.grizzly-httpservice-bundle
> >>
> >>Dec 23, 2009 4:30:48 PM
> >>com.sun.jersey.api.core.PackagesResourceConfig init
> >>
> >>INFO: Scanning for root resource and provider classes in the
> >>packages:
> >> camiant.osgi.msr.rest.resource
> >>
> >>Dec 23, 2009 4:30:48 PM
> >>com.sun.jersey.api.core.ScanningResourceConfig init
> >>INFO: No root resource classes found.
> >>Dec 23, 2009 4:30:48 PM
> >>com.sun.jersey.api.core.ScanningResourceConfig init
> >>INFO: No provider classes found.
> >>
> >>ERROR: EventDispatcher: Error during dispatch.
> >>(com.sun.jersey.spi.service.ServiceConfigurationError:
> >>com.sun.jersey.spi.container.WebApplicationProvider: The class
> >>com.sun.jersey.server.impl.container.WebApplicationProviderImpl
> >>implementing
> >>provider interface
> >>com.sun.jersey.spi.container.WebApplicationProvider could
> >>not be instantiated: null)
> >>
> >>com.sun.jersey.spi.service.ServiceConfigurationError:
> >>com.sun.jersey.spi.container.WebApplicationProvider: The class
> >>com.sun.jersey.server.impl.container.WebApplicationProviderImpl
> >>implementing
> >>provider interface
> >>com.sun.jersey.spi.container.WebApplicationProvider could
> >>not be instantiated: null
> >>
> >> at
> >>com.sun.jersey.spi.service.ServiceFinder.fail(ServiceFinder.java:380)
> >> at
> >>com.sun.jersey.spi.service.ServiceFinder.access
> >>$600(ServiceFinder.java:144)
> >> at
> >>com.sun.jersey.spi.service.ServiceFinder
> >>$LazyObjectIterator.hasNext(ServiceF
> >>inder.java:683)
> >> at
> >>com
> >>.sun
> >>.jersey.spi.container.WebApplicationFactory.createWebApplication(WebA
> >>pplicationFactory.java:61)
> >> at
> >>com
> >>.sun
> >>.jersey.spi.container.servlet.ServletContainer.create(ServletContaine
> >>r.java:325)
> >> at
> >>com.sun.jersey.spi.container.servlet.ServletContainer
> >>$InternalWebComponent.c
> >>reate(ServletContainer.java:240)
> >> at
> >>com
> >>.sun
> >>.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:548
> >>)
> >> at
> >>com
> >>.sun
> >>.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:201
> >>)
> >> at
> >>com
> >>.sun
> >>.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.
> >>java:307)
> >> at
> >>com
> >>.sun
> >>.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.
> >>java:470)
> >> at
> >>javax.servlet.GenericServlet.init(GenericServlet.java:242)
> >> at
> >>com
> >>.sun
> >>.grizzly.http.servlet.ServletAdapter.loadServlet(ServletAdapter.java:
> >>428)
> >> at
> >>com
> >>.sun
> >>.grizzly.osgi.httpservice.OSGiServletAdapter.startServlet(OSGiServlet
> >>Adapter.java:99)
> >> at
> >>com
> >>.sun
> >>.grizzly.osgi.httpservice.OSGiMainAdapter.registerServletAdapter(OSGi
> >>MainAdapter.java:178)
> >> at
> >>com
> >>.sun
> >>.grizzly.osgi.httpservice.HttpServiceImpl.registerServlet(HttpService
> >>Impl.java:92)
> >> at
> >>camiant
> >>.osgi.msr.rest.HttpServiceServiceTrackerCustomizer.addingService(Http
> >>ServiceServiceTrackerCustomizer.java:70)
> >> at
> >>org.osgi.util.tracker.ServiceTracker
> >>$Tracked.customizerAdding(ServiceTracker
> >>.java:896)
> >> at
> >>org
> >>.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:
> >>261)
> >> at
> >>org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
> >> at
> >>org.osgi.util.tracker.ServiceTracker
> >>$Tracked.serviceChanged(ServiceTracker.j
> >>ava:840)
> >> at
> >>org
> >>.apache
> >>.felix.framework.util.EventDispatcher.invokeServiceListenerCallbac
> >>k(EventDispatcher.java:878)
> >> at
> >>org
> >>.apache
> >>.felix.framework.util.EventDispatcher.fireEventImmediately(EventDi
> >>spatcher.java:732)
> >> at
> >>org
> >>.apache
> >>.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispat
> >>cher.java:662)
> >> at
> >>org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:3587)
> >> at org.apache.felix.framework.Felix.access
> >>$000(Felix.java:40)
> >> at
> >>org.apache.felix.framework.Felix$1.serviceChanged(Felix.java:625)
> >> at
> >>org
> >>.apache
> >>.felix.framework.ServiceRegistry.registerService(ServiceRegistry.j
> >>ava:90)
> >> at
> >>org.apache.felix.framework.Felix.registerService(Felix.java:2711)
> >> at
> >>org
> >>.apache
> >>.felix.framework.BundleContextImpl.registerService(BundleContextIm
> >>pl.java:252)
> >> at
> >>org
> >>.apache
> >>.felix.framework.BundleContextImpl.registerService(BundleContextIm
> >>pl.java:230)
> >> at
> >>com.sun.grizzly.osgi.httpservice.Activator.start(Activator.java:89)
> >> at
> >>org
> >>.apache
> >>.felix.framework.util.SecureAction.startActivator(SecureAction.jav
> >>a:639)
> >> at
> >>org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
> >> at
> >>org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
> >> at
> >>org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1077)
> >> at
> >>org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:
> >>264)
> >> at java.lang.Thread.run(Thread.java:619)
> >>Caused by: java.lang.ClassCastException
> >> at java.lang.Class.cast(Class.java:2990)
> >> at
> >>com.sun.jersey.spi.service.ServiceFinder
> >>$LazyObjectIterator.hasNext(ServiceF
> >>inder.java:641)
> >>
> >> ... 34 more
> >>
> >>[INFO] Started bridged http service
> >>ps
> >>
> >>START LEVEL 1
> >>
> >> ID State Level Name
> >>[ 0] [Active ] [ 0] System Bundle (2.0.1)
> >>[ 1] [Active ] [ 1] Ant repackaging (3.0.0.b74b)
> >>[ 2] [Active ] [ 1] ASM all classes (3.2)
> >>[ 3] [Active ] [ 1] Camiant MSR Core (0.1.0)
> >>[ 4] [Active ] [ 1] Camiant MSR REST (0.1.0)
> >>[ 5] [Active ] [ 1] Grizzly OSGi HttpService Bundle
> >>(1.9.18.e)
> >>[ 6] [Active ] [ 1] http (0)
> >>[ 7] [Active ] [ 1] Jackson JSON processor (1.1.1)
> >>[ 8] [Active ] [ 1] javax.annotation API v.1.1 (3.0.0.b74b)
> >>[ 9] [Active ] [ 1] javax.ejb API v.3.1 (3.0.0.b74b)
> >>[ 10] [Active ] [ 1] Java Persistence API 2.0
> >>(2.0.0.v200911271158)
> >>[ 11] [Active ] [ 1] javax.servlet API v.3.0 (3.0.0.b74b)
> >>[ 12] [Active ] [ 1] javax.servlet.jsp API v.2.1.2
> >>(3.0.0.b74b)
> >>[ 13] [Active ] [ 1] jaxb-api (2.2)
> >>[ 14] [Active ] [ 1] jaxb (2.2)
> >>[ 15] [Active ] [ 1] jdom (0)
> >>[ 16] [Active ] [ 1] jersey-bundle (1.1.5.ea-SNAPSHOT)
> >>[ 17] [Active ] [ 1] jettison (1.1)
> >>[ 18] [Active ] [ 1] jsr311-api (1.1.1)
> >>[ 19] [Active ] [ 1] JavaMail API (1.4.3)
> >>[ 20] [Active ] [ 1] Apache Felix Configuration Admin Service
> >>(1.2.4)
> >>[ 21] [Active ] [ 1] Apache Felix Http Bundle (2.0.4)
> >>[ 22] [Active ] [ 1] Apache Felix Shell Service (1.4.1)
> >>[ 23] [Active ] [ 1] Apache Felix Shell TUI (1.4.1)
> >>[ 24] [Active ] [ 1] Apache Felix Web Management Console
> >>(2.0.2)
> >>[ 25] [Resolved ] [ 1] Camiant MSR Log4JProperties (0.5.0)
> >>[ 26] [Active ] [ 1] Apache Jakarta log4j Plug-in
> >>(1.2.15.v200910021404)
> >>[ 27] [Active ] [ 1] ROME, RSS and atOM utilitiEs for Java
> >>(1.0)
> >>[ 28] [Active ] [ 1] slf4j-api (1.5.8)
> >>[ 29] [Resolved ] [ 1] slf4j-log4j12 (1.5.8)
> >>[ 30] [Active ] [ 1] Sun Misc RT Packages (1.0.0)
> >>[ 31] [Active ] [ 1] tools (0)
> >>[ 32] [Active ] [ 1] Weld OSGi Bundle (1.0.0.SP4)
> >>
> >>
> >>David Tkaczyk
> >>Member of Technical Staff
> >>
> >><image001.gif>
> >>
> >>www.camiant.com
> >>200 Nickerson Road, Marlborough, MA 01752-4603 USA
> >>
> >><image002.gif>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
http://blogs.sun.com/japod