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:org.opcfoundation.ua.transport.https.HttpsServer.java

public HttpsServer(Application application) throws ServiceResultException {
    super(CloseableObjectState.Closed, CloseableObjectState.Closed);

    this.application = application;
    this.ioConfig = new IOReactorConfig();
    this.securityPolicies = application.getHttpsSettings().getHttpsSecurityPolicies();

    // Disable Nagle's
    ioConfig.setTcpNoDelay(false);/* w  w w.j  a  va 2 s  . co  m*/

    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
            // Use standard server-side protocol interceptors
            new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() });
    // Create request handler registry
    registry = new RequestResolver();
    // Register the default handler for all URIs
    final Map<NHttpServerConnection, HttpsServerConnection> connMap = Collections
            .synchronizedMap(new HashMap<NHttpServerConnection, HttpsServerConnection>());
    // Create connection re-use strategy
    connectionReuseStrategy = new DefaultConnectionReuseStrategy();

    // Create server-side HTTP protocol handler
    protocolHandler = new HttpAsyncService(httpproc, connectionReuseStrategy, registry, getHttpParams()) {

        @Override
        public void connected(final NHttpServerConnection conn) {
            NHttpConnectionBase conn2 = (NHttpConnectionBase) conn;
            log.info("connected: {} {}<-> {} context={} socketTimeout={}",
                    HttpsServer.this.getBoundSocketAddresses(), conn2.getLocalAddress(),
                    conn2.getRemoteAddress(), conn2.getContext(), conn2.getSocketTimeout());
            HttpsServerConnection httpsConnection = new HttpsServerConnection(HttpsServer.this, conn);
            connMap.put(conn, httpsConnection);
            connections.addConnection(httpsConnection);
            super.connected(conn);
        }

        @Override
        public void closed(final NHttpServerConnection conn) {
            NHttpConnectionBase conn2 = (NHttpConnectionBase) conn;
            log.info("closed: {} {}<-> {} context={} socketTimeout={}",
                    HttpsServer.this.getBoundSocketAddresses(), conn2.getLocalAddress(),
                    conn2.getRemoteAddress(), conn2.getContext(), conn2.getSocketTimeout());
            HttpsServerConnection conn3 = connMap.remove(conn);
            connections.removeConnection(conn3);
            super.closed(conn);
        }

    };

    // Create a service server for connections that query endpoints (url = "")
    discoveryServer = new Server(application);
    discoveryServer.setEndpointBindings(endpointBindings);
    EndpointBinding discoveryBinding = new EndpointBinding(this, discoveryEndpoint, discoveryServer);
    discoveryHandler = new HttpsServerEndpointHandler(discoveryBinding);
}

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 .ja v  a 2  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.apache.commons.vfs2.util.NHttpServer.java

