Example usage for org.apache.http.protocol UriHttpRequestHandlerMapper register

List of usage examples for org.apache.http.protocol UriHttpRequestHandlerMapper register

Introduction

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

Prototype

public void register(String str, HttpRequestHandler httpRequestHandler) 

Source Link

Usage

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();/*  w w  w . j a  v a  2 s.c  om*/

    // 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:httpscheduler.HttpScheduler.java

/**
 * @param args the command line arguments
 * @throws java.lang.Exception/*from   w  w  w  . j  a  v  a  2s. co  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 a  v a2 s . com
            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.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();/*from  w  w w .  ja  v a2  s  . 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 ww .  j a v  a  2 s.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 av a 2 s. co  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]);
    }/* w  ww  .java2  s . c o  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:org.pepstock.jem.node.HttpsInternalSubmitter.java

/**
 * Starts the HTTP listener, setting the handlers and SSL factory.
 * /*from ww  w .  j ava  2  s .  c om*/
 * @param port port to stay in listening mode
 * @throws ConfigurationException if any errors occurs
 */
public static void start(int port) throws ConfigurationException {
    // Set up the HTTP protocol processor
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Jem/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();

    // Set up request handlers
    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    reqistry.register(SubmitHandler.DEFAULT_ACTION, new SubmitHandler());

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);
    try {
        // sets HTTPS ALWAYS, take a SSL server socket factory
        SSLServerSocketFactory sf = KeyStoreUtil.getSSLServerSocketFactory();
        // creates thread and starts it.
        Thread t = new RequestListener(port, httpService, sf);
        t.setDaemon(false);
        t.start();
    } catch (Exception e) {
        throw new ConfigurationException(e.getMessage(), e);
    }
}

From source file:com.gravspace.core.HttpServer.java

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

    int port = 8082;
    if (args.length >= 1) {
        port = Integer.parseInt(args[0]);
    }//  w w  w  .ja v a2s . c  om

    ActorSystem system = ActorSystem.create("Application-System");
    Properties config = new Properties();
    config.load(HttpServer.class.getResourceAsStream("/megapode.conf"));
    ActorRef master = system.actorOf(Props.create(CoordinatingActor.class, config), "Coordinator");

    // 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 HttpHandler(system, master));

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

    SSLServerSocketFactory sf = null;
    if (port == 8443) {
        // Initialize SSL context
        ClassLoader cl = HttpServer.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();
    }

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

    t.join();
}

From source file:com.cooksys.httpserver.HttpServerStarter.java

@Override
protected Task createTask() {
    return new Task<Void>() {
        @Override/*from  w  w  w  .  j av a 2  s . co m*/
        protected Void call() throws Exception {
            // Set up the HTTP protocol processor
            HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
                    .add(new ResponseServer("PostMaster/1.1")).add(new ResponseContent())
                    .add(new ResponseConnControl()).build();

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

            // Set up the HTTP service that listens for incoming requests
            HttpService httpService = new HttpService(httpproc, registry);

            //RequestListenerThread extends the Thread class, but since we are
            //letting the concurrency handle background tasks, it would not 
            //make sense to spawn another thread inside this task, so we
            //will just call run() method instead of start()
            System.out.println("creating serverThread...");
            try {
                serverThread = new RequestListenerThread(postmasterModel.getPort(), httpService);
            } catch (IOException e) {
                System.out.println("Caught IOException:" + e.getMessage());
                //end the server task
                this.updateMessage(e.getMessage());
                throw e;
            }
            System.out.println("serverThread created: " + serverThread);
            serverThread.run(); //the compiler will warn here, but we did this on purpose

            return null;
        }

        @Override
        protected void failed() {

        }
    };
}