List of usage examples for org.apache.http.params CoreConnectionPNames SO_TIMEOUT
String SO_TIMEOUT
To view the source code for org.apache.http.params CoreConnectionPNames SO_TIMEOUT.
Click Source Link
From source file:niproxy.NiProxy.java
/** * Setups a monitoring http proxy and starts a non blocking listening * service based on a {@link NiProxyConfig}. This is based on the Apache * Software Foundation's example code "Basic non-blocking HTTP server" that * can be found from http://hc.apache.org/httpcomponents-core-ga/examples.html. */// w w w .j a va 2 s.co m public NiProxy() { HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, NiProxyConfig.getHttpConnectionTimeout()) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers NHttpRequestHandlerRegistry registry = new NHttpRequestHandlerRegistry(); registry.register("*", NiProxyMonitor.get()); handler.setHandlerResolver(registry); // Provide an event logger handler.setEventListener(new EventLogger()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params); try { logger.info("Setting up " + NiProxyConfig.getIOReactorWorkersCount() + " IOReactor workers"); ListeningIOReactor ioReactor = new DefaultListeningIOReactor(NiProxyConfig.getIOReactorWorkersCount(), params); String host = NiProxyConfig.getNiProxyHost(); int port = NiProxyConfig.getNiProxyPort(); logger.info("Listening for connections at " + host + ":" + port); ioReactor.listen(new InetSocketAddress(host, port)); logger.info("NiProxy set up done. Launching event dispatch..."); ioReactor.execute(ioEventDispatch); } catch (Exception e) { logger.error("I/O reactor was interrupted. Exception: " + e); e.printStackTrace(); } logger.info("NiProxy server shutdown."); }
From source file:org.fourthline.cling.transport.impl.apache.StreamServerImpl.java
synchronized public void init(InetAddress bindAddress, Router router) throws InitializationException { try {//from ww w . jav a2 s .com this.router = router; this.serverSocket = new ServerSocket(configuration.getListenPort(), configuration.getTcpConnectionBacklog(), bindAddress); log.info("Created socket (for receiving TCP streams) on: " + serverSocket.getLocalSocketAddress()); this.globalParams .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, configuration.getDataWaitTimeoutSeconds() * 1000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, configuration.getBufferSizeKilobytes() * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, configuration.isStaleConnectionCheck()) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, configuration.isTcpNoDelay()); } catch (Exception ex) { throw new InitializationException( "Could not initialize " + getClass().getSimpleName() + ": " + ex.toString(), ex); } }
From source file:com.github.ignition.support.http.IgnitedHttpRequestBase.java
@Override public IgnitedHttpRequest withTimeout(int timeout) { oldSocketTimeout = httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, IgnitedHttp.DEFAULT_SOCKET_TIMEOUT); oldConnTimeout = httpClient.getParams().getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, IgnitedHttp.DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT); ignitedHttp.setSocketTimeout(timeout); ignitedHttp.setConnectionTimeout(timeout); timeoutChanged = true;/* w w w.j av a2s. c om*/ return this; }
From source file:android.core.TestHttpClient.java
public TestHttpClient() { super();//from ww w.j a v a2 s. c om 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); }
From source file:com.intel.cosbench.api.httpauth.HttpAuth.java
public HttpAuth(String url, String username, String password, int timeout) { // this.host = host; // this.port = port; this.auth_url = url; this.username = username; this.password = password; this.timeout = timeout; this.client = new DefaultHttpClient(); this.client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); }
From source file:com.proofpoint.http.client.ApacheHttpClient.java
public ApacheHttpClient(HttpClientConfig config, Set<? extends HttpRequestFilter> requestFilters) { Preconditions.checkNotNull(config, "config is null"); Preconditions.checkNotNull(requestFilters, "requestFilters is null"); PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.setMaxTotal(config.getMaxConnections()); connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsPerServer()); BasicHttpParams httpParams = new BasicHttpParams(); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, Ints.checkedCast(config.getReadTimeout().toMillis())); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Ints.checkedCast(config.getConnectTimeout().toMillis())); httpParams.setParameter(CoreConnectionPNames.SO_LINGER, 0); // do we need this? DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, httpParams); defaultHttpClient.setKeepAliveStrategy(new FixedIntervalKeepAliveStrategy(config.getKeepAliveInterval())); defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); this.httpClient = defaultHttpClient; this.requestFilters = ImmutableList.copyOf(requestFilters); }
From source file:com.jcn.dlna.sdk.dms.httpserver.HttpServer.java
private HttpServer(WifiManager wifiManager) { this.wifiManager = wifiManager; this.listenPort = 0; 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); startServer();//w w w. j a va 2 s . c o m }
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:com.andrestrequest.http.HttpClientBuilder.java
/** * @return an HttpClient with config as specified in this builder *///from w ww . j av a 2 s. c om DefaultHttpClient getHttpClient() { if (httpClient == null) { httpClient = new DefaultHttpClient(); if (retryHandler == null) { retryHandler = new DefaultHttpRequestRetryHandler(0, false); } httpClient.setHttpRequestRetryHandler(retryHandler); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout); } return httpClient; }
From source file:org.andstatus.app.net.HttpConnectionBasic.java
@Override public JSONObject postRequest(HttpPost postMethod) throws ConnectionException { String method = "postRequest"; String result = "?"; JSONObject jObj = null;/*w w w. ja v a 2 s. c o m*/ int statusCode = 0; try { HttpClient client = HttpApacheUtils.getHttpClient(); postMethod.setHeader("User-Agent", HttpConnection.USER_AGENT); if (getCredentialsPresent()) { postMethod.addHeader("Authorization", "Basic " + getCredentials()); } client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, MyPreferences.getConnectionTimeoutMs()); client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, MyPreferences.getConnectionTimeoutMs()); HttpResponse httpResponse = client.execute(postMethod); statusCode = httpResponse.getStatusLine().getStatusCode(); result = retrieveInputStream(httpResponse.getEntity()); jObj = new JSONObject(result); if (jObj != null) { String error = jObj.optString("error"); if ("Could not authenticate you.".equals(error)) { throw new ConnectionException(error); } } } catch (UnsupportedEncodingException e) { MyLog.e(this, e); } catch (JSONException e) { throw ConnectionException.loggedJsonException(this, e, result, method); } catch (Exception e) { MyLog.e(this, method, e); throw new ConnectionException(e); } finally { postMethod.abort(); } parseStatusCode(statusCode); return jObj; }