Example usage for org.apache.http.protocol ResponseServer ResponseServer

List of usage examples for org.apache.http.protocol ResponseServer ResponseServer

Introduction

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

Prototype

public ResponseServer() 

Source Link

Usage

From source file:com.yanzhenjie.andserver.CoreThread.java

/**
 * Create HttpProcessor.//  www .j  a va  2 s.  c o m
 *
 * @return {@link HttpProcessor}.
 */
private HttpProcessor createHttpProcessor() {
    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseProcessCookies());
    return httpProcessor;
}

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:com.bluetooth.activities.WiFiControl.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wifi_control);

    SERVERIP = getLocalIpAddress();/*from   ww  w .  j a  va 2  s  . c  om*/

    httpContext = new BasicHttpContext();

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

    httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory());

    registry = new HttpRequestHandlerRegistry();
    registry.register(ALL_PATTERN, new RequestHandler());

    httpService.setHandlerResolver(registry);

    tvData = (LogView) findViewById(R.id.tvData);
    tvIP = (TextView) findViewById(R.id.tvIP);
    bToggle = (Button) findViewById(R.id.bToggle);
    log = "";
}

From source file:org.cytoscape.app.internal.net.server.CyHttpdFactoryImpl.java

public CyHttpdImpl(final ServerSocketFactory serverSocketFactory) {
    if (serverSocketFactory == null)
        throw new IllegalArgumentException("serverSocketFactory == null");
    this.serverSocketFactory = serverSocketFactory;

    // Setup params

    params = (new SyncBasicHttpParams()).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");

    // Setup service

    final HttpProcessor proc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { new ResponseDate(),
            new ResponseServer(), new ResponseContent(), new ResponseConnControl() });

    final HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    registry.register("*", new RequestHandlerDispatcher());

    service = new HttpService(proc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(),
            registry, params);//from  w w  w.  ja v  a  2s.  c om
}

From source file:org.apache.axis2.transport.http.server.DefaultHttpConnectionManager.java

public void process(final AxisHttpConnection conn) {
    if (conn == null) {
        throw new IllegalArgumentException("HTTP connection may not be null");
    }/*from   w  w w .  ja  va 2s . co m*/
    // Evict destroyed processors
    cleanup();

    // Assemble new Axis HTTP service
    HttpProcessor httpProcessor;
    ConnectionReuseStrategy connStrategy;
    HttpResponseFactory responseFactory;

    if (httpFactory != null) {
        httpProcessor = httpFactory.newHttpProcessor();
        connStrategy = httpFactory.newConnStrategy();
        responseFactory = httpFactory.newResponseFactory();
    } else {
        BasicHttpProcessor p = new BasicHttpProcessor();
        p.addInterceptor(new RequestSessionCookie());
        p.addInterceptor(new ResponseDate());
        p.addInterceptor(new ResponseServer());
        p.addInterceptor(new ResponseContent());
        p.addInterceptor(new ResponseConnControl());
        p.addInterceptor(new ResponseSessionCookie());
        httpProcessor = p;
        connStrategy = new DefaultConnectionReuseStrategy();
        responseFactory = new DefaultHttpResponseFactory();
    }

    AxisHttpService httpService = new AxisHttpService(httpProcessor, connStrategy, responseFactory,
            this.configurationContext, this.workerfactory.newWorker());
    httpService.setParams(this.params);

    // Create I/O processor to execute HTTP service
    IOProcessorCallback callback = new IOProcessorCallback() {

        public void completed(final IOProcessor processor) {
            removeProcessor(processor);
            if (LOG.isDebugEnabled()) {
                LOG.debug(processor + " terminated");
            }
        }

    };
    IOProcessor processor = new HttpServiceProcessor(httpService, conn, callback);

    addProcessor(processor);
    this.executor.execute(processor);
}

From source file:com.facebook.stetho.server.LocalSocketHttpServer.java

private HttpService createService(HttpParams params) {
    HttpRequestHandlerRegistry registry = mRegistryInitializer.getRegistry();

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

    HttpService service = new HttpService(httpproc, new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory());
    service.setParams(params);//w  w  w .j  a v a 2 s  . c  o  m
    service.setHandlerResolver(registry);

    return service;
}

From source file:org.apache.camel.itest.http.HttpTestServer.java

/**
 * Obtains an HTTP protocol processor with default interceptors.
 *
 * @return  a protocol processor for server-side use
 *///from ww w  .j ava2  s. co  m
protected HttpProcessor newProcessor() {
    return new ImmutableHttpProcessor(new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(),
            new ResponseContent(), new ResponseConnControl() });
}

