List of usage examples for org.apache.http.protocol BasicHttpProcessor addInterceptor
public final void addInterceptor(HttpResponseInterceptor httpResponseInterceptor)
From source file:com.limegroup.gnutella.http.HttpTestServer.java
public void execute(EventListener listener) throws IOException { BasicHttpProcessor processor = new BasicHttpProcessor(); processor.addInterceptor(new ResponseDate()); processor.addInterceptor(new ResponseServer()); processor.addInterceptor(new ResponseContent()); processor.addInterceptor(new ResponseConnControl()); AsyncNHttpServiceHandler serviceHandler = new AsyncNHttpServiceHandler(processor, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); serviceHandler.setEventListener(listener); serviceHandler.setHandlerResolver(this.registry); reactor = new DefaultDispatchedIOReactor(params, NIODispatcher.instance().getScheduledExecutorService()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(serviceHandler, params); reactor.execute(ioEventDispatch);//from w w w. j a v a 2 s . c om }
From source file:org.apache.camel.component.http4.HttpAuthenticationTest.java
@Override protected BasicHttpProcessor getBasicHttpProcessor() { BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new RequestBasicAuth()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseBasicUnauthorized()); return httpproc; }
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:org.apache.camel.component.http4.HttpCompressionTest.java
@Override protected BasicHttpProcessor getBasicHttpProcessor() { BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new RequestDecompressingInterceptor()); httpproc.addInterceptor(new ResponseCompressingInterceptor()); return httpproc; }
From source file:org.apache.droids.protocol.http.DroidsHttpClient.java
@Override protected BasicHttpProcessor createHttpProcessor() { BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new RequestDefaultHeaders()); // Required protocol interceptors httpproc.addInterceptor(new RequestContent()); httpproc.addInterceptor(new RequestTargetHost()); // Recommended protocol interceptors httpproc.addInterceptor(new RequestConnControl()); httpproc.addInterceptor(new RequestUserAgent()); httpproc.addInterceptor(new RequestExpectContinue()); // HTTP authentication interceptors httpproc.addInterceptor(new RequestProxyAuthentication()); return httpproc; }
From source file:org.wso2.carbon.automation.extensions.servers.httpserver.SimpleHttpServer.java
public void start() throws IOException { serverSocket = new ServerSocket(port); params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, getParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, getParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, getParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, 0) == 1) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, getParameter(CoreConnectionPNames.TCP_NODELAY, 1) == 1) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "WSO2ESB-Test-Server"); // Configure HTTP protocol processor BasicHttpProcessor httpProcessor = new BasicHttpProcessor(); httpProcessor.addInterceptor(new ResponseDate()); httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); registry.register("*", requestHandler); // Set up the HTTP service httpService = new HttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), registry, params); listener = Executors.newSingleThreadExecutor(); workerPool = Executors.newFixedThreadPool(getParameter("ThreadCount", 2)); shutdown = false;//from ww w.j ava 2 s .c om listener.submit(new HttpListener()); }
From source file:com.subgraph.vega.internal.http.proxy.HttpProxy.java
public HttpProxy(int listenPort, ProxyTransactionManipulator transactionManipulator, HttpInterceptor interceptor, IHttpRequestEngine requestEngine, SSLContextRepository sslContextRepository) { this.eventHandlers = new ArrayList<IHttpInterceptProxyEventHandler>(); this.transactionManipulator = transactionManipulator; this.interceptor = interceptor; this.listenPort = listenPort; this.params = new BasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) // .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); BasicHttpProcessor inProcessor = new BasicHttpProcessor(); inProcessor.addInterceptor(new ResponseConnControl()); inProcessor.addInterceptor(new ResponseContentCustom()); HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); registry.register("*", new ProxyRequestHandler(this, logger, requestEngine)); httpService = new VegaHttpService(inProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), registry, params, sslContextRepository); connectionList = new ArrayList<ConnectionTask>(); }
From source file:marytts.tools.perceptiontest.PerceptionTestHttpServer.java
public void run() { logger.info("Starting server."); System.out.println("Starting server...."); //int localPort = MaryProperties.needInteger("socket.port"); int localPort = serverPort; HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 seconds) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); //registry.register("/perceptionTest", new FileDataRequestHandler("perception.html")); //registry.register("/process", new FileDataRequestHandler("perception.html")); //registry.register("/perceptionTest", new UtterancePlayRequestHandler()); DataRequestHandler infoRH = new DataRequestHandler(this.testXmlName); UserRatingStorer userRatingRH = new UserRatingStorer(this.userRatingsDirectory, infoRH); registry.register("/options", infoRH); registry.register("/queryStatement", infoRH); registry.register("/process", new UtterancePlayRequestHandler(infoRH)); registry.register("/perceptionTest", new PerceptionRequestHandler(infoRH, userRatingRH)); registry.register("/userRating", new StoreRatingRequestHandler(infoRH, userRatingRH)); registry.register("*", new FileDataRequestHandler()); handler.setHandlerResolver(registry); // Provide an event logger handler.setEventListener(new EventLogger()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params); //int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5); int numParallelThreads = 5; logger.info("Waiting for client to connect on port " + localPort); System.out.println("Waiting for client to connect on port " + localPort); try {//ww w . j ava 2 s . co m ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params); ioReactor.listen(new InetSocketAddress(localPort)); ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { logger.info("Interrupted", ex); System.out.println("Interrupted" + ex.toString()); } catch (IOException e) { logger.info("Problem with HTTP connection ", e); System.out.println("Problem with HTTP connection " + e.toString()); } logger.debug("Shutdown"); System.out.println("Shutdown"); }
From source file:com.yanzhenjie.andserver.DefaultAndServer.java
@Override public void run() { try {/*from www . j ava 2 s. c o m*/ mServerSocket = new ServerSocket(); mServerSocket.setReuseAddress(true); mServerSocket.bind(new InetSocketAddress(mPort)); // HTTP?? BasicHttpProcessor httpProcessor = new BasicHttpProcessor(); httpProcessor.addInterceptor(new ResponseDate()); httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); // HTTP Attribute. HttpParams httpParams = new BasicHttpParams(); httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "WebServer/1.1"); // Http? HttpRequestHandlerRegistry handlerRegistry = new HttpRequestHandlerRegistry(); for (Map.Entry<String, AndServerRequestHandler> handlerEntry : mRequestHandlerMap.entrySet()) { handlerRegistry.register("/" + handlerEntry.getKey(), new DefaultHttpRequestHandler(handlerEntry.getValue())); } // HTTP? HttpService httpService = new HttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); httpService.setParams(httpParams); httpService.setHandlerResolver(handlerRegistry); /** * ? */ while (isLoop) { // if (!mServerSocket.isClosed()) { Socket socket = mServerSocket.accept(); DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection(); serverConnection.bind(socket, httpParams); // Dispatch request handler. RequestHandleTask requestTask = new RequestHandleTask(this, httpService, serverConnection); requestTask.setDaemon(true); AndWebUtil.executeRunnable(requestTask); } } } catch (Exception e) { } finally { close(); } }
From source file:org.apache.axis2.transport.http.server.DefaultHttpConnectionManager.java
public void process(final AxisHttpConnection conn) { if (conn == null) { throw new IllegalArgumentException("HTTP connection may not be null"); }//from w w w . j a v a2 s. co m // Evict destroyed processors cleanup(); // Assemble new Axis HTTP service HttpProcessor httpProcessor; ConnectionReuseStrategy connStrategy; HttpResponseFactory responseFactory; if (httpFactory != null) { httpProcessor = httpFactory.newHttpProcessor(); connStrategy = httpFactory.newConnStrategy(); responseFactory = httpFactory.newResponseFactory(); } else { BasicHttpProcessor p = new BasicHttpProcessor(); p.addInterceptor(new RequestSessionCookie()); p.addInterceptor(new ResponseDate()); p.addInterceptor(new ResponseServer()); p.addInterceptor(new ResponseContent()); p.addInterceptor(new ResponseConnControl()); p.addInterceptor(new ResponseSessionCookie()); httpProcessor = p; connStrategy = new DefaultConnectionReuseStrategy(); responseFactory = new DefaultHttpResponseFactory(); } AxisHttpService httpService = new AxisHttpService(httpProcessor, connStrategy, responseFactory, this.configurationContext, this.workerfactory.newWorker()); httpService.setParams(this.params); // Create I/O processor to execute HTTP service IOProcessorCallback callback = new IOProcessorCallback() { public void completed(final IOProcessor processor) { removeProcessor(processor); if (LOG.isDebugEnabled()) { LOG.debug(processor + " terminated"); } } }; IOProcessor processor = new HttpServiceProcessor(httpService, conn, callback); addProcessor(processor); this.executor.execute(processor); }