List of usage examples for org.apache.http.impl DefaultConnectionReuseStrategy DefaultConnectionReuseStrategy
DefaultConnectionReuseStrategy
From source file:com.jrodeo.remote.TestHttpCore.java
public TestHttpCore() { super();//from ww w .j a v a 2 s .c o m this.params = new SyncBasicHttpParams(); this.params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); this.params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); this.params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false); this.params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024); this.params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 15000); this.httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] { new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent() }, null); this.httpexecutor = new HttpRequestExecutor(); this.connStrategy = new DefaultConnectionReuseStrategy(); this.pool = new BasicConnPool(this.params); }
From source file:net.kungfoo.grizzly.proxy.impl.Activator.java
private static void setupClient() throws IOReactorException { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); connectingIOReactor = new DefaultConnectingIOReactor(1, params); BasicHttpProcessor originServerProc = new BasicHttpProcessor(); originServerProc.addInterceptor(new RequestContent()); originServerProc.addInterceptor(new RequestTargetHost()); originServerProc.addInterceptor(new RequestConnControl()); originServerProc.addInterceptor(new RequestUserAgent()); originServerProc.addInterceptor(new RequestExpectContinue()); NHttpClientHandler connectingHandler = new ConnectingHandler(originServerProc, new DefaultConnectionReuseStrategy(), params); connectingEventDispatch = new DefaultClientIOEventDispatch(connectingHandler, params); }
From source file:com.zotoh.maedr.device.apache.HttpIO.java
protected void onStart() throws Exception { // mostly copied from apache http tutotial... HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, (int) getSocetTimeoutMills()) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) // 8k? .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "Apache-HttpCore/4.x"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); ConnectionReuseStrategy strategy = new DefaultConnectionReuseStrategy(); HttpResponseFactory rspFac = new DefaultHttpResponseFactory(); NHttpServiceHandler svc;//from w w w .java2s .com EventListener evt = new EventLogger(getId(), tlog()); if (isAsync()) { AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(httpproc, rspFac, strategy, params); NHttpRequestHandlerRegistry r = new NHttpRequestHandlerRegistry(); r.register("*", new HttpNRequestCB(this)); handler.setHandlerResolver(r); handler.setEventListener(evt); svc = handler; } else { StreamedHttpServiceHandler handler = new StreamedHttpServiceHandler(httpproc, rspFac, strategy, params); HttpRequestHandlerRegistry r = new HttpRequestHandlerRegistry(); r.register("*", new HttpRequestCB(this)); handler.setHandlerResolver(r); handler.setEventListener(evt); svc = handler; } IOEventDispatch disp = isSSL() ? onSSL(svc, params) : onBasic(svc, params); ListeningIOReactor ioReactor; ioReactor = new DefaultListeningIOReactor(getWorkers(), params); ioReactor.listen(new InetSocketAddress(NetUte.getNetAddr(getHost()), getPort())); _curIO = ioReactor; // start... runServer(disp, ioReactor); }
From source file:org.fourthline.cling.transport.impl.apache.HttpServerConnectionUpnpStream.java
protected HttpServerConnectionUpnpStream(ProtocolFactory protocolFactory, HttpServerConnection connection, final HttpParams params) { super(protocolFactory); this.connection = connection; this.params = params; // The Date header is recommended in UDA, need to document the requirement in StreamServer interface? httpProcessor.addInterceptor(new ResponseDate()); // The Server header is only required for Control so callers have to add it to UPnPMessage // httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); httpService = new UpnpHttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); httpService.setParams(params);//from w w w . j a v a 2s .co m }
From source file:com.android.unit_tests.TestHttpServer.java
public TestHttpServer() throws IOException { super();//w w w.j a v a 2 s .c om this.params = new BasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 20000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "TEST-SERVER/1.1"); this.httpproc = new BasicHttpProcessor(); this.httpproc.addInterceptor(new ResponseDate()); this.httpproc.addInterceptor(new ResponseServer()); this.httpproc.addInterceptor(new ResponseContent()); this.httpproc.addInterceptor(new ResponseConnControl()); this.connStrategy = new DefaultConnectionReuseStrategy(); this.responseFactory = new DefaultHttpResponseFactory(); this.reqistry = new HttpRequestHandlerRegistry(); this.serversocket = new ServerSocket(0); }
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 {/* w w w .java 2 s .com*/ 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:bigbird.benchmark.BenchmarkWorker.java
public BenchmarkWorker(final HttpParams params, int verbosity, final RequestGenerator requestGenerator, final HttpHost targetHost, int count, boolean keepalive) { super();// w ww . jav a 2 s.c o m this.params = params; this.requestGenerator = requestGenerator; this.context = new BasicHttpContext(null); this.targetHost = targetHost; this.count = count; this.keepalive = keepalive; this.httpProcessor = new BasicHttpProcessor(); this.httpexecutor = new HttpRequestExecutor(); // Required request interceptors this.httpProcessor.addInterceptor(new RequestContent()); this.httpProcessor.addInterceptor(new RequestTargetHost()); // Recommended request interceptors this.httpProcessor.addInterceptor(new RequestConnControl()); this.httpProcessor.addInterceptor(new RequestUserAgent()); this.httpProcessor.addInterceptor(new RequestExpectContinue()); this.connstrategy = new DefaultConnectionReuseStrategy(); this.verbosity = verbosity; }
From source file:com.yanzhenjie.andserver.DefaultAndServer.java
@Override public void run() { try {/* w w w .j a v a2 s .c om*/ 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:com.k42b3.aletheia.protocol.http.HttpProtocol.java
public void setRequest(com.k42b3.aletheia.protocol.Request request, CallbackInterface callback) throws Exception { super.setRequest(request, callback); // request settings int port = request.getUrl().getPort(); if (port == -1) { if (request.getUrl().getProtocol().equalsIgnoreCase("https")) { port = 443;//from w w w.j a va2 s . c o m } else { port = 80; } } context = new BasicHttpContext(null); host = new HttpHost(request.getUrl().getHost(), port); conn = new DefaultHttpClientConnection(); connStrategy = new DefaultConnectionReuseStrategy(); context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host); }
From source file:org.devtcg.five.server.AbstractHttpServer.java
public void run() { if (mReqHandler == null) throw new IllegalStateException("Request handler not set."); while (Thread.interrupted() == false) { try {// w ww . j a v a 2s .c o m Socket sock = getSocket().accept(); DefaultHttpServerConnection conn = new DefaultHttpServerConnection(); conn.bind(sock, mParams); BasicHttpProcessor proc = new BasicHttpProcessor(); proc.addInterceptor(new ResponseContent()); proc.addInterceptor(new ResponseConnControl()); HttpRequestHandlerRegistry reg = new HttpRequestHandlerRegistry(); reg.register("*", mReqHandler); HttpService svc = new HttpService(proc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); svc.setParams(mParams); svc.setHandlerResolver(reg); WorkerThread t; synchronized (mWorkers) { t = new WorkerThread(svc, conn); mWorkers.add(t); } t.start(); } catch (IOException e) { if (!hasCanceled()) { if (LOG.isErrorEnabled()) LOG.error("I/O error initializing connection thread", e); } break; } } }