Exemplo 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;
  }
Exemplo n.º 2
0
  private HttpServer createHttpServer() {
    final HttpServer server = new HttpServer();

    final int requestSize = (int) currentConfig.getMaxRequestSize();
    final ServerConfiguration serverConfig = server.getServerConfiguration();
    serverConfig.setMaxBufferedPostSize(requestSize);
    serverConfig.setMaxFormPostSize(requestSize);
    serverConfig.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);

    if (keepStats()) {
      setHttpStatsProbe(server);
    }

    // Configure the network listener
    final NetworkListener listener =
        new NetworkListener(
            "Rest2LDAP", NetworkListener.DEFAULT_NETWORK_HOST, initConfig.getListenPort());
    server.addListener(listener);

    // Configure the network transport
    final TCPNIOTransport transport = listener.getTransport();
    transport.setReuseAddress(currentConfig.isAllowTCPReuseAddress());
    transport.setKeepAlive(currentConfig.isUseTCPKeepAlive());
    transport.setTcpNoDelay(currentConfig.isUseTCPNoDelay());
    transport.setWriteTimeout(currentConfig.getMaxBlockedWriteTimeLimit(), TimeUnit.MILLISECONDS);

    final int bufferSize = (int) currentConfig.getBufferSize();
    transport.setReadBufferSize(bufferSize);
    transport.setWriteBufferSize(bufferSize);
    transport.setIOStrategy(SameThreadIOStrategy.getInstance());

    final int numRequestHandlers =
        getNumRequestHandlers(currentConfig.getNumRequestHandlers(), friendlyName);
    transport.setSelectorRunnersCount(numRequestHandlers);
    transport.setServerConnectionBackLog(currentConfig.getAcceptBacklog());

    // Configure SSL
    if (sslEngineConfigurator != null) {
      listener.setSecure(true);
      listener.setSSLEngineConfig(sslEngineConfigurator);
    }

    return server;
  }