List of usage examples for org.apache.http.params HttpConnectionParams setSoTimeout
public static void setSoTimeout(HttpParams httpParams, int i)
From source file:com.betfair.cougar.client.HttpClientExecutable.java
public void init() throws Exception { super.init(); // create client if not been set externally (e.g for testing) if (client == null) { client = new DefaultHttpClient(clientConnectionManager); ((DefaultHttpClient) client).setUserTokenHandler(userTokenHandler); }//from w w w .ja v a 2 s. co m // configure retryhandler if set if (retryHandler != null) { ((AbstractHttpClient) client).setHttpRequestRetryHandler(retryHandler); } // configure timeout if set if (connectTimeout != -1) { HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, connectTimeout); HttpConnectionParams.setSoTimeout(params, connectTimeout); } //Configure SSL - if relevant if (transportSSLEnabled) { KeyStoreManagement keyStore = KeyStoreManagement.getKeyStoreManagement(httpsKeystoreType, httpsKeystore, httpsKeyPassword); if (jmxControl != null && keyStore != null) { jmxControl.registerMBean("CoUGAR:name=HttpClientKeyStore,beanName=" + beanName, keyStore); } KeyStoreManagement trustStore = KeyStoreManagement.getKeyStoreManagement(httpsTruststoreType, httpsTruststore, httpsTrustPassword); if (jmxControl != null) { jmxControl.registerMBean("CoUGAR:name=HttpClientTrustStore,beanName=" + beanName, trustStore); } SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore != null ? keyStore.getKeyStore() : null, keyStore != null ? httpsKeyPassword : null, trustStore.getKeyStore()); if (hostnameVerificationDisabled) { socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); LOGGER.warn("CRITICAL SECURITY CHECKS ARE DISABLED: server SSL certificate hostname " + "verification is turned off."); } Scheme sch = new Scheme("https", extractPortFromAddress(), socketFactory); client.getConnectionManager().getSchemeRegistry().register(sch); } metrics = new HttpClientTransportMetrics(); if (jmxControl != null) { jmxControl.registerMBean("CoUGAR:name=HttpClientExecutable,beanName=" + beanName, this); } }
From source file:com.evernote.client.conn.mobile.TEvernoteHttpClient.java
@Deprecated public void setReadTimeout(int timeout) { HttpConnectionParams.setSoTimeout(httpParameters, timeout); }
From source file:com.jute.fed4j.engine.component.http.HttpDispatcherImpl_Jakarta.java
public void run(HttpComponent component) { this.commponent = component; HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, component.connectTimeout); HttpConnectionParams.setSoTimeout(params, component.readTimeout); try {/*from ww w. ja v a 2s . c o m*/ this.init(component); HttpClient httpclient = new MyHttpClient( getConnectionManager(params, component.enablePersistentConnection), params); if (component.enableProxy && "http".equals(component.proxyType)) { HttpHost proxy = new HttpHost(component.proxyHost, component.proxyPort, component.proxyType); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } HttpUriRequest request = new HttpRequest(component.method, component.uri); MyHttpResponseHandler responseHandler = new MyHttpResponseHandler(component.responseCharset); String body = httpclient.execute(request, responseHandler); this.onResponse(component, responseHandler.code, body); } catch (SocketTimeoutException e) { onException(component, -2, " socket timeout error occurs: " + e.getMessage()); } catch (ClientProtocolException e) { onException(component, -3, " error resposed from server: " + e.getMessage()); } catch (IOException e) { onException(component, -4, " error occurs during dispatch: " + e.getMessage()); } catch (Exception e) { onException(component, -5, "error occurs during parsing xml:" + e.getMessage()); } }
From source file:me.pjq.benchmark.AndroidHttpClient.java
/** * Create a new HttpClient with reasonable defaults (which you can update). * * @param userAgent to report in your HTTP requests. * @param sessionCache persistent session cache * @return AndroidHttpClient for you to use for all your requests. *//* w ww . jav a2 s. co m*/ public static AndroidHttpClient newInstance(String userAgent)/*, SSLClientSessionCache sessionCache) */ { 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); // 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)); // schemeRegistry.register(new Scheme("https", // socketFactoryWithCache(sessionCache), 443)); ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); // DhcpInfo info = new DhcpInfo(); // UVANLogger.getInstance().d("Server", info.toString()); //to do waiting for a while // HttpHost host = UVANApplication.getHttpProxy(); // if (host==null){ // host = new HttpHost("0.0.0.0"); // } // HttpRoute route = new HttpRoute(host); // // Object object = new Object(); // try { // ManagedClientConnection managedClientConnection = manager.requestConnection(route, object).getConnection(20 * 1000, TimeUnit.MILLISECONDS); // managedClientConnection.setIdleDuration(5 * 60 * 1000, TimeUnit.MILLISECONDS); // } catch (ConnectionPoolTimeoutException e) { // e.printStackTrace(); // } catch (InterruptedException e) { // e.printStackTrace(); // } // 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:de.escidoc.core.common.business.indexing.GsearchHandler.java
@SuppressWarnings("unused") @PostConstruct/*from w w w .j av a2 s . c om*/ private void init() { // setup HttpClient configuration HttpConnectionParams.setSoTimeout(gSearchDefaultParams, EscidocConfiguration.getInstance() .getAsInt(EscidocConfiguration.INDEXER_REQUEST_TIMEOUT, Constants.REQUEST_TIMEOUT)); // load gSearch configuration final EscidocConfiguration config = EscidocConfiguration.getInstance(); if (config != null) { final String gsearchUrl = config.get(EscidocConfiguration.GSEARCH_URL); if (gsearchUrl != null) { try { this.gsearchUrl = new URL(gsearchUrl); } catch (final MalformedURLException e) { LOGGER.error(INITIALIZATION_ERROR_MSG, e); } } else { if (LOGGER.isErrorEnabled()) { LOGGER.error(INITIALIZATION_ERROR_MSG + " Property " + EscidocConfiguration.GSEARCH_URL + " is not set."); } } } else { if (LOGGER.isErrorEnabled()) { LOGGER.error(INITIALIZATION_ERROR_MSG + " No configuration available."); } } }
From source file:CB_Core.GCVote.GCVote.java
private static String Execute(HttpRequestBase httprequest) throws IOException, ClientProtocolException { httprequest.setHeader("Content-type", "application/x-www-form-urlencoded"); // httprequest.setHeader("UserAgent", "cachebox"); int conectionTimeout = CB_Core_Settings.conection_timeout.getValue(); int socketTimeout = CB_Core_Settings.socket_timeout.getValue(); // Execute HTTP Post Request String result = ""; HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. // The default value is zero, that means the timeout is not used. HttpConnectionParams.setConnectionTimeout(httpParameters, conectionTimeout); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(httpParameters, socketTimeout); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); HttpResponse response = httpClient.execute(httprequest); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { result += line + "\n"; }/*from w ww . j ava 2 s .c o m*/ return result; }
From source file:com.taqueue.connection.QueueConnectionManager.java
/** * Sends a POST to the queue with the parameters nvps, returns the result. * @param nvps the NameValuePair of parameters to be sent to the queue server * @return ConnectionResult containing the status code for the attempt and the message returned * message will be null iff the status is not OK */// w ww.j ava2 s .c o m private ConnectionResult sendMessage(List<NameValuePair> nvps) { ConnectionResult res = new ConnectionResult(); //default to OK, we'll change in the event of an error res.status = ConnectionStatus.OK; HttpPost post = new HttpPost(HOST + PATH); //DefaultHttpClient client = new DefaultHttpClient(); //set up the timeout HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIMEOUT); // set up the connection manager if needed if (manager == null) { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); manager = new ThreadSafeClientConnManager(httpParams, registry); } DefaultHttpClient client = new DefaultHttpClient(manager, httpParams); try { //set up our POST values post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); //send it along ResponseHandler<String> handler = new BasicResponseHandler(); connectionWatcher watcher = new connectionWatcher(post); Thread t = new Thread(watcher); t.start(); res.message = client.execute(post, handler); watcher.finished(); //and clean up //if any exceptions are thrown return a connection error result } catch (Exception e) { res.status = ConnectionStatus.CONNECTION_ERROR; res.message = null; } finally { post.abort(); } return res; }