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

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

Introduction

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

Prototype

ResponseDate

Source Link

Usage

From source file:httpscheduler.HttpScheduler.java

/**
 * @param args the command line arguments
 * @throws java.lang.Exception//from  w w  w  .j a  v  a 2 s.c o m
 */

public static void main(String[] args) throws Exception {

    if (args.length != 2) {
        System.err.println("Invalid command line parameters for worker");
        System.exit(-1);
    }

    int fixedExecutorSize = 4;

    //Creating fixed size executor
    ThreadPoolExecutor taskCommExecutor = new ThreadPoolExecutor(fixedExecutorSize, fixedExecutorSize, 0L,
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
    // Used for late binding
    JobMap jobMap = new JobMap();

    // Set port number
    int port = Integer.parseInt(args[0]);

    // Set worker mode
    String mode = args[1].substring(2);

    // Set up the HTTP protocol processor
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();

    // Set up request handlers
    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    // Different handlers for late binding and generic cases
    if (mode.equals("late"))
        reqistry.register("*", new LateBindingRequestHandler(taskCommExecutor, jobMap));
    else
        reqistry.register("*", new GenericRequestHandler(taskCommExecutor, mode));

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);

    SSLServerSocketFactory sf = null;

    // create a thread to listen for possible client available connections
    Thread t;
    if (mode.equals("late"))
        t = new LateBindingRequestListenerThread(port, httpService, sf);
    else
        t = new GenericRequestListenerThread(port, httpService, sf);
    System.out.println("Request Listener Thread created");
    t.setDaemon(false);
    t.start();

    // main thread should wait for the listener to exit before shutdown the
    // task executor pool
    t.join();

    // shutdown task executor pool and wait for any taskCommExecutor thread
    // still running
    taskCommExecutor.shutdown();
    while (!taskCommExecutor.isTerminated()) {
    }

    System.out.println("Finished all task communication executor threads");
    System.out.println("Finished all tasks");

}

From source file:net.minder.httpcap.HttpCap.java

public static void main(String[] args) throws Exception {
    PropertyConfigurator.configure(ClassLoader.getSystemResourceAsStream("log4j.properties"));

    int port = DEFAULT_PORT;

    if (args.length > 0) {
        try {//  w  ww. j ava2s . c  om
            port = Integer.parseInt(args[0]);
        } catch (NumberFormatException nfe) {
            port = DEFAULT_PORT;
        }
    }

    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("HttpCap/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();

    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    reqistry.register("*", new HttpCapHandler());

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);

    SSLServerSocketFactory sf = null;
    //    if (port == 8443) {
    //      // Initialize SSL context
    //      ClassLoader cl = HttpCap.class.getClassLoader();
    //      URL url = cl.getResource("my.keystore");
    //      if (url == null) {
    //        System.out.println("Keystore not found");
    //        System.exit(1);
    //      }
    //      KeyStore keystore  = KeyStore.getInstance("jks");
    //      keystore.load(url.openStream(), "secret".toCharArray());
    //      KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
    //          KeyManagerFactory.getDefaultAlgorithm());
    //      kmfactory.init(keystore, "secret".toCharArray());
    //      KeyManager[] keymanagers = kmfactory.getKeyManagers();
    //      SSLContext sslcontext = SSLContext.getInstance("TLS");
    //      sslcontext.init(keymanagers, null, null);
    //      sf = sslcontext.getServerSocketFactory();
    //    }

    Thread t = new RequestListenerThread(port, httpService, sf);
    t.setDaemon(false);
    t.start();
}

From source file:com.vikram.kdtree.ElementalHttpServer.java

public static void main(String[] args) throws Exception {
    // Set up the HTTP protocol processor
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();//  ww  w .  j a v  a  2s .  c  o m

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

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);

    Properties properties = new Properties();
    properties.load(new FileInputStream("Config.properties"));

    Thread t = new RequestListenerThread(Integer.valueOf(properties.getProperty("requestPort")), httpService,
            null);
    t.setDaemon(false);
    t.start();
}

From source file:com.adhi.webserver.WebServer.java

