users@grizzly.java.net

RE: osgi httpservice jersey help

From: David Tkaczyk <djt69_at_comcast.net>
Date: Fri, 22 Jan 2010 09:53:04 -0500

Alexey,

 

Thank you very much for the response - I had just about given up hope of
ever getting this to work - it has taken up far too much time already.
Given the large amount of required Jersey bundles/jar files I'm not sure how
"small" it really is. It doesn't appear to me like the latest Jersey bundle
uses "resolution optional" enough. My code within the project is very
small.

 

I've gzipped up my entire eclipse project (~32MB) - is there an FTP site I
can drop this file in? If this is not possible I can send you a bit more of
my code. The "bundle" directory in that project has everything in it
necessary to startup felix.

 

I'm using java 1.6 and org.apache.felix.main.Main to startup Felix.

 

Thanks,
Dave

 

  _____

From: Oleksiy.Stashok_at_Sun.COM [mailto:Oleksiy.Stashok_at_Sun.COM]
Sent: Friday, January 22, 2010 9:11 AM
To: users_at_grizzly.dev.java.net
Subject: Re: osgi httpservice jersey help

 

Hi David,

 

can you pls. provide a testcase (small project) to reproduce the issue?

 

Thank you.

 

WBR,

Alexey.

 

On Jan 22, 2010, at 0:09 , David Tkaczyk wrote:





Hi,

 

Has anyone ever tested Grizzly's HttpService with a Jersey ServletContainer?
I have tried several different ways and have failed to get Jersey to locate
my resource file. I see an Embedded Grizzly test in the Jersey tests, but
not one with HttpService. I see use of the Jersey client in the Grizzly
tests, but no use of the Jersey servlet.

 

I'm using Felix BTW.

 

Here's my code and the result from the startup log file.

 

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.api.core.PackagesResourceConfig;

import com.sun.jersey.spi.container.servlet.ServletContainer;

 

public class RestGrizzlyServiceTrackerCustomizer implements
ServiceTrackerCustomizer {

 

  private static final Logger LOGGER =
LoggerFactory.getLogger(RestGrizzlyServiceTrackerCustomizer.class);

 

  @Override

  public Object addingService(ServiceReference serviceRef) {

    LOGGER.info("Adding service: " +
serviceRef.getBundle().getSymbolicName());

   

    Dictionary<String, String> JERSEY_INIT_PARAMS = new Hashtable<String,
String>();

   

    // package based

    JERSEY_INIT_PARAMS.put(PackagesResourceConfig.PROPERTY_PACKAGES,
"camiant.osgi.msr.rest.resource");

   

    // application based

    //JERSEY_INIT_PARAMS.put("javax.ws.rs.Application",
"camiant.osgi.msr.rest.MSRRestApplication");

   

    // resource based

    // JERSEY_INIT_PARAMS.put("com.sun.jersey.config.property.classnames",
Resource1.class.getCanonicalName());

    //
JERSEY_INIT_PARAMS.put("com.sun.jersey.config.property.resourceConfigClass",
ClassNamesResourceConfig.class.getName());

 

    HttpService grizzlyService =
(HttpService)serviceRef.getBundle().getBundleContext().getService(serviceRef
);

    try {

      ServletContainer jerseyServletContainer = new ServletContainer();

     

      grizzlyService.registerServlet("/rs", jerseyServletContainer,
JERSEY_INIT_PARAMS, null);

    } catch (Exception e) {

      e.printStackTrace();

      grizzlyService = null;

    }

 

    return grizzlyService;

  }

 

  @Override

  public void modifiedService(ServiceReference serviceRef, Object
httpService) {

    LOGGER.info("Modifying service: " +
serviceRef.getBundle().getSymbolicName());

    removedService(serviceRef, httpService);

    addingService(serviceRef);

  }

 

  @Override

  public void removedService(ServiceReference serviceRef, Object
httpService) {

    LOGGER.info("Removing service: " +
serviceRef.getBundle().getSymbolicName());

    serviceRef.getBundle().getBundleContext().ungetService(serviceRef);

    httpService = null;

  }

 

}

 

Welcome to Felix

================

2010-01-21 17:55:36,020-0500 INFO SLF4JBridgeActivator:23 - SLF4J JUL
Bridge - starting

