List of usage examples for org.apache.http.params HttpConnectionParams setConnectionTimeout
public static void setConnectionTimeout(HttpParams httpParams, int i)
From source file:org.openiot.gsn.http.rest.RestRemoteWrapper.java
private HttpParams getHttpClientParams(int timeout) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); HttpConnectionParams.setTcpNoDelay(params, false); HttpConnectionParams.setSocketBufferSize(params, 8192); HttpConnectionParams.setStaleCheckingEnabled(params, true); HttpConnectionParams.setConnectionTimeout(params, 30 * 1000); // Set the connection time to 30s HttpConnectionParams.setSoTimeout(params, timeout); HttpProtocolParams.setUserAgent(params, "GSN-HTTP-CLIENT"); return params; }
From source file:com.networkmanagerapp.RestartWifi.java
/** * Requests the restart of WIFI in the background * @param arg0 the data to process in the background * @throws IOException caught locally. Catch throws NullPointerException, also caught internally. *//*from w w w . j a v a 2 s . c o m*/ @Override protected void onHandleIntent(Intent arg0) { mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); showNotification(); try { String password = PreferenceManager.getDefaultSharedPreferences(this).getString("password_preference", ""); String ip = PreferenceManager.getDefaultSharedPreferences(this).getString("ip_preference", "192.168.1.1"); String enc = URLEncoder.encode(ip, "utf-8"); String scriptUrl = "http://" + enc + ":1080/cgi-bin/wifi.sh"; HttpParams httpParams = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(httpParams, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 5000; HttpConnectionParams.setSoTimeout(httpParams, timeoutSocket); HttpHost targetHost = new HttpHost(enc, 1080, "http"); DefaultHttpClient client = new DefaultHttpClient(httpParams); client.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("root", password)); HttpGet request = new HttpGet(scriptUrl); client.execute(targetHost, request); } catch (IOException ex) { try { Log.e("Network Manager reboot", ex.getLocalizedMessage()); } catch (NullPointerException e) { Log.e("Network Manager reboot", "Rebooting, " + e.getLocalizedMessage()); } } finally { mNM.cancel(R.string.wifi_service_restarted); stopSelf(); } }
From source file:net.bither.image.http.BaseHttpResponse.java
private DefaultHttpClient getThreadSafeHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); ClientConnectionManager mgr = httpClient.getConnectionManager(); HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HttpSetting.HTTP_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, HttpSetting.HTTP_SO_TIMEOUT); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);//from www . java 2s. c om return httpClient; }
From source file:com.android.volley.toolbox.HttpClientStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders); addHeaders(httpRequest, additionalHeaders); addHeaders(httpRequest, request.getHeaders()); onPrepareRequest(httpRequest);/*from w w w. j av a 2s . c om*/ HttpParams httpParams = httpRequest.getParams(); int timeoutMs = request.getTimeoutMs(); // TODO: Reevaluate this connection timeout based on more wide-scale // data collection and possibly different for wifi vs. 3G. HttpConnectionParams.setConnectionTimeout(httpParams, 5000); HttpConnectionParams.setSoTimeout(httpParams, timeoutMs); return mClient.execute(httpRequest); }
From source file:org.xwiki.android.authenticator.rest.XWikiConnector.java
/** * Configures the httpClient to connect to the URL provided. *//*from w ww . j a v a 2 s .c o m*/ public static HttpClient getHttpClient() { HttpClient httpClient = new DefaultHttpClient(); final HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS); ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS); return httpClient; }
From source file:com.applicake.beanstalkclient.utils.AndroidHttpClient.java
/** * Create a new HttpClient with reasonable defaults (which you can update). * /* w w w . j a v a 2 s . c o m*/ * @param userAgent * to report in your HTTP requests. * @param sessionCache * persistent session cache * @return AndroidHttpClient for you to use for all your requests. */ 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); // 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:com.idsmanager.eagleeye.net.UploadHttpStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { //create post http request HttpPost httpPost = new HttpPost(request.getUrl()); httpPost.setEntity(((IDsManagerMultiPartRequest) request).getEntity()); addHeaders(httpPost, additionalHeaders); addHeaders(httpPost, request.getHeaders()); onPrepareRequest(httpPost);/*from w w w . jav a2 s .c om*/ HttpParams httpParams = httpPost.getParams(); int timeoutMs = request.getTimeoutMs(); HttpConnectionParams.setConnectionTimeout(httpParams, 50000); HttpConnectionParams.setSoTimeout(httpParams, timeoutMs); /* Register schemes, HTTP and HTTPS */ SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory sslSocketFactory; if (mIsConnectingToYourServer) { sslSocketFactory = MySSLSocketFactory.getFixedSocketFactory(); } else { sslSocketFactory = SSLSocketFactory.getSocketFactory(); } registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sslSocketFactory, 443)); /* Make a thread safe connection manager for the client */ ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(httpParams, registry); HttpClient httpClient = new DefaultHttpClient(manager, httpParams); return httpClient.execute(httpPost); }
From source file:com.ihongqiqu.util.LocationUtils.java
/** * ????// w w w. j av a 2 s . co m * * @param longitude ? * @param latitude * @param lang ?en * @return ?? * @throws Exception */ public static String getAddress(double longitude, double latitude, String lang) throws Exception { if (DEBUG) { LogUtils.d(TAG, "location : (" + longitude + "," + latitude + ")"); } if (lang == null) { lang = "en"; } // HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 10 * 1000); HttpConnectionParams.setSoTimeout(params, 10 * 1000); // HttpClient???? HttpClient client = new DefaultHttpClient(params); // ????GET HttpGet httpGet = new HttpGet("https://maps.googleapis.com/maps/api/" + "geocode/json?latlng=" + latitude + "," + longitude + "&sensor=false&language=" + lang); if (DEBUG) { LogUtils.d(TAG, "URL : " + httpGet.getURI()); } StringBuilder sb = new StringBuilder(); // HttpResponse response = client.execute(httpGet); HttpEntity entity = response.getEntity(); // ??? InputStream stream = entity.getContent(); int b; while ((b = stream.read()) != -1) { sb.append((char) b); } // ??JSONObject JSONObject jsonObj = new JSONObject(sb.toString()); Log.d("ConvertUtil", "getAddress:" + sb.toString()); // ???? JSONObject addressObject = jsonObj.getJSONArray("results").getJSONObject(0); String address = decodeLocationName(addressObject); if (DEBUG) { LogUtils.d(TAG, "address : " + address); } return address; }
From source file:uk.ac.ebi.phenotype.web.util.BioMartBot.java
/** * URL to request. /*from w w w .j a v a 2 s . c o m*/ * @param url */ public void initConnection(String url) { // Create a new HttpClient and Post Header final HttpParams httpParams = new BasicHttpParams(); // httpclient.getParams().setParameter("http.socket.timeout", new Integer(1000)); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIME_OUT); HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIME_OUT); httpclient = new DefaultHttpClient(httpParams); // check system properties for proxy settings if (System.getProperty("http.proxyHost") != null && System.getProperty("http.proxyPort") != null) { HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")), "http"); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else if (System.getProperty("HTTP_PROXY_HOST") != null && System.getProperty("HTTP_PROXY_PORT") != null) { log.info("Using proxy settings:\t" + System.getProperty("HTTP_PROXY_HOST") + "\t" + System.getProperty("HTTP_PROXY_PORT")); HttpHost proxy = new HttpHost(System.getProperty("HTTP_PROXY_HOST"), Integer.parseInt(System.getProperty("HTTP_PROXY_PORT")), "http"); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } httppost = new HttpPost(url); }
From source file:info.ajaxplorer.client.http.RestRequest.java
public void setTimeout(int timeoutMillis) { HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), timeoutMillis); }