public static void main(String[] args) throws Exception {

    int port = 9999;

    // Set up the HTTP protocol processor
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();//  w ww .  ja  v a2s  . c  o m

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

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);

    SSLServerSocketFactory sf = null;
    if (port == 8443) {
        // Initialize SSL context
        ClassLoader cl = WebServer.class.getClassLoader();
        URL url = cl.getResource("my.keystore");
        if (url == null) {
            System.out.println("Keystore not found");
            System.exit(1);
        }
        KeyStore keystore = KeyStore.getInstance("jks");
        keystore.load(url.openStream(), "secret".toCharArray());
        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmfactory.init(keystore, "secret".toCharArray());
        KeyManager[] keymanagers = kmfactory.getKeyManagers();
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(keymanagers, null, null);
        sf = sslcontext.getServerSocketFactory();
    }

    Thread t = new RequestListenerThread(port, httpService, sf);
    t.setDaemon(false);
    t.start();
}

From source file:com.bfd.job.testClient.t04.ElementalHttpServer.java

public static void main(String[] args) throws Exception {
    /**//from  w w  w .ja  v a2s. c  om
     * if (args.length < 1) {
     * System.err.println("Please specify document root directory");
     * System.exit(1); } // Document root directory String docRoot =
     * args[0];
     */
    String docRoot = "c:/root";
    int port = 8080;
    if (args.length >= 2) {
        port = Integer.parseInt(args[1]);
    }

    // Set up the HTTP protocol processor
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();

    // Set up request handlers
    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    reqistry.register("*", new HttpFileHandler(docRoot));

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);

    SSLServerSocketFactory sf = null;
    if (port == 8443) {
        // Initialize SSL context
        ClassLoader cl = ElementalHttpServer.class.getClassLoader();
        URL url = cl.getResource("my.keystore");
        if (url == null) {
            System.out.println("Keystore not found");
            System.exit(1);
        }
        KeyStore keystore = KeyStore.getInstance("jks");
        keystore.load(url.openStream(), "secret".toCharArray());
        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmfactory.init(keystore, "secret".toCharArray());
        KeyManager[] keymanagers = kmfactory.getKeyManagers();
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(keymanagers, null, null);
        sf = sslcontext.getServerSocketFactory();
    }

    Thread t = new RequestListenerThread(port, httpService, sf);
    t.setDaemon(false);
    t.start();
}

From source file:httpserver.ElementalHttpServer.java

public static void main(String[] args) throws Exception {

    // Clay code, adding arguments to simulate command line execution
    args = new String[2];
    args[0] = "C://Users/Clay/Documents";
    args[1] = "80";

    if (args.length < 1) {
        System.err.println("Please specify document root directory");
        System.exit(1);//from ww w .  j a va2s  .  c o m
    }
    // Document root directory
    String docRoot = args[0];

    // Setting up port, if port was specified, then use that one
    int port = 8080;
    if (args.length >= 2) {
        port = Integer.parseInt(args[1]);
    }

    // Set up the HTTP protocol processor
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();

    // Set up request handlers
    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    reqistry.register("*", new HttpFileHandler(docRoot));

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);

    SSLServerSocketFactory sf = null;
    if (port == 8443) {
        // Initialize SSL context
        ClassLoader cl = ElementalHttpServer.class.getClassLoader();
        URL url = cl.getResource("my.keystore");
        if (url == null) {
            System.out.println("Keystore not found");
            System.exit(1);
        }
        KeyStore keystore = KeyStore.getInstance("jks");
        keystore.load(url.openStream(), "secret".toCharArray());
        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmfactory.init(keystore, "secret".toCharArray());
        KeyManager[] keymanagers = kmfactory.getKeyManagers();
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(keymanagers, null, null);
        sf = sslcontext.getServerSocketFactory();
    }

    Thread t = new RequestListenerThread(port, httpService, sf);
    t.setDaemon(false);
    t.start();
}

From source file:za.co.taung.httpdotserver.main.HttpDotServer.java

