List of usage examples for org.apache.http.protocol ResponseContent ResponseContent
public ResponseContent()
From source file:org.pepstock.jem.node.HttpsInternalSubmitter.java
/** * Starts the HTTP listener, setting the handlers and SSL factory. * /* ww w .ja va2 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.cooksys.httpserver.HttpServerStarter.java
@Override protected Task createTask() { return new Task<Void>() { @Override//from w w w. j a v a 2s . c om 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 {/* w w w . j a v a 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(); } }
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:brooklyn.util.ResourceUtilsHttpTest.java
@BeforeClass(alwaysRun = true) public void setUp() throws Exception { utils = ResourceUtils.create(this, "mycontext"); BasicHttpProcessor httpProcessor = new BasicHttpProcessor(); httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); httpProcessor.addInterceptor(new RequestBasicAuth()); httpProcessor.addInterceptor(new ResponseBasicUnauthorized()); server = new LocalTestServer(httpProcessor, null); server.register("/simple", new SimpleResponseHandler("OK")); server.register("/empty", new SimpleResponseHandler(HttpStatus.SC_NO_CONTENT, "")); server.register("/missing", new SimpleResponseHandler(HttpStatus.SC_NOT_FOUND, "Missing")); server.register("/redirect", new SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new BasicHeader("Location", "/simple"))); server.register("/cycle", new SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new BasicHeader("Location", "/cycle"))); server.register("/secure", new SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new BasicHeader("Location", "https://0.0.0.0/"))); server.register("/auth", new AuthHandler("test", "test", "OK")); server.register("/auth_escape", new AuthHandler("test@me:/", "test", "OK")); server.register("/auth_escape2", new AuthHandler("test@me:test", "", "OK")); server.register("/no_credentials", new CheckNoCredentials()); server.start();// w w w . j a v a 2 s .c om InetSocketAddress addr = server.getServiceAddress(); baseUrl = "http://" + addr.getHostName() + ":" + addr.getPort(); }
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(); }// w ww . j a v a2s . c o m return _httpProcessor; }