public void runBlock(final int port, final File docRoot) throws KeyStoreException, NoSuchAlgorithmException,
        CertificateException, IOException, UnrecoverableKeyException, KeyManagementException {
    if (docRoot == null) {
        throw new IllegalArgumentException("No doc root specified.");
    }//from   w  w  w .  j  a va  2 s. c om
    // HTTP parameters for the server
    final HttpParams params = new SyncBasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpTest/1.1");
    // Create HTTP protocol processing chain
    final HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
            // Use standard server-side protocol interceptors
            new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() });
    // Create request handler registry
    final HttpAsyncRequestHandlerRegistry reqistry = new HttpAsyncRequestHandlerRegistry();
    // Register the default handler for all URIs
    reqistry.register("*", new HttpFileHandler(docRoot));
    // Create server-side HTTP protocol handler
    final HttpAsyncService protocolHandler = new HttpAsyncService(httpproc,
            new DefaultConnectionReuseStrategy(), reqistry, params) {

        @Override
        public void closed(final NHttpServerConnection conn) {
            NHttpServer.debug(conn + ": connection closed");
            super.closed(conn);
        }

        @Override
        public void connected(final NHttpServerConnection conn) {
            NHttpServer.debug(conn + ": connection open");
            super.connected(conn);
        }

    };
    // Create HTTP connection factory
    NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory;
    if (port == 8443) {
        // Initialize SSL context
        final ClassLoader cl = NHttpServer.class.getClassLoader();
        final URL url = cl.getResource("my.keystore");
        if (url == null) {
            NHttpServer.debug("Keystore not found");
            System.exit(1);
        }
        final KeyStore keystore = KeyStore.getInstance("jks");
        keystore.load(url.openStream(), "secret".toCharArray());
        final KeyManagerFactory kmfactory = KeyManagerFactory
                .getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmfactory.init(keystore, "secret".toCharArray());
        final KeyManager[] keymanagers = kmfactory.getKeyManagers();
        final SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(keymanagers, null, null);
        connFactory = new SSLNHttpServerConnectionFactory(sslcontext, null, params);
    } else {
        connFactory = new DefaultNHttpServerConnectionFactory(params);
    }
    // Create server-side I/O event dispatch
    final IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory);
    // Create server-side I/O reactor
    this.ioReactor = new DefaultListeningIOReactor();
    try {
        // Listen of the given port
        this.ioReactor.listen(new InetSocketAddress(port));
        // Ready to go!
        this.ioReactor.execute(ioEventDispatch);
    } catch (final InterruptedIOException ex) {
        System.err.println("Interrupted");
    } catch (final IOException e) {
        System.err.println("I/O error: " + e.getMessage());
    }
    NHttpServer.debug("Shutdown");
}

From source file:net.facework.core.http.TinyHttpServer.java

@Override
public void onCreate() {

    super.onCreate();

    mContext = getApplicationContext();// ww  w.  j  a v  a2 s.c o m
    mRegistry = new MHttpRequestHandlerRegistry();
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    mParams = new BasicHttpParams();
    mParams.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, "MajorKernelPanic HTTP Server");

    // Set up the HTTP protocol processor
    mHttpProcessor = new BasicHttpProcessor();
    mHttpProcessor.addInterceptor(new ResponseDate());
    mHttpProcessor.addInterceptor(new ResponseServer());
    mHttpProcessor.addInterceptor(new ResponseContent());
    mHttpProcessor.addInterceptor(new ResponseConnControl());

    // Will be used in the "Last-Modifed" entity-header field
    try {
        String packageName = mContext.getPackageName();
        mLastModified = new Date(mContext.getPackageManager().getPackageInfo(packageName, 0).lastUpdateTime);
    } catch (NameNotFoundException e) {
        mLastModified = new Date(0);
    }

    // Let's restore the state of the service 
    mHttpPort = Integer.parseInt(mSharedPreferences.getString(mHttpPortKey, String.valueOf(mHttpPort)));
    mHttpsPort = Integer.parseInt(mSharedPreferences.getString(mHttpsPortKey, String.valueOf(mHttpsPort)));
    mHttpEnabled = mSharedPreferences.getBoolean(mHttpEnabledKey, mHttpEnabled);
    mHttpsEnabled = mSharedPreferences.getBoolean(mHttpsEnabledKey, mHttpsEnabled);

    // If the configuration is modified, the server will adjust
    mSharedPreferences.registerOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener);

    // Loads plugins available in the package net.majorkernelpanic.http
    for (int i = 0; i < MODULES.length; i++) {
        try {
            Class<?> pluginClass = Class
                    .forName(TinyHttpServer.class.getPackage().getName() + "." + MODULES[i]);
            Constructor<?> pluginConstructor = pluginClass.getConstructor(new Class[] { TinyHttpServer.class });
            addRequestHandler((String) pluginClass.getField("PATTERN").get(null),
                    (HttpRequestHandler) pluginConstructor.newInstance(this));
        } catch (ClassNotFoundException ignore) {
            // Module disabled
        } catch (Exception e) {
            Log.e(TAG, "Bad module: " + MODULES[i]);
            e.printStackTrace();
        }
    }

    start();

}

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

