users@jersey.java.net

Sun's lightweight built in HttpServer hangs on windows

From: William Brogden <wbrogden_at_bga.com>
Date: Sun, 30 Mar 2008 15:07:38 -0500

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