2010-01-21 17:55:36,024-0500 INFO SLF4JBridgeActivator:35 - SLF4J JUL
Bridge - started

2010-01-21 17:55:36,100-0500 INFO RestBundleActivator:23 - Info - Starting
Rest Bundle!!!!!!!!!!!!!

2010-01-21 17:55:36,101-0500 INFO RestMSRCoreServiceTrackerCustomizer:16 -
Adding service: camiant.osgi.msr.core

2010-01-21 17:55:36,185-0500 INFO grizzly:765 - Starting Grizzly Framework
1.9.18-k - Thu Jan 21 17:55:36 EST 2010

2010-01-21 17:55:36,205-0500 INFO RestGrizzlyServiceTrackerCustomizer:21 -
Adding service: com.sun.grizzly.osgi.grizzly-httpservice-bundle

2010-01-21 17:55:36,226-0500 INFO PackagesResourceConfig:107 - Scanning for
root resource and provider classes in the packages:

  camiant.osgi.msr.rest.resource

2010-01-21 17:55:36,250-0500 INFO ScanningResourceConfig:76 - No root
resource classes found.

2010-01-21 17:55:36,250-0500 INFO ScanningResourceConfig:83 - 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.RestGrizzlyServiceTrackerCustomizer.addingService(Rest
GrizzlyServiceTrackerCustomizer.java:38)

            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

->

 

So, I've tried package-based, resource-based, and application methods of
trying to get Jersey to locate my resource file. No luck at all. Am I not
bundling things such that Jersey can see them (i.e. classload issue?).

 

Any help would be greatly appreciated.

 

Thanks,
Dave

 

P.S. here's the ps.

 

-> ps -l

START LEVEL 1

   ID State Level Location

[ 0] [Active ] [ 0] System Bundle

[ 1] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/ant.jar

[ 2] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/asm-all-3.2.jar

[ 3] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/camiant.osgi.msr.core.jar

[ 4] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/camiant.osgi.msr.log.jar

[ 5] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/camiant.osgi.msr.rest.jar

[ 6] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/dom4j-1.6.1.jar

[ 7] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/grizzly-httpservice-bundle-1.9
.18-k.jar

[ 8] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/hibernate.bundle.jar

[ 9] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/http-20070405.jar

[ 10] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/jackson-core-asl-1.1.1.jar

[ 11] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/javax.annotation.jar

[ 12] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/javax.ejb.jar

[ 13] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/javax.servlet.jar

[ 14] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/javax.servlet.jsp.jar

[ 15] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/jaxb-osgi.jar

[ 16] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/jdom.jar

[ 17] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/jersey-bundle-1.1.5.jar

[ 18] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/jettison-1.1.jar

[ 19] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/jsr311-api-1.1.1.jar

[ 20] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/jul-to-slf4j-1.5.8.jar

[ 21] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/mail.jar

[ 22] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.felix.configadmin-1
.2.4.jar

[ 23] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.felix.http.api-2.0.
4.jar

[ 24] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.felix.http.base-2.0
.4.jar

[ 25] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.felix.scr-1.4.0.jar

[ 26] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.felix.shell-1.4.1.j
ar

[ 27] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.felix.shell.tui-1.4
.1.jar

[ 28] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.felix.webconsole-2.
0.2.jar

[ 29] [Resolved ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.log4j.properties.ja
r

[ 30] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.apache.log4j_1.2.15.v20091
0021404.jar

[ 31] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/org.osgi.compendium-4.2.0.jar

[ 32] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/rome-1.0.jar

[ 33] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/slf4j-api-1.5.8.jar

[ 34] [Resolved ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/slf4j-log4j12-1.5.8.jar

[ 35] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/sun.rt.jar

[ 36] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/tools.jar

[ 37] [Active ] [ 1]
file:/home/users/dtkaczyk/ewks1/OSGi_1/bundle/weld-osgi-bundle.jar

->

 

David Tkaczyk

Member of Technical Staff

Office: 508-303-4162

Fax: 508-486-9595

 

 
<http://www.fiercewireless.com/special-reports/camiant-top-wireless-company-
2009-fiercewireless-fierce-15> <image001.gif>

 

 <http://www.camiant.com> www.camiant.com

200 Nickerson Road, Marlborough, MA 01752-4603 USA

 

 <http://twitter.com/camiant> <image002.gif>