public static void main(String[] args) throws Exception {

    LOG.info("Initialise server");

    // The parameter is the Port to listen on. Default is 8080. 
    int port = 8080;
    if (args.length >= 1) {
        port = Integer.parseInt(args[0]);
    }/*www. ja v  a2 s  . co  m*/

    // Set up the HTTP protocol processor.
    HttpProcessor httpProcessor = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("HttpDotServer/1.1")).add(new ResponseContent())
            .add(new ResponseConnControl()).build();

    // Set up request handler. This is the method that generates SVG. 
    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    reqistry.register("*", new Dot2SVGHandler());

    // Set up the HTTP service.
    HttpService httpService = new HttpService(httpProcessor, reqistry);

    // Set up SSL if listening on 8443 for https.
    SSLServerSocketFactory serverSocketFactory = null;
    if (port == 8443) {
        // Get the location of the keystore secrets.
        ClassLoader cl = HttpDotServer.class.getClassLoader();
        URL url = cl.getResource("my.keystore");
        if (url == null) {
            LOG.error("Keystore not found");
            System.exit(1);
        }
        // Load the secret into a keystore and manage the key material.
        KeyStore keystore = KeyStore.getInstance("jks");
        keystore.load(url.openStream(), "secret".toCharArray());
        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmfactory.init(keystore, "secret".toCharArray());
        KeyManager[] keymanagers = kmfactory.getKeyManagers();
        // Prepare the socket factory for use by the RequestListenerThread.
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(keymanagers, null, null);
        serverSocketFactory = sslcontext.getServerSocketFactory();
    }

    LOG.debug("Start the RequestListenerThread");
    Thread thread = new RequestListenerThread(port, httpService, serverSocketFactory);
    thread.setDaemon(false);
    thread.start();
}

From source file:proxy.NHttpServer.java

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Please specify document root directory");
        System.exit(1);/*  ww w  . ja va  2s  . c om*/
    }
    // Document root directory
    File docRoot = new File(args[0]);
    int port = 8080;
    if (args.length >= 2) {
        port = Integer.parseInt(args[1]);
    }

    // Create HTTP protocol processing chain
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();
    // Create request handler registry
    UriHttpAsyncRequestHandlerMapper reqistry = new UriHttpAsyncRequestHandlerMapper();
    // Register the default handler for all URIs
    reqistry.register("*", new HttpFileHandler(docRoot));
    // Create server-side HTTP protocol handler
    HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, reqistry) {

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

        @Override
        public void closed(final NHttpServerConnection conn) {
            System.out.println(conn + ": connection closed");
            super.closed(conn);
        }

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

From source file:yucatan.communication.server.NHttpServer.java

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Please specify document root directory");
        System.exit(1);//from  w  ww .  j a  va2 s  .co  m
    }
    // Document root directory
    File docRoot = new File(args[0]);
    int port = 8080;
    if (args.length >= 2) {
        port = Integer.parseInt(args[1]);
    }
    // HTTP parameters for the server
    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
    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
            // Use standard server-side protocol interceptors
            new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() });
    // Create request handler registry
    HttpAsyncRequestHandlerRegistry reqistry = new HttpAsyncRequestHandlerRegistry();
    // Register the default handler for all URIs
    reqistry.register("*", new HttpFileHandler(docRoot));
    // Create server-side HTTP protocol handler
    HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, new DefaultConnectionReuseStrategy(),
            reqistry, params) {

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

        @Override
        public void closed(final NHttpServerConnection conn) {
            System.out.println(conn + ": connection closed");
            super.closed(conn);
        }

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

From source file:com.yahoo.gondola.container.utils.LocalTestServer.java

public LocalTestServer(HttpRequestHandler handler) {
    try {/* ww  w  .ja va 2  s  .  c  om*/
        setUp();
        HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
                .add(new ResponseServer(LocalServerTestBase.ORIGIN)).add(new ResponseContent())
                .add(new ResponseConnControl()).add(new RequestBasicAuth()).add(new ResponseBasicUnauthorized())
                .build();
        this.serverBootstrap.setHttpProcessor(httpproc);
        this.serverBootstrap.registerHandler("*", handler);
        host = start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}