users@jersey.java.net

Re: Jersey HelloWorld sample hangs on Windows

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 27 Mar 2008 13:10:29 +0100

Hi Dave,

Nice timing, i just replied to a comment on my blog:

http://blogs.sun.com/sandoz/entry/jersey_0_6_is_released#comment-1206561409000

from a developer who seems to be experiencing the same issue.


David Bosschaert wrote:
> Hi,
>
> I'm a newbie to Jersey and came across a really weird problem. I run
> the HelloWorld sample using:
>
>> ant run
> ..
> [java] Visit: http://localhost:9998/helloworld
> [java] Hit return to stop...
>
> Now when I try to hit the http://localhost:9998/helloworld with a
> browser (tried FireFox, IE and wget) it just hangs.
> (I'm using Jersey 0.6.1-ea and tried both JDK 1.5 and 1.6)
>
> When I try the exact same on Linux it works fine.
>
> Does anyone know what the problem is? I need to get this working on Windows.
>

I think it is a bug in the Light Weight HTTP server :-( but I don't know
precisely what the issue is, there are others using the LW HTTP on
windows without any issues. Is there any way you could profile where it
is hanging?


An alternative is to use the Grizzly container as follows:

import com.sun.grizzly.http.SelectorThread;
import com.sun.ws.rest.api.container.grizzly.GrizzlyServerFactory;
import java.io.IOException;

public class Main {

     public static void main(String[] args) throws IOException {
         SelectorThread s =
GrizzlyServerFactory.create("http://localhost:9998/");

         System.out.println("Server running");
         System.out.println("Visit: http://localhost:9998/helloworld");
         System.out.println("Hit return to stop...");
         System.in.read();
         System.out.println("Stopping server");
         s.stopEndpoint();
         System.out.println("Server stopped");
     }
}

Note that any path component of the URI passed to the create method will
be ignored (that needs to be fixed). So if you have a resource

   @Path("helloworld") public class Root { ... }

the path to that resource will be http://localhost:9998/helloworld

You need to include the jar "grizzly-http-webserver-1.7.2.jar" in the
classpath.

Another alternative is to use Jetty with Servlet, see here:

https://jersey.dev.java.net/servlets/BrowseList?list=users&by=thread&from=1064653


And of course if you don't need embedded use switch to using a web
container.

Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109