Ejemplo n.º 1
0
  /**
   * @param docRoot the document root, can be <code>null</code> when no static pages are needed
   * @param host the network port to which this listener will bind
   * @param range port range to attempt to bind to
   * @return a <code>HttpServer</code> configured to listen to requests on <code>host</code>:<code>
   *     [port-range]</code>, using the specified <code>docRoot</code> as the server's document root
   */
  public static HttpServer createSimpleServer(
      final String docRoot, final String host, final PortRange range) {

    final HttpServer server = new HttpServer();
    final ServerConfiguration config = server.getServerConfiguration();
    if (docRoot != null) {
      config.addHttpHandler(new StaticHttpHandler(docRoot), "/");
    }
    final NetworkListener listener = new NetworkListener("grizzly", host, range);
    server.addListener(listener);
    return server;
  }