users@jersey.java.net

Re: [Jersey] Re: Cant get Jersey running in embedded Grizzly

From: Alex Sherwin <alex.sherwin_at_acadiasoft.com>
Date: Mon, 18 May 2009 11:48:17 -0400

Hi Paul,

I don't know what it was, still can't figure that out... But depending
on the jar export settings used in Eclipse, it seemed to be causing a
problem.

I can build the classes, then jar them myself (or with ant) and have it
work, but a jar exported with Eclipse is causing the errors.

I didn't try this before because I've never had an issue with Eclipse
creating jars for me before, this was just a simple test server for a
proof of concept to test throughput of Grizzly/Jersey

It does work though... just can't jar it with Eclipse for some reason.



Paul Sandoz wrote:
>
> On May 18, 2009, at 3:52 PM, Alex Sherwin wrote:
>
>> Hi Paul,
>>
>> Sorry for this discrepancy in the log, but I just copied the error
>> from when i moved the HelloWorldResource into the same package as the
>> GrizzlyServer class (in either case, the correct package was being
>> specified in the init params). I just triple checked again to
>> verify, same problem.
>>
>> The problem still persists... works fine when launched by Eclipse,
>> but fails with the following error if run from its own jar (either
>> exporting only my classes into a jar and setting up the classpath
>> with all dependencies, or exporting into a fat jar with all
>> dependencies... same thing).
>>
>
> How are you executing? java - jar ? if so how are you generating the
> executable jar?
>
> I recall that another developer was having issues when using an index
> file, that was generated by ant, for example:
>
> <jar destfile="${jarname}.jar" index="false">
>
> Paul.
>
>
>
>> 2009-05-18 09:47:54,578 INFO [main]
>> [com.asherwin.server.GrizzlyServer:30] Starting Grizzly
>> [http://localhost:8080/]
>> 2009-05-18 09:47:54,734 DEBUG [main]
>> [com.asherwin.server.GrizzlyServer:59] [Queued = 0, Total Queued = 0,
>> Peak Queued = 0, Open Connections = 0, Total Connections = 0, Max
>> Queued = 4096, Queue Size Bytes = 4096]
>> 2009-05-18 09:47:56,734 DEBUG [main]
>> [com.asherwin.server.GrizzlyServer:59] [Queued = 0, Total Queued = 0,
>> Peak Queued = 0, Open Connections = 0, Total Connections = 0, Max
>> Queued = 4096, Queue Size Bytes = 4096]
>> 2009-05-18 09:47:58,734 DEBUG [main]
>> [com.asherwin.server.GrizzlyServer:59] [Queued = 0, Total Queued = 0,
>> Peak Queued = 0, Open Connections = 0, Total Connections = 0, Max
>> Queued = 4096, Queue Size Bytes = 4096]
>> May 18, 2009 9:48:00 AM
>> com.sun.jersey.api.core.PackagesResourceConfig init
>> INFO: Scanning for root resource and provider classes in the packages:
>> com.asherwin.resource
>> 2009-05-18 09:48:00,734 DEBUG [main]
>> [com.asherwin.server.GrizzlyServer:59] [Queued = 0, Total Queued = 0,
>> Peak Queued = 0, Open Connections = 1, Total Connections = 1, Max
>> Queued = 4096, Queue Size Bytes = 4096]
>> 2009-05-18 09:48:02,734 DEBUG [main]
>> [com.asherwin.server.GrizzlyServer:59] [Queued = 0, Total Queued = 0,
>> Peak Queued = 0, Open Connections = 1, Total Connections = 1, Max
>> Queued = 4096, Queue Size Bytes = 4096]
>> May 18, 2009 9:48:03 AM
>> com.sun.jersey.server.impl.application.WebApplicationImpl
>> processRootResources
>> SEVERE: The ResourceConfig instance does not contain any root
>> resource classes.
>> May 18, 2009 9:48:03 AM com.sun.grizzly.http.servlet.ServletAdapter
>> service
>> SEVERE: service exception:
>> com.sun.jersey.api.container.ContainerException: The ResourceConfig
>> instance does not contain any root resource classes.
>>
>> at
>> com.sun.jersey.server.impl.application.WebApplicationImpl.processRootResources(WebApplicationImpl.java:718)
>>
>> at
>> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:590)
>>
>> at
>> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:383)
>>
>> at
>> com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:377)
>>
>> at
>> com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:242)
>>
>> at
>> com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:449)
>>
>> at
>> com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:169)
>>
>> at
>> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:281)
>>
>> at
>> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:442)
>>
>> at javax.servlet.GenericServlet.init(GenericServlet.java:241)
>> at
>> com.sun.grizzly.http.servlet.ServletAdapter.loadServlet(ServletAdapter.java:374)
>>
>> at
>> com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:312)
>>
>> at
>> com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:165)
>>
>> at
>> com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:746)
>> at
>> com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:655)
>> at
>> com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:905)
>> at
>> com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:161)
>>
>> at
>> com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:136)
>>
>> at
>> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
>>
>> at
>> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
>>
>> at
>> com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
>>
>> at
>> com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
>>
>> at
>> com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
>>
>> at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
>> at
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>>
>> at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>>
>> at java.lang.Thread.run(Thread.java:619)
>> 2009-05-18 09:48:04,734 DEBUG [main]
>> [com.asherwin.server.GrizzlyServer:59] [Queued = 0, Total Queued = 0,
>> Peak Queued = 0, Open Connections = 0, Total Connections = 1, Max
>> Queued = 4096, Queue Size Bytes = 4096]
>>
>>
>>
>> Paul Sandoz wrote:
>>> Hi,
>>>
>>> The log states that the package "com.asherwin.server" is scanned:
>>>
>>> May 16, 2009 8:57:35 AM
>>> com.sun.jersey.api.core.PackagesResourceConfig init
>>> INFO: Scanning for root resource and provider classes in the packages:
>>> com.asherwin.server
>>>
>>>
>>> But in your code you make reference to the package
>>> "com.asherwin.resource":
>>>
>>> GrizzlyWebServer ws = new GrizzlyWebServer(PORT);
>>> ServletAdapter jerseyAdapter = new ServletAdapter();
>>> jerseyAdapter.setServletInstance(new
>>> com.sun.jersey.spi.container.servlet.ServletContainer());
>>>
>>> jerseyAdapter.addInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES,
>>>
>>> "com.asherwin.resource");
>>>
>>>
>>> So your code may be inconsistent with what you are running.
>>>
>>> Paul.
>>>
>>> On May 16, 2009, at 2:58 PM, Alex Sherwin wrote:
>>>
>>>> Replying to my own thread... Forgot to attach the stacktrace
>>>>
>>>> May 16, 2009 8:57:35 AM
>>>> com.sun.jersey.api.core.PackagesResourceConfig init
>>>> INFO: Scanning for root resource and provider classes in the packages:
>>>> com.asherwin.server
>>>> May 16, 2009 8:57:36 AM
>>>> com.sun.jersey.server.impl.application.WebApplicationImpl
>>>> processRootResources
>>>> SEVERE: The ResourceConfig instance does not contain any root
>>>> resource classes.
>>>> May 16, 2009 8:57:36 AM com.sun.grizzly.http.servlet.ServletAdapter
>>>> service
>>>> SEVERE: service exception:
>>>> com.sun.jersey.api.container.ContainerException: The ResourceConfig
>>>> instance does not contain any root resource classes.
>>>> at
>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.processRootResources(WebApplicationImpl.java:718)
>>>>
>>>> at
>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:590)
>>>>
>>>> at
>>>> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:383)
>>>>
>>>> at
>>>> com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:377)
>>>>
>>>> at
>>>> com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:242)
>>>>
>>>> at
>>>> com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:449)
>>>>
>>>> at
>>>> com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:169)
>>>>
>>>> at
>>>> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:281)
>>>>
>>>> at
>>>> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:442)
>>>>
>>>> at javax.servlet.GenericServlet.init(GenericServlet.java:241)
>>>> at
>>>> com.sun.grizzly.http.servlet.ServletAdapter.loadServlet(ServletAdapter.java:374)
>>>>
>>>> at
>>>> com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:312)
>>>>
>>>> at
>>>> com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:165)
>>>>
>>>> at
>>>> com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:746)
>>>>
>>>> at
>>>> com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:655)
>>>> at
>>>> com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:905)
>>>> at
>>>> com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:161)
>>>>
>>>> at
>>>> com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:136)
>>>>
>>>> at
>>>> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
>>>>
>>>> at
>>>> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
>>>>
>>>> at
>>>> com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
>>>>
>>>> at
>>>> com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
>>>>
>>>> at
>>>> com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
>>>>
>>>> at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
>>>> at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
>>>>
>>>> at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
>>>>
>>>> at java.lang.Thread.run(Thread.java:613)
>>>>
>>>>
>>>> On Sat, May 16, 2009 at 8:21 AM, Alex Sherwin
>>>> <alex.sherwin_at_gmail.com> wrote:
>>>>> I've got:
>>>>>
>>>>> jersey bundle 1.0.3
>>>>> grizzly-servlet-webserver 1.9.15a
>>>>>
>>>>> (also, activation, commons lang, commons logging, jaxb api, jaxb
>>>>> impl,
>>>>> jsr311 api)
>>>>>
>>>>> If I follow the straight forward approach from the HelloWorld
>>>>> example,
>>>>> everything works fine when running inside Eclipse (JDK 1.5.0_16).
>>>>> However, once i export a jar and run it from a command line
>>>>> (either on
>>>>> OS X JDK 1.5.0_16 or OpenSolaris JDK 1.6.0_06) the Grizzly web server
>>>>> starts up, but once I make a web request and Jersey attempts to
>>>>> initialize, it is failing to locate my HelloWorldResource class
>>>>> (again, this works when run from inside Eclipse).
>>>>>
>>>>> Everything (meaning both of my classes) are in jar, classpath is all
>>>>> setup, etc etc...
>>>>>
>>>>> There is no special run configuration setup in eclipse, just a basic
>>>>> Run As > Java Application invocation, which is simply running my main
>>>>> method with the classpath setup with my libs.
>>>>>
>>>>> What could possibly be different between running from within Eclipse
>>>>> and the command line that would only change the way that Jersey is
>>>>> attempting/failing to locate my resource classes? Here are my two
>>>>> test classes...
>>>>>
>>>>> Note that I've tried configuring the grizzly web server two different
>>>>> ways labeled with "Method 1" and "Method 2", both work from within
>>>>> Eclipse, both fail the same way when run from the command line
>>>>> (Grizzly starts up, but Jersey fails to find Resource classes when a
>>>>> web request is made)
>>>>>
>>>>> After generating my jar (jersey-grizzly.jar), it is run like this:
>>>>>
>>>>> java -cp
>>>>> .:activation-1.1.1.jar:asm-3.1.jar:commons-lang-2.4.jar:commons-logging-1.1.1.jar:grizzly-servlet-webserver-1.9.15a.jar:jaxb-api-2.1.jar:jaxb-impl-2.1.11.jar:jersey-bundle-1.0.3.jar:jersey-grizzly.jar:jsr311-api-1.0.jar:junit-4.6.jar:log4j-1.2.15.jar
>>>>>
>>>>> com.asherwin.server.GrizzlyServer
>>>>>
>>>>> com.asherwin.server.GrizzlyServer.java
>>>>> ==============================
>>>>>
>>>>> package com.asherwin.server;
>>>>>
>>>>> import java.io.IOException;
>>>>> import java.util.concurrent.TimeUnit;
>>>>>
>>>>> import org.apache.log4j.Logger;
>>>>>
>>>>> import com.sun.grizzly.http.StatsThreadPool;
>>>>> import com.sun.grizzly.http.embed.GrizzlyWebServer;
>>>>> import com.sun.grizzly.http.servlet.ServletAdapter;
>>>>> import com.sun.jersey.api.core.PackagesResourceConfig;
>>>>>
>>>>> public class GrizzlyServer {
>>>>>
>>>>> private static final Logger LOG =
>>>>> Logger.getLogger(GrizzlyServer.class);
>>>>>
>>>>> private static final String HOST = "localhost";
>>>>> private static final int PORT = 8080;
>>>>>
>>>>> private static final MyStatistics threadPool = new MyStatistics(10,
>>>>> 100, Integer.MAX_VALUE, 60, TimeUnit.SECONDS);
>>>>>
>>>>> public GrizzlyServer() {
>>>>>
>>>>> }
>>>>>
>>>>> public static void main(final String[] args) {
>>>>>
>>>>> final String baseUri = new
>>>>> StringBuilder().append("http://").append(HOST).append(":").append(PORT).append("/").toString();
>>>>>
>>>>>
>>>>> LOG.info("Starting Grizzly [" + baseUri + "]");
>>>>>
>>>>> try {
>>>>>
>>>>> // Method 1
>>>>> // final Map<String, String> initParams = new HashMap<String,
>>>>> String>();
>>>>> // initParams.put(PackagesResourceConfig.PROPERTY_PACKAGES,
>>>>> "com.asherwin.resource");
>>>>> // final SelectorThread threadSelector =
>>>>> GrizzlyWebContainerFactory.create(baseUri, initParams);
>>>>> // threadSelector.setSelectorReadThreadsCount(5);
>>>>> // threadSelector.setThreadPool(threadPool);
>>>>> // threadSelector.enableMonitoring();
>>>>>
>>>>> // Method 2
>>>>> GrizzlyWebServer ws = new GrizzlyWebServer(PORT);
>>>>> ServletAdapter jerseyAdapter = new ServletAdapter();
>>>>> jerseyAdapter.setServletInstance(new
>>>>> com.sun.jersey.spi.container.servlet.ServletContainer());
>>>>>
>>>>> jerseyAdapter.addInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES,
>>>>>
>>>>> "com.asherwin.resource");
>>>>> ws.addGrizzlyAdapter(jerseyAdapter, new String[] { "/" });
>>>>> ws.getSelectorThread().enableMonitoring();
>>>>> ws.getSelectorThread().setThreadPool(threadPool);
>>>>> ws.start();
>>>>>
>>>>> // System.in.read();
>>>>>
>>>>> boolean done = false;
>>>>> while (!done) {
>>>>>
>>>>> // LOG.debug("activeCount [" + threadPool.getActiveCount() +
>>>>> "], poolSize [" + threadPool.getPoolSize() + //
>>>>> // "], largestPoolSize [" // + threadPool.getLargestPoolSize()
>>>>> + "], taskCount [" + threadPool.getTaskCount() +
>>>>> // "], completedTaskCount [" // +
>>>>> threadPool.getCompletedTaskCount() + "]");
>>>>>
>>>>> LOG.debug(threadPool.getStats());
>>>>>
>>>>> Thread.sleep(2000);
>>>>> }
>>>>>
>>>>> // Method 2
>>>>> ws.stop();
>>>>>
>>>>> // Method 1
>>>>> // threadSelector.stopEndpoint();
>>>>> } catch (IOException e) {
>>>>> LOG.error("Caught IOException [" + e.getMessage() + "]", e);
>>>>> } catch (InterruptedException e) {
>>>>> LOG.error("Caught InterruptedException [" + e.getMessage() +
>>>>> "]", e);
>>>>> }
>>>>>
>>>>> System.exit(0);
>>>>>
>>>>> }
>>>>>
>>>>> public static class MyStatistics extends StatsThreadPool {
>>>>>
>>>>> public MyStatistics(int corePoolSize, int maximumPoolSize, int
>>>>> maxTasksCount, long keepAliveTime, TimeUnit unit) {
>>>>> super(corePoolSize, maximumPoolSize, maxTasksCount,
>>>>> keepAliveTime, unit);
>>>>> }
>>>>>
>>>>> public String getStats() {
>>>>> final StringBuilder sb = new StringBuilder();
>>>>>
>>>>> sb.append("[Queued = ");
>>>>> sb.append(getStatistic().getCountQueued());
>>>>>
>>>>> sb.append(", Total Queued = ");
>>>>> sb.append(getStatistic().getCountTotalQueued());
>>>>>
>>>>> sb.append(", Peak Queued = ");
>>>>> sb.append(getStatistic().getPeakQueued());
>>>>>
>>>>> sb.append(", Open Connections = ");
>>>>> sb.append(getStatistic().getOpenConnectionsCount());
>>>>>
>>>>> sb.append(", Total Connections = ");
>>>>> sb.append(getStatistic().getCountTotalConnections());
>>>>>
>>>>> sb.append(", Max Queued = ");
>>>>> sb.append(getStatistic().getMaxQueued());
>>>>>
>>>>> sb.append(", Queue Size Bytes = ");
>>>>> sb.append(getStatistic().getQueueSizeInBytes());
>>>>>
>>>>> sb.append("]");
>>>>> return sb.toString();
>>>>> }
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>> com.asherwin.resource.HelloWorldResource.class
>>>>> =======================================
>>>>>
>>>>> package com.asherwin.resource;
>>>>>
>>>>> import javax.ws.rs.GET;
>>>>> import javax.ws.rs.Path;
>>>>> import javax.ws.rs.core.Response;
>>>>>
>>>>> @Path("/helloworld")
>>>>> public class HelloWorldResource {
>>>>>
>>>>> public HelloWorldResource() {
>>>>>
>>>>> }
>>>>>
>>>>> @GET
>>>>> public Response helloWorld() {
>>>>> return Response.ok("Hello World").build();
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> --
>>>>> Alexander Sherwin
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Alexander Sherwin
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>>
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>
>