List of usage examples for org.apache.http.protocol UriHttpRequestHandlerMapper UriHttpRequestHandlerMapper
public UriHttpRequestHandlerMapper()
From source file:httpscheduler.HttpScheduler.java
/** * @param args the command line arguments * @throws java.lang.Exception/*from ww w . j a va 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 ava 2 s. c o m 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();/*from w ww. j av a2s . 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();// www . j a va 2s . 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 { /**// ww w . jav a2 s. c o m * 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);// www. j a va 2 s .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]); }/*from w ww . j av a 2 s. com*/ // 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 www .j a v a 2s.c o m * @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.cooksys.httpserver.HttpServerStarter.java
@Override protected Task createTask() { return new Task<Void>() { @Override//from www . ja va 2s .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() { } }; }
From source file:io.github.thefishlive.updater.HttpServer.java
public void run() { try {/*from w w w.ja va 2 s . c o m*/ int port = GitUpdater.port; // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("GitUpdater/1.0-SNAPSHOT")).add(new ResponseContent()) .add(new ResponseConnControl()).build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new ResponceHandler()); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; if (port == 8443) { // Initialize SSL context ClassLoader cl = getClass().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(); } try { Thread t = new RequestListenerThread(port, httpService, sf); t.setDaemon(false); t.start(); } catch (BindException ex) { System.out.println("Error binding to port " + port); System.out.println("Perhaps another server is running on that port"); return; } catch (IOException ex) { ex.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } }