List of usage examples for org.apache.http.params HttpConnectionParams setConnectionTimeout
public static void setConnectionTimeout(HttpParams httpParams, int i)
From source file:com.photon.phresco.nativeapp.eshop.net.HttpRequest.java
/** * Send the JSON data to specified URL and get the httpResponse back * * @param sURL/*from www.j a v a 2 s.c om*/ * @param jObject * @return InputStream * @throws IOException */ public static InputStream post(String sURL, JSONObject jObject) throws IOException { HttpResponse httpResponse = null; InputStream is = null; PhrescoLogger.info(TAG + " post: " + sURL); PhrescoLogger.info(TAG + " jObject: " + jObject); HttpPost httpPostRequest = new HttpPost(sURL); HttpEntity entity; httpPostRequest.setHeader("Accept", "application/json"); httpPostRequest.setHeader(HTTP.CONTENT_TYPE, "application/json"); httpPostRequest.setEntity(new ByteArrayEntity(jObject.toString().getBytes("UTF-8"))); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = TIME_OUT; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = TIME_OUT; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); httpResponse = httpClient.execute(httpPostRequest); if (httpResponse != null) { entity = httpResponse.getEntity(); is = entity.getContent(); } return is; }
From source file:com.puppetlabs.puppetdb.javaclient.impl.DefaultModule.java
/** * Provides a HttpClient that is configured with the preferences of this module and the * injected <code>sslSocketFactory</code>. * /*from w w w .j a v a 2s .co m*/ * @param sslSocketFactory * The injected SSL socket factory * @return The new HttpClient instance */ @Provides public HttpClient provideHttpClient(SSLSocketFactory sslSocketFactory) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, preferences.getConnectTimeout()); HttpConnectionParams.setSoTimeout(params, preferences.getSoTimeout()); DefaultHttpClient httpClient = new DefaultHttpClient(params); if (preferences.getCertPEM() != null) httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme("https", 443, sslSocketFactory)); return httpClient; }
From source file:com.android.i18n.addressinput.AndroidAsyncRequestApi.java
@Override public void requestObject(String url, AsyncCallback callback, int timeoutMillis) { HttpParams params = CLIENT.getParams(); HttpConnectionParams.setConnectionTimeout(params, timeoutMillis); HttpConnectionParams.setSoTimeout(params, timeoutMillis); HttpUriRequest request = new HttpGet(encodeUrl(url)); (new AsyncHttp(request, callback)).start(); }
From source file:org.ednovo.goorusearchwidget.WebService.java
public WebService(String serviceName) { HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, 10000); HttpConnectionParams.setSoTimeout(myParams, 10000); httpClient = new DefaultHttpClient(myParams); localContext = new BasicHttpContext(); webServiceUrl = serviceName;/*from ww w . j ava2 s . c om*/ }
From source file:org.apache.tuscany.sca.host.http.client.HttpClientFactory.java
public HttpClient createHttpClient() { HttpParams defaultParameters = new BasicHttpParams(); //defaultParameters.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 10); ConnManagerParams.setMaxTotalConnections(defaultParameters, 1024); ConnPerRoute connPerRoute = new ConnPerRouteBean(256); ConnManagerParams.setMaxConnectionsPerRoute(defaultParameters, connPerRoute); HttpProtocolParams.setContentCharset(defaultParameters, HTTP.UTF_8); HttpConnectionParams.setConnectionTimeout(defaultParameters, 60000); HttpConnectionParams.setSoTimeout(defaultParameters, 60000); SchemeRegistry supportedSchemes = new SchemeRegistry(); supportedSchemes/*from www.j a va2s .c o m*/ .register(new Scheme(HttpHost.DEFAULT_SCHEME_NAME, PlainSocketFactory.getSocketFactory(), 80)); supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(defaultParameters, supportedSchemes); return new DefaultHttpClient(connectionManager, defaultParameters); }
From source file:com.sumologic.logback.SumoLogicAppender.java
@Override public void start() { super.start(); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, connectionTimeout); HttpConnectionParams.setSoTimeout(params, socketTimeout); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(), params); }
From source file:com.dahl.brendan.wordsearch.util.AndroidHttpClient.java
/** * Create a new HttpClient with reasonable defaults (which you can update). * * @param userAgent to report in your HTTP requests. * @return AndroidHttpClient for you to use for all your requests. *//* www.ja va 2s . com*/ public static AndroidHttpClient newInstance(String userAgent) { HttpParams params = new BasicHttpParams(); // Turn off stale checking. Our connections break all the time anyway, // and it's not worth it to pay the penalty of checking every time. HttpConnectionParams.setStaleCheckingEnabled(params, false); // Default connection and socket timeout of 20 seconds. Tweak to taste. HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpConnectionParams.setSoTimeout(params, 20 * 1000); HttpConnectionParams.setSocketBufferSize(params, 8192); // Don't handle redirects -- return them to the caller. Our code // often wants to re-POST after a redirect, which we must do ourselves. HttpClientParams.setRedirecting(params, false); HttpClientParams.setAuthenticating(params, false); // Set the specified user agent and register standard protocols. HttpProtocolParams.setUserAgent(params, userAgent); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); // We use a factory method to modify superclass initialization // parameters without the funny call-a-static-method dance. return new AndroidHttpClient(manager, params); }
From source file:org.apache.tomcat.maven.it.AbstractWarProjectIT.java
@Before public void setUp() throws Exception { httpClient = new DefaultHttpClient(); final HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, getTimeout()); HttpConnectionParams.setSoTimeout(params, getTimeout()); webappHome = ResourceExtractor.simpleExtractResources(getClass(), "/" + getWarArtifactId()); verifier = new Verifier(webappHome.getAbsolutePath()); boolean debugVerifier = Boolean.getBoolean("verifier.maven.debug"); verifier.setMavenDebug(debugVerifier); verifier.setDebugJvm(Boolean.getBoolean("verifier.debugJvm")); verifier.displayStreamBuffers();/*from w w w. ja va2 s . c o m*/ verifier.deleteArtifact("org.apache.tomcat.maven.it", getWarArtifactId(), "1.0-SNAPSHOT", "war"); }
From source file:com.emc.vipr.services.s3.ViPRS3HttpClient.java
public ViPRS3HttpClient(ViPRS3Config viprConfig) { super(viprConfig.getClientConfiguration(), new SmartHttpClient(viprConfig.toSmartClientConfig()), null); ClientConfiguration azConfig = viprConfig.getClientConfiguration(); HttpParams httpClientParams = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(httpClientParams, azConfig.getConnectionTimeout()); HttpConnectionParams.setSoTimeout(httpClientParams, azConfig.getSocketTimeout()); HttpConnectionParams.setStaleCheckingEnabled(httpClientParams, true); HttpConnectionParams.setTcpNoDelay(httpClientParams, true); int socketSendBufferSizeHint = azConfig.getSocketBufferSizeHints()[0]; int socketReceiveBufferSizeHint = azConfig.getSocketBufferSizeHints()[1]; if (socketSendBufferSizeHint > 0 || socketReceiveBufferSizeHint > 0) { HttpConnectionParams.setSocketBufferSize(httpClientParams, Math.max(socketSendBufferSizeHint, socketReceiveBufferSizeHint)); }/* www.j a v a 2s . c om*/ ClientConnectionManager connectionManager = httpClient.getConnectionManager(); ((SmartHttpClient) httpClient).setRedirectStrategy(new LocationHeaderNotRequiredRedirectStrategy()); try { Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory()); SSLSocketFactory sf = new SSLSocketFactory(SSLContext.getDefault(), SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", 443, sf); SchemeRegistry sr = connectionManager.getSchemeRegistry(); sr.register(http); sr.register(https); } catch (NoSuchAlgorithmException e) { throw new AmazonClientException("Unable to access default SSL context", e); } /* * If SSL cert checking for endpoints has been explicitly disabled, * register a new scheme for HTTPS that won't cause self-signed certs to * error out. */ if (System.getProperty(SDKGlobalConfiguration.DISABLE_CERT_CHECKING_SYSTEM_PROPERTY) != null) { Scheme sch = new Scheme("https", 443, new TrustingSocketFactory()); httpClient.getConnectionManager().getSchemeRegistry().register(sch); } /* Set proxy if configured */ String proxyHost = azConfig.getProxyHost(); int proxyPort = azConfig.getProxyPort(); if (proxyHost != null && proxyPort > 0) { log.info("Configuring Proxy. Proxy Host: " + proxyHost + " " + "Proxy Port: " + proxyPort); HttpHost proxyHttpHost = new HttpHost(proxyHost, proxyPort); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHttpHost); String proxyUsername = azConfig.getProxyUsername(); String proxyPassword = azConfig.getProxyPassword(); String proxyDomain = azConfig.getProxyDomain(); String proxyWorkstation = azConfig.getProxyWorkstation(); if (proxyUsername != null && proxyPassword != null) { ((SmartHttpClient) httpClient).getCredentialsProvider().setCredentials( new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUsername, proxyPassword, proxyWorkstation, proxyDomain)); } // Add a request interceptor that sets up proxy authentication pre-emptively if configured if (azConfig.isPreemptiveBasicProxyAuth()) { ((SmartHttpClient) httpClient).addRequestInterceptor(new PreemptiveProxyAuth(proxyHttpHost), 0); } } }
From source file:eu.trentorise.smartcampus.portfolio.utils.HttpClientFactory.java
private final HttpClient createHttpClient() { HttpParams httpParams = new BasicHttpParams(); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParams, HTTP.DEFAULT_CONTENT_CHARSET); SchemeRegistry schemeRegistry = new SchemeRegistry(); Scheme httpScheme = new Scheme(HTTP_SCHEMA, PlainSocketFactory.getSocketFactory(), 80); schemeRegistry.register(httpScheme); Scheme httpsScheme = new Scheme(HTTPS_SCHEMA, SSLSocketFactory.getSocketFactory(), 443); schemeRegistry.register(httpsScheme); ClientConnectionManager tsConnManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry); HttpClient client = new DefaultHttpClient(tsConnManager, httpParams); HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT); HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT); return client; }