Example usage for org.apache.http.nio.protocol BufferingHttpServiceHandler BufferingHttpServiceHandler

List of usage examples for org.apache.http.nio.protocol BufferingHttpServiceHandler BufferingHttpServiceHandler

Introduction

In this page you can find the example usage for org.apache.http.nio.protocol BufferingHttpServiceHandler BufferingHttpServiceHandler.

Prototype

public BufferingHttpServiceHandler(final HttpProcessor httpProcessor, final HttpResponseFactory responseFactory,
            final ConnectionReuseStrategy connStrategy, final HttpParams params) 

Source Link

Usage

From source file:org.hydracache.server.httpd.HttpServiceHandlerFactory.java

public NHttpServiceHandler create() throws Exception {
    BasicHttpProcessor httpproc = new BasicHttpProcessor();

    // Required protocol interceptors
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    httpproc.addInterceptor(new ParameterFetchRequestIntercepter());

    BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc,
            new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), httpParams);

    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();

    reqistry.register("*", requestHandler);

    handler.setHandlerResolver(reqistry);

    handler.setEventListener(protocolEventListener);

    return handler;
}

From source file:marytts.tools.perceptiontest.PerceptionTestHttpServer.java

public void run() {
    logger.info("Starting server.");
    System.out.println("Starting server....");
    //int localPort = MaryProperties.needInteger("socket.port");
    int localPort = serverPort;

    HttpParams params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 seconds)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc,
            new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params);

    // Set up request handlers
    HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    //registry.register("/perceptionTest", new FileDataRequestHandler("perception.html"));
    //registry.register("/process", new FileDataRequestHandler("perception.html"));
    //registry.register("/perceptionTest", new UtterancePlayRequestHandler());

    DataRequestHandler infoRH = new DataRequestHandler(this.testXmlName);
    UserRatingStorer userRatingRH = new UserRatingStorer(this.userRatingsDirectory, infoRH);
    registry.register("/options", infoRH);
    registry.register("/queryStatement", infoRH);
    registry.register("/process", new UtterancePlayRequestHandler(infoRH));
    registry.register("/perceptionTest", new PerceptionRequestHandler(infoRH, userRatingRH));
    registry.register("/userRating", new StoreRatingRequestHandler(infoRH, userRatingRH));
    registry.register("*", new FileDataRequestHandler());

    handler.setHandlerResolver(registry);

    // Provide an event logger
    handler.setEventListener(new EventLogger());

    IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);

    //int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5);
    int numParallelThreads = 5;

    logger.info("Waiting for client to connect on port " + localPort);
    System.out.println("Waiting for client to connect on port " + localPort);

    try {/*from w ww.  j a  v a  2 s .  c o m*/
        ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params);
        ioReactor.listen(new InetSocketAddress(localPort));
        ioReactor.execute(ioEventDispatch);
    } catch (InterruptedIOException ex) {
        logger.info("Interrupted", ex);
        System.out.println("Interrupted" + ex.toString());
    } catch (IOException e) {
        logger.info("Problem with HTTP connection ", e);
        System.out.println("Problem with HTTP connection " + e.toString());
    }
    logger.debug("Shutdown");
    System.out.println("Shutdown");
}

From source file:NioHttpServer.java

public NioHttpServer(int port, // TCP port for the server.
        HttpRequestHandler request_responder, // Scheme level responder for HTTP requests from clients.
        EventListener connection_listener) throws Exception {

    HttpParams params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    BufferingHttpServiceHandler service_handler = new BufferingHttpServiceHandler(httpproc,
            new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params);

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", request_responder);

    service_handler.setHandlerResolver(reqistry);

    service_handler.setEventListener(connection_listener); // Provide a connection listener.

    // Use two worker threads for the IO reactor.
    io_reactor = new DefaultListeningIOReactor(2, params);
    io_event_dispatch = new DefaultServerIOEventDispatch(handler, params);
    this.port = port; // Set the listening TCP port.
}

From source file:marytts.server.http.MaryHttpServer.java

public void run() {
    logger.info("Starting server.");

    int localPort = MaryProperties.needInteger("socket.port");

    HttpParams params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 seconds)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc,
            new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params);

    // Set up request handlers
    HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    registry.register("/process", new SynthesisRequestHandler());
    InfoRequestHandler infoRH = new InfoRequestHandler();
    registry.register("/version", infoRH);
    registry.register("/datatypes", infoRH);
    registry.register("/locales", infoRH);
    registry.register("/voices", infoRH);
    registry.register("/audioformats", infoRH);
    registry.register("/exampletext", infoRH);
    registry.register("/audioeffects", infoRH);
    registry.register("/audioeffect-default-param", infoRH);
    registry.register("/audioeffect-full", infoRH);
    registry.register("/audioeffect-help", infoRH);
    registry.register("/audioeffect-is-hmm-effect", infoRH);
    registry.register("/features", infoRH);
    registry.register("/features-discrete", infoRH);
    registry.register("/vocalizations", infoRH);
    registry.register("/styles", infoRH);
    registry.register("*", new FileRequestHandler());

    handler.setHandlerResolver(registry);

    // Provide an event logger
    handler.setEventListener(new EventLogger());

    IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);

    int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5);

    logger.info("Waiting for client to connect on port " + localPort);

    try {//from  ww  w. j  a v a2  s  .c o m
        ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params);
        ioReactor.listen(new InetSocketAddress(localPort));
        isReady = true;
        ioReactor.execute(ioEventDispatch);
    } catch (InterruptedIOException ex) {
        logger.info("Interrupted", ex);
    } catch (IOException e) {
        logger.info("Problem with HTTP connection", e);
    }
    logger.debug("Shutdown");
}

From source file:org.frameworkset.spi.remote.http.HttpServer.java

protected NHttpServiceHandler createHttpServiceHandler(HttpRequestHandler requestHandler,
        HttpExpectationVerifier expectationVerifier, EventListener eventListener) {

    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(httpproc,
            new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), this.serverParams);

    serviceHandler.setHandlerResolver(new SimpleHttpRequestHandlerResolver(requestHandler));
    serviceHandler.setExpectationVerifier(expectationVerifier);
    serviceHandler.setEventListener(eventListener);

    return serviceHandler;
}