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:org.carrot2.util.httpclient.HttpClientFactory.java
/** * @param timeout Timeout in milliseconds. * @return Returns a client with sockets configured to timeout after some sensible * time./* w w w. j av a 2s . c om*/ */ public static DefaultHttpClient getTimeoutingClient(int timeout) { final DefaultHttpClient httpClient = new DefaultHttpClient(); configureProxy(httpClient); // Setup defaults. httpClient.setReuseStrategy(new NoConnectionReuseStrategy()); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_LINGER, 0); return httpClient; }
From source file:com.sunhz.projectutils.httputils.HttpClientUtils.java
/** * get access to the network, you need to use in the sub-thread * * @param url url//from w ww. j a v a 2 s. c om * @return response inputStream * @throws IOException In the case of non-200 status code is returned, it would have thrown */ public static InputStream getInputStream(String url) throws IOException { org.apache.http.client.HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Constant.TimeInApplication.NET_TIMEOUT); client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, Constant.TimeInApplication.NET_TIMEOUT); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response.getEntity().getContent(); } else { throw new IllegalArgumentException("getInputStreamInSubThread response status code is " + response.getStatusLine().getStatusCode()); } }
From source file:com.rackspacecloud.blueflood.http.HttpClientVendor.java
public HttpClientVendor() { client = new DefaultHttpClient(buildConnectionManager(20)); client.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true); client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000); client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000); // Wait this long for an available connection. Setting this correctly is important in order to avoid // connectionpool timeouts. client.getParams().setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, 5000); }
From source file:Main.java
public static HttpEntity getEntity(String uri, ArrayList<BasicNameValuePair> params, int method) throws ClientProtocolException, IOException { mClient = new DefaultHttpClient(); HttpUriRequest request = null;// w w w . java2 s . c om switch (method) { case METHOD_GET: StringBuilder sb = new StringBuilder(uri); if (params != null && !params.isEmpty()) { sb.append("?"); for (BasicNameValuePair param : params) { sb.append(param.getName()).append("=").append(URLEncoder.encode(param.getValue(), "UTF_8")) .append("&"); } sb.deleteCharAt(sb.length() - 1); } request = new HttpGet(sb.toString()); break; case METHOD_POST: HttpPost post = new HttpPost(uri); if (params != null && !params.isEmpty()) { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF_8"); post.setEntity(entity); } request = post; break; } mClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000); mClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000); HttpResponse response = mClient.execute(request); System.err.println(response.getStatusLine().toString()); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response.getEntity(); } return null; }
From source file:org.andstatus.app.net.http.MisconfiguredSslHttpClientFactory.java
static HttpClient getHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); // This is done to get rid of the "javax.net.ssl.SSLException: hostname in certificate didn't match" error // See e.g. http://stackoverflow.com/questions/8839541/hostname-in-certificate-didnt-match socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", socketFactory, 443)); HttpParams params = getHttpParams(); ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); HttpClient client = new DefaultHttpClient(clientConnectionManager, params); client.getParams()//from ww w . ja v a 2s . c om .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, MyPreferences.getConnectionTimeoutMs()) .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, MyPreferences.getConnectionTimeoutMs()); return client; }
From source file:com.wrapp.android.webimage.ImageDownloader.java
public static boolean loadImage(final String imageKey, final URL imageUrl) { HttpEntity responseEntity = null;/*from w w w.ja va 2 s. c o m*/ InputStream contentInputStream = null; try { final String imageUrlString = imageUrl.toString(); if (imageUrlString == null || imageUrlString.length() == 0) { throw new Exception("Passed empty URL"); } LogWrapper.logMessage("Requesting image '" + imageUrlString + "'"); final HttpClient httpClient = new DefaultHttpClient(); final HttpParams httpParams = httpClient.getParams(); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, CONNECTION_TIMEOUT_IN_MS); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT_IN_MS); httpParams.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, DEFAULT_BUFFER_SIZE); final HttpGet httpGet = new HttpGet(imageUrlString); final HttpResponse response = httpClient.execute(httpGet); responseEntity = response.getEntity(); if (responseEntity == null) { throw new Exception("No response entity for image: " + imageUrl.toString()); } contentInputStream = responseEntity.getContent(); if (contentInputStream == null) { throw new Exception("No content stream for image: " + imageUrl.toString()); } Bitmap bitmap = BitmapFactory.decodeStream(contentInputStream); ImageCache.saveImageInFileCache(imageKey, bitmap); LogWrapper.logMessage("Downloaded image: " + imageUrl.toString()); bitmap.recycle(); } catch (IOException e) { LogWrapper.logException(e); return false; } catch (Exception e) { LogWrapper.logException(e); return false; } finally { try { if (contentInputStream != null) { contentInputStream.close(); } if (responseEntity != null) { responseEntity.consumeContent(); } } catch (IOException e) { LogWrapper.logException(e); } } return true; }
From source file:org.openrepose.core.services.httpclient.impl.HttpConnectionPoolProvider.java
public static HttpClient genClient(PoolType poolConf) { PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setDefaultMaxPerRoute(poolConf.getHttpConnManagerMaxPerRoute()); cm.setMaxTotal(poolConf.getHttpConnManagerMaxTotal()); //Set all the params up front, instead of mutating them? Maybe this matters HttpParams params = new BasicHttpParams(); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, poolConf.getHttpSocketTimeout()); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, poolConf.getHttpConnectionTimeout()); params.setParameter(CoreConnectionPNames.TCP_NODELAY, poolConf.isHttpTcpNodelay()); params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, poolConf.getHttpConnectionMaxHeaderCount()); params.setParameter(CoreConnectionPNames.MAX_LINE_LENGTH, poolConf.getHttpConnectionMaxLineLength()); params.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, poolConf.getHttpSocketBufferSize()); params.setBooleanParameter(CHUNKED_ENCODING_PARAM, poolConf.isChunkedEncoding()); final String uuid = UUID.randomUUID().toString(); params.setParameter(CLIENT_INSTANCE_ID, uuid); //Pass in the params and the connection manager DefaultHttpClient client = new DefaultHttpClient(cm, params); SSLContext sslContext = ProxyUtilities.getTrustingSslContext(); SSLSocketFactory ssf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = cm.getSchemeRegistry(); Scheme scheme = new Scheme("https", DEFAULT_HTTPS_PORT, ssf); registry.register(scheme);//from w ww .ja va 2 s .c o m client.setKeepAliveStrategy(new ConnectionKeepAliveWithTimeoutStrategy(poolConf.getKeepaliveTimeout())); LOG.info("HTTP connection pool {} with instance id {} has been created", poolConf.getId(), uuid); return client; }
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:org.red5.server.util.HttpConnectionUtil.java
/** * Returns a client with all our selected properties / params. * /* w w w .j a v a 2 s .c om*/ * @return client */ public static final DefaultHttpClient getClient() { // create a singular HttpClient object DefaultHttpClient client = new DefaultHttpClient(connectionManager); // dont retry client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); // get the params for the client HttpParams params = client.getParams(); // establish a connection within x seconds params.setParameter(CoreConnectionPNames.SO_TIMEOUT, connectionTimeout); // no redirects params.setParameter(ClientPNames.HANDLE_REDIRECTS, false); // set custom ua params.setParameter(CoreProtocolPNames.USER_AGENT, userAgent); // set the proxy if the user has one set if ((System.getProperty("http.proxyHost") != null) && (System.getProperty("http.proxyPort") != null)) { HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost").toString(), Integer.valueOf(System.getProperty("http.proxyPort"))); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } return client; }