public HttpProcessor newHttpProcessor() {
    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new RequestSessionCookie());
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());
    httpProcessor.addInterceptor(new ResponseSessionCookie());
    return httpProcessor;
}

From source file:net.kseek.http.TinyHttpServer.java

@Override
public void onCreate() {
    super.onCreate();

    mContext = getApplicationContext();//from  www .  ja v a  2s  . c  o  m
    mRegistry = new MHttpRequestHandlerRegistry();
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    mParams = new BasicHttpParams();
    mParams.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, "MajorKernelPanic HTTP Server");

    // Set up the HTTP protocol processor
    mHttpProcessor = new BasicHttpProcessor();
    mHttpProcessor.addInterceptor(new ResponseDate());
    mHttpProcessor.addInterceptor(new ResponseServer());
    mHttpProcessor.addInterceptor(new ResponseContent());
    mHttpProcessor.addInterceptor(new ResponseConnControl());

    // Will be used in the "Last-Modifed" entity-header field
    try {
        String packageName = mContext.getPackageName();
        mLastModified = new Date(mContext.getPackageManager().getPackageInfo(packageName, 0).lastUpdateTime);
    } catch (NameNotFoundException e) {
        mLastModified = new Date(0);
    }

    // Restores the state of the service 
    mHttpPort = Integer.parseInt(mSharedPreferences.getString(KEY_HTTP_PORT, String.valueOf(mHttpPort)));
    mHttpsPort = Integer.parseInt(mSharedPreferences.getString(KEY_HTTPS_PORT, String.valueOf(mHttpsPort)));
    mHttpEnabled = mSharedPreferences.getBoolean(KEY_HTTP_ENABLED, mHttpEnabled);
    mHttpsEnabled = mSharedPreferences.getBoolean(KEY_HTTPS_ENABLED, mHttpsEnabled);

    // If the configuration is modified, the server will adjust
    mSharedPreferences.registerOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener);

    // Loads plugins available in the package net.kseek.http
    for (int i = 0; i < MODULES.length; i++) {
        try {
            Class<?> pluginClass = Class
                    .forName(TinyHttpServer.class.getPackage().getName() + "." + MODULES[i]);
            Constructor<?> pluginConstructor = pluginClass.getConstructor(new Class[] { TinyHttpServer.class });
            addRequestHandler((String) pluginClass.getField("PATTERN").get(null),
                    (HttpRequestHandler) pluginConstructor.newInstance(this));
        } catch (ClassNotFoundException ignore) {
            // Module disabled
        } catch (Exception e) {
            Log.e(TAG, "Bad module: " + MODULES[i]);
            e.printStackTrace();
        }
    }

    start();

}

From source file:com.baqr.baqrcam.http.TinyHttpServer.java

@Override
public void onCreate() {
    super.onCreate();

    mContext = getApplicationContext();/*from  ww  w . j av a  2 s .  c  o  m*/
    mRegistry = new MHttpRequestHandlerRegistry();
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    mParams = new BasicHttpParams();
    mParams.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, "MajorKernelPanic HTTP Server");

    // Set up the HTTP protocol processor
    mHttpProcessor = new BasicHttpProcessor();
    mHttpProcessor.addInterceptor(new ResponseDate());
    mHttpProcessor.addInterceptor(new ResponseServer());
    mHttpProcessor.addInterceptor(new ResponseContent());
    mHttpProcessor.addInterceptor(new ResponseConnControl());

    // Will be used in the "Last-Modifed" entity-header field
    try {
        String packageName = mContext.getPackageName();
        mLastModified = new Date(mContext.getPackageManager().getPackageInfo(packageName, 0).lastUpdateTime);
    } catch (NameNotFoundException e) {
        mLastModified = new Date(0);
    }

    // Restores the state of the service 
    mHttpPort = Integer.parseInt(mSharedPreferences.getString(KEY_HTTP_PORT, String.valueOf(mHttpPort)));
    mHttpsPort = Integer.parseInt(mSharedPreferences.getString(KEY_HTTPS_PORT, String.valueOf(mHttpsPort)));
    mHttpEnabled = mSharedPreferences.getBoolean(KEY_HTTP_ENABLED, mHttpEnabled);
    mHttpsEnabled = mSharedPreferences.getBoolean(KEY_HTTPS_ENABLED, mHttpsEnabled);

    // If the configuration is modified, the server will adjust
    mSharedPreferences.registerOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener);

    // Loads plugins available in the package net.majorkernelpanic.http
    for (int i = 0; i < MODULES.length; i++) {
        try {
            Class<?> pluginClass = Class
                    .forName(TinyHttpServer.class.getPackage().getName() + "." + MODULES[i]);
            Constructor<?> pluginConstructor = pluginClass.getConstructor(new Class[] { TinyHttpServer.class });
            addRequestHandler((String) pluginClass.getField("PATTERN").get(null),
                    (HttpRequestHandler) pluginConstructor.newInstance(this));
        } catch (ClassNotFoundException ignore) {
            // Module disabled
        } catch (Exception e) {
            Log.e(TAG, "Bad module: " + MODULES[i]);
            e.printStackTrace();
        }
    }

    start();

}