From source file:com.aptana.webserver.internal.core.builtin.LocalWebServer.java

private void runServer(InetSocketAddress socketAddress, HttpAsyncRequestHandler httpRequestHandler) {
    HttpParams params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIMEOUT)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, SOCKET_BUFFER_SIZE)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER,
                    "HttpComponents/" + EclipseUtil.getPluginVersion("org.apache.httpcomponents.httpcore")); //$NON-NLS-1$ //$NON-NLS-2$

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

    HttpAsyncRequestHandlerRegistry handlerRegistry = new HttpAsyncRequestHandlerRegistry();
    handlerRegistry.register("*", httpRequestHandler); //$NON-NLS-1$

    HttpAsyncService serviceHandler = new HttpAsyncService(httpProcessor, new DefaultConnectionReuseStrategy(),
            handlerRegistry, params);//  w  ww  .  j ava2 s  .  c  o  m
    // serviceHandler.setEventListener(new LocalWebServerLogger());

    IOReactorConfig config = new IOReactorConfig();
    config.setIoThreadCount(WORKER_COUNT);
    config.setConnectTimeout(SOCKET_TIMEOUT);
    config.setTcpNoDelay(true);
    config.setSoKeepalive(true);

    DefaultHttpServerIODispatch eventDispatch = new DefaultHttpServerIODispatch(serviceHandler, params);
    try {
        reactor = new DefaultListeningIOReactor(config);
        reactor.listen(socketAddress);
        reactor.execute(eventDispatch);
    } catch (InterruptedIOException e) {
        return;
    } catch (IOReactorException e) {
        IdeLog.logWarning(WebServerCorePlugin.getDefault(), e);
    } catch (IOException e) {
        IdeLog.logError(WebServerCorePlugin.getDefault(), e);
    }
}

From source file:com.eislab.af.translator.spokes.HttpServer_spoke.java

public HttpServer_spoke(String ipaddress, String path) throws IOException, InterruptedException {

    address = ipaddress;/*  w  w w.  j a  v  a  2s. c  o m*/
    // HTTP parameters for the server
    HttpParams params = new SyncBasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIMEOUT)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, SOCKET_BUFFER_SIZE)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, SERVER_NAME);

    // Create HTTP protocol processing chain
    // Use standard server-side protocol interceptors
    HttpRequestInterceptor[] requestInterceptors = new HttpRequestInterceptor[] { new RequestAcceptEncoding() };
    HttpResponseInterceptor[] responseInterceptors = new HttpResponseInterceptor[] { new ResponseAllowCORS(),
            new ResponseContentEncoding(), new ResponseDate(), new ResponseServer(), new ResponseContent(),
            new ResponseConnControl() };
    HttpProcessor httpProcessor = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors);

    // Create request handler registry
    HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();

    // register the handler that will reply to the proxy requests

    registry.register(path, new RequestHandler("", true));

    // Create server-side HTTP protocol handler
    HttpAsyncService protocolHandler = new HttpAsyncService(httpProcessor, new DefaultConnectionReuseStrategy(),
            registry, params);

    // Create HTTP connection factory
    NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory = new DefaultNHttpServerConnectionFactory(
            params);

    // Create server-side I/O event dispatch
    final IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory);

    try {
        // Create server-side I/O reactor
        ioReactor = new DefaultListeningIOReactor();
        // Listen of the given port

        InetSocketAddress socketAddress = new InetSocketAddress(ipaddress, 0);
        ListenerEndpoint endpoint1 = ioReactor.listen(socketAddress);

        // create the listener thread
        Thread listener = new Thread("Http listener") {

            @Override
            public void run() {
                try {
                    ioReactor.execute(ioEventDispatch);

                } catch (IOException e) {
                    //                     LOGGER.severe("I/O Exception: " + e.getMessage());
                }

            }
        };

        listener.setDaemon(false);
        listener.start();

        endpoint1.waitFor();

        if (address.contains(":")) {
            if (!address.startsWith("[")) {
                address = "[" + address + "]";
            }
        }

        address = address + ":" + Integer.toString(((InetSocketAddress) endpoint1.getAddress()).getPort())
                + "/";
        System.out.println(address);

    } catch (IOException e) {
        //            LOGGER.severe("I/O error: " + e.getMessage());
    }
}

From source file:org.apache.http.localserver.LocalTestServer.java

/**
 * Obtains an HTTP protocol processor with default interceptors.
 *
 * @return  a protocol processor for server-side use
 *//*  w w w  .j av a2  s . c  o  m*/
protected BasicHttpProcessor newProcessor() {

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

    return httpproc;
}