Esempio n. 1
0
	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;
	}
Esempio n. 2
0
  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 {
      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");
  }