List of usage examples for org.apache.http.nio.protocol BufferingHttpServiceHandler setEventListener
public void setEventListener(final EventListener eventListener)
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: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: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; }
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 {/*www . j av 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: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 {/*w w w. j ava 2 s. co 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"); }