List of usage examples for org.apache.http.params CoreConnectionPNames STALE_CONNECTION_CHECK
String STALE_CONNECTION_CHECK
To view the source code for org.apache.http.params CoreConnectionPNames STALE_CONNECTION_CHECK.
Click Source Link
From source file:wh.contrib.RewardOptimizerHttpClient.java
public static void main(String[] args) throws Exception { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 64 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1 (RewardOptimizer - karlthepagan@gmail.com)"); final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, params); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new RequestContent()); httpproc.addInterceptor(new RequestTargetHost()); httpproc.addInterceptor(new RequestConnControl()); httpproc.addInterceptor(new RequestUserAgent()); httpproc.addInterceptor(new RequestExpectContinue()); // We are going to use this object to synchronize between the // I/O event and main threads RequestCount requestCount = new RequestCount(1); BufferingHttpClientHandler handler = new BufferingHttpClientHandler(httpproc, new MyHttpRequestExecutionHandler(requestCount), new DefaultConnectionReuseStrategy(), params); handler.setEventListener(new EventLogger()); final IOEventDispatch ioEventDispatch = new DefaultClientIOEventDispatch(handler, params); Thread t = new Thread(new Runnable() { public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); }/* www.j a v a 2 s .co m*/ System.out.println("Shutdown"); } }); t.start(); List<SessionRequest> reqs = new ArrayList<SessionRequest>(); // reqs.add(ioReactor.connect( // new InetSocketAddress("www.yahoo.com", 80), // null, // new HttpHost("www.yahoo.com"), // null)); // reqs.add(ioReactor.connect( // new InetSocketAddress("www.google.com", 80), // null, // new HttpHost("www.google.ch"), // null)); // reqs.add(ioReactor.connect( // new InetSocketAddress("www.apache.org", 80), // null, // new HttpHost("www.apache.org"), // null)); reqs.add(ioReactor.connect(new InetSocketAddress("www.wowhead.com", 80), null, new HttpHost("www.wowhead.com"), null)); // Block until all connections signal // completion of the request execution synchronized (requestCount) { while (requestCount.getValue() > 0) { requestCount.wait(); } } System.out.println("Shutting down I/O reactor"); ioReactor.shutdown(); System.out.println("Done"); }
From source file:org.eclipse.ecf.provider.filetransfer.httpcore.NHttpClient.java
public static void main(String[] args) throws Exception { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1"); final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, params); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new RequestContent()); httpproc.addInterceptor(new RequestTargetHost()); httpproc.addInterceptor(new RequestConnControl()); httpproc.addInterceptor(new RequestUserAgent()); httpproc.addInterceptor(new RequestExpectContinue()); // We are going to use this object to synchronize between the // I/O event and main threads //CountDownLatch requestCount = new CountDownLatch(3); CountDownLatch requestCount = new CountDownLatch(1); BufferingHttpClientHandler handler = new MyBufferingHttpClientHandler(httpproc, new MyHttpRequestExecutionHandler(requestCount), new DefaultConnectionReuseStrategy(), params); handler.setEventListener(new EventLogger()); final IOEventDispatch ioEventDispatch = new DefaultClientIOEventDispatch(handler, params); Thread t = new Thread(new Runnable() { public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); }/*from w w w . j a v a 2s .c om*/ System.out.println("Shutdown"); } }); t.start(); SessionRequest[] reqs = new SessionRequest[1]; reqs[0] = ioReactor.connect(new InetSocketAddress("ftp.osuosl.org", 80), null, new HttpHost("ftp.osuosl.org"), new MySessionRequestCallback(requestCount)); // Block until all connections signal // completion of the request execution requestCount.await(); System.out.println("Shutting down I/O reactor"); ioReactor.shutdown(); System.out.println("Done"); }
From source file:NHttpClient.java
public static void main(String[] args) throws Exception { HttpParams params = new BasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1"); final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2, params); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new RequestContent()); httpproc.addInterceptor(new RequestTargetHost()); httpproc.addInterceptor(new RequestConnControl()); httpproc.addInterceptor(new RequestUserAgent()); httpproc.addInterceptor(new RequestExpectContinue()); // We are going to use this object to synchronize between the // I/O event and main threads CountDownLatch requestCount = new CountDownLatch(3); BufferingHttpClientHandler handler = new BufferingHttpClientHandler(httpproc, new MyHttpRequestExecutionHandler(requestCount), new DefaultConnectionReuseStrategy(), params); handler.setEventListener(new EventLogger()); final IOEventDispatch ioEventDispatch = new DefaultClientIOEventDispatch(handler, params); Thread t = new Thread(new Runnable() { public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); }// w w w . j a v a2s. c om System.out.println("Shutdown"); } }); t.start(); SessionRequest[] reqs = new SessionRequest[3]; reqs[0] = ioReactor.connect(new InetSocketAddress("www.yahoo.com", 80), null, new HttpHost("www.yahoo.com"), new MySessionRequestCallback(requestCount)); reqs[1] = ioReactor.connect(new InetSocketAddress("www.google.com", 80), null, new HttpHost("www.google.ch"), new MySessionRequestCallback(requestCount)); reqs[2] = ioReactor.connect(new InetSocketAddress("www.apache.org", 80), null, new HttpHost("www.apache.org"), new MySessionRequestCallback(requestCount)); // Block until all connections signal // completion of the request execution requestCount.await(); System.out.println("Shutting down I/O reactor"); ioReactor.shutdown(); System.out.println("Done"); }
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:org.hydracache.server.httpd.HttpParamsFactory.java
public HttpParams create() { HttpParams httpParams = new BasicHttpParams(); httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout); httpParams.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, socketBufferSize); httpParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false); httpParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); httpParams.setParameter(CoreProtocolPNames.ORIGIN_SERVER, ORIGIN_SERVER_NAME); return httpParams; }
From source file:com.almende.util.ApacheHttpClient.java
/** * Instantiates a new apache http client. * //from w w w . j a va 2 s . c o m */ private ApacheHttpClient() { // generate httpclient httpClient = new DefaultHttpClient(); // Set cookie policy and persistent cookieStore try { httpClient.setCookieStore(new MyCookieStore()); } catch (final Exception e) { LOG.log(Level.WARNING, "Failed to initialize persistent cookieStore!", e); } final HttpParams params = httpClient.getParams(); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); params.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false); httpClient.setParams(params); }
From source file:org.devtcg.five.util.streaming.LocalHttpServer.java
public LocalHttpServer() { super("LocalHttpServer"); mParams = new BasicHttpParams(); mParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); setDaemon(true);//from w w w.j a v a2 s. c o m }
From source file:com.tejus.shavedog.HttpServer.java
public HttpServer(LocalInetAddressResolver localInetAddressResolver, int listenPort) { this.localInetAddressResolver = localInetAddressResolver; this.listenPort = listenPort; this.handlerRegistry = new HttpRequestHandlerRegistry(); this.params = new BasicHttpParams(); this.params.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "4thLineAndroidHttpServer/1.0") .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); if (Util.ANDROID_EMULATOR) { // Start immediately on emulator because there will never be a "WiFi switched on" event startServer();//from w w w . jav a 2s . c o m } }
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;//w w w .j a v a2 s . c om listener.submit(new HttpListener()); }
From source file:android.core.TestHttpClient.java
public TestHttpClient() { super();//from w w w . j a va 2 s . c o m this.params = new BasicHttpParams(); this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1) .setParameter(CoreProtocolPNames.USER_AGENT, "TEST-CLIENT/1.1"); this.httpproc = new BasicHttpProcessor(); // Required protocol interceptors this.httpproc.addInterceptor(new RequestContent()); this.httpproc.addInterceptor(new RequestTargetHost()); // Recommended protocol interceptors this.httpproc.addInterceptor(new RequestConnControl()); this.httpproc.addInterceptor(new RequestUserAgent()); this.httpproc.addInterceptor(new RequestExpectContinue()); this.httpexecutor = new HttpRequestExecutor(); this.connStrategy = new DefaultConnectionReuseStrategy(); this.context = new BasicHttpContext(null); }