List of usage examples for org.apache.http.protocol ResponseDate ResponseDate
ResponseDate
From source file:org.pepstock.jem.node.HttpsInternalSubmitter.java
/** * Starts the HTTP listener, setting the handlers and SSL factory. * // w w w . ja va 2s. com * @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// w w w . ja v a 2s . c o 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:org.hydracache.server.httpd.HttpServiceHandlerFactory.java
public NHttpServiceHandler create() throws Exception { BasicHttpProcessor httpproc = new BasicHttpProcessor(); // Required protocol interceptors httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); httpproc.addInterceptor(new ParameterFetchRequestIntercepter()); BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), httpParams); HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry(); reqistry.register("*", requestHandler); handler.setHandlerResolver(reqistry); handler.setEventListener(protocolEventListener); return handler; }
From source file:com.wondershare.http.core.Dispatcher.java
protected void initHttpService() { BasicHttpProcessor proc = new BasicHttpProcessor(); ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); HttpResponseFactory responseFactory = new DefaultHttpResponseFactory(); proc.addInterceptor(new ResponseDate()); proc.addInterceptor(new ResponseServer()); proc.addInterceptor(new ResponseContent()); proc.addInterceptor(new ResponseConnControl()); httpService = new HttpService(proc, connStrategy, responseFactory); }
From source file:ru.apertum.qsystem.reports.net.QSystemHtmlInstance.java
private QSystemHtmlInstance() { this.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, "QSystemReportHttpServer/1.1"); // Set up the HTTP protocol processor final BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); // Set up request handlers final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry(); reqistry.register("*", new HttpQSystemReportsHandler()); // Set up the HTTP service this.httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), reqistry, this.params); }
From source file:io.github.thefishlive.updater.HttpServer.java
public void run() { try {/*from w ww .j a v a2s. 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(); } }
From source file:com.wentam.defcol.connect_to_computer.WebServer.java
public WebServer(Context context, String jquery) { this.setContext(context); httpproc = new BasicHttpProcessor(); httpContext = new BasicHttpContext(); 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("/", new HomeCommandHandler(context, jquery)); httpService.setHandlerResolver(registry); }
From source file:com.personalserver.HttpThread.java
public HttpThread(Context ctx, Socket soket, String threadName) { this.mContext = ctx; this.mSocket = soket; this.setName(threadName); mHttpProcessor = new BasicHttpProcessor(); mHttpContext = new BasicHttpContext(); mHttpProcessor.addInterceptor(new ResponseDate()); mHttpProcessor.addInterceptor(new ResponseServer()); mHttpProcessor.addInterceptor(new ResponseContent()); mHttpProcessor.addInterceptor(new ResponseConnControl()); mHttpService = new HttpService(mHttpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); mHttpRequestHandlerRegistry = new HttpRequestHandlerRegistry(); mHttpRequestHandlerRegistry.register(ALL_PATTERN, new HomeCommandHandler(ctx)); mHttpRequestHandlerRegistry.register(DIR_PATTERN, new DirCommandHandler(ctx)); mHttpService.setHandlerResolver(mHttpRequestHandlerRegistry); }
From source file:org.Cherry.Modules.Web.Engine.WebEngine.java
private HttpProcessor getHttpProcessor() { if (null == _httpProcessor) { final HttpProcessorBuilder httpProcessorBuilder = HttpProcessorBuilder.create(); httpProcessorBuilder.add(new ResponseDate()); httpProcessorBuilder.add(new ResponseServer(getOriginServer())); httpProcessorBuilder.add(new ResponseContent()); httpProcessorBuilder.add(new ResponseConnControl()); httpProcessorBuilder.add(getRequestInterceptorService()); httpProcessorBuilder.add(getResponseInterceptorService()); _httpProcessor = httpProcessorBuilder.build(); }//from ww w .jav a2 s . c om return _httpProcessor; }
From source file:se.ginkou.interfaceio.InterfaceServer.java
public static void startServer() throws Exception { // 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, "HttpComponents/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() }); // Set up request handlers HttpAsyncRequestHandlerRegistry reqistry = new HttpAsyncRequestHandlerRegistry(); reqistry.register("*/datatables", new DataTablesHandler()); reqistry.register("*/loginmodules", new RuleFileHandler()); reqistry.register("*/login", new LoginHandler()); reqistry.register("*", new HttpFileHandler(new File("website"))); reqistry.register("*/ping", new TestHandler()); // Create server-side HTTP protocol handler HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, new DefaultConnectionReuseStrategy(), reqistry, params) {//w w w . j a va2 s . c o m @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; // // 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); 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"); }