From source file:com.wifi.brainbreaker.mydemo.http.TinyHttpServer.java

@Override
public void onCreate() {
    super.onCreate();

    mContext = getApplicationContext();//from   ww w.  j  av  a  2s.co m
    mRegistry = new MHttpRequestHandlerRegistry();
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    mParams = new BasicHttpParams();
    mParams.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, "MajorKernelPanic HTTP Server");

    // Set up the HTTP protocol processor
    mHttpProcessor = new BasicHttpProcessor();
    mHttpProcessor.addInterceptor(new ResponseDate());
    mHttpProcessor.addInterceptor(new ResponseServer());
    mHttpProcessor.addInterceptor(new ResponseContent());
    mHttpProcessor.addInterceptor(new ResponseConnControl());

    // Will be used in the "Last-Modifed" entity-header field
    try {
        String packageName = mContext.getPackageName();
        mLastModified = new Date(mContext.getPackageManager().getPackageInfo(packageName, 0).lastUpdateTime);
    } catch (NameNotFoundException e) {
        mLastModified = new Date(0);
    }

    // Restores the state of the service
    mHttpPort = Integer.parseInt(mSharedPreferences.getString(KEY_HTTP_PORT, String.valueOf(mHttpPort)));
    mHttpsPort = Integer.parseInt(mSharedPreferences.getString(KEY_HTTPS_PORT, String.valueOf(mHttpsPort)));
    mHttpEnabled = mSharedPreferences.getBoolean(KEY_HTTP_ENABLED, mHttpEnabled);
    mHttpsEnabled = mSharedPreferences.getBoolean(KEY_HTTPS_ENABLED, mHttpsEnabled);

    // If the configuration is modified, the server will adjust
    mSharedPreferences.registerOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener);

    // Loads plugins available in the package net.majorkernelpanic.http
    for (int i = 0; i < MODULES.length; i++) {
        try {
            Class<?> pluginClass = Class
                    .forName(TinyHttpServer.class.getPackage().getName() + "." + MODULES[i]);
            Constructor<?> pluginConstructor = pluginClass.getConstructor(new Class[] { TinyHttpServer.class });
            addRequestHandler((String) pluginClass.getField("PATTERN").get(null),
                    (HttpRequestHandler) pluginConstructor.newInstance(this));
        } catch (ClassNotFoundException ignore) {
            // Module disabled
        } catch (Exception e) {
            Log.e(TAG, "Bad module: " + MODULES[i]);
            e.printStackTrace();
        }
    }

    start();

}

From source file:org.apache.axis2.transport.nhttp.ServerHandler.java

/**
 * Return the HttpProcessor for responses
 * @return the HttpProcessor that processes HttpResponses of this server
 *//*from w ww .  j ava  2 s. c  o m*/
private HttpProcessor getHttpProcessor() {
    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());
    return httpProcessor;
}

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;
}