users@jersey.java.net

Re: Sun's lightweight built in HttpServer hangs on windows

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 31 Mar 2008 10:49:32 +0200

Hi Bill,

I just talked to another developer who had similar issues and he jogged
my memory. We managed to find out what was causing the problem by
replacing the:

   System.in.read();

with a:

   Thread.sleep(...);

!!!

It seems on Windows the "System.in.read()" on the main thread blocks
other threads of the LW HTTP server. (However, if run your server-side
code in debug mode it does not block.)

Perhaps executing the "server.start()" or the "System.in.read()" in a
new thread might resolve it. [BTW as you may have guessed i don't have a
windows box]

Paul.

William Brogden wrote:
>
> This is similar to David Bosschaert's problem - I'm on
> Windows XP with Java 1.6 and Jersey 0.6 & NetBeans.
>
> I tried using the lightweight server following the HelloWorld
> example for launching using the following class.
> ---------------------
> package com.wbrogden.phonetic;
>
> import com.sun.net.httpserver.* ;
> import java.net.* ;
> import com.sun.ws.rest.api.container.* ;
> import java.io.IOException ;
>
> public class LwRestful {
>
> public static void main(String[] args) throws IOException {
> System.out.println("try to start lightweight server");
> // Create the HttpHandler
> // Pass in the Jersey resource class
> HttpHandler handler = ContainerFactory.createContainer(
> HttpHandler.class,
> LookupResource.class);
>
> // Create the HTTP server using the HttpHandler
> HttpServer server = HttpServer.create(
> new InetSocketAddress(9998),
> 0); // default backlog
> server.createContext("/", handler);
> server.setExecutor(null); // default Executor
> server.start();
>
> System.out.println("Server running");
> System.out.println("Visit:
> http://localhost:9998/lookup/domain/word");
> System.out.println("Hit return to stop...");
> System.in.read();
> System.out.println("Stopping server");
> server.stop(0);
> System.out.println("Server stopped");
> }
> }
> ----------------
> With this running I can use a browser to GET like this:
>
> http://localhost:9998/lookup/Names/Rebecca
>
> Nothing happens, BUT when I kill the server, following the
> "Server stopped" I get output from my LookupResource class
> getHtml method, which shows that the GET was correctly interpreted
> and that a String was created and returned. The browser reports
> that the connection was closed - it does not appear to have gotten
> any output.
>
> I am guessing that the HttpHandler is not correctly handling
> the response.
>
> Bill
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

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