List of usage examples for org.apache.http.params HttpConnectionParams setConnectionTimeout
public static void setConnectionTimeout(HttpParams httpParams, int i)
From source file:org.droidparts.http.worker.HttpClientWorker.java
public HttpClientWorker(String userAgent) { super(userAgent); httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpClientParams.setRedirecting(params, false); HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params, BUFFER_SIZE); HttpClientParams.setCookiePolicy(params, BROWSER_COMPATIBILITY); if (userAgent != null) { HttpProtocolParams.setUserAgent(params, userAgent); }/* w w w . jav a2s . c o m*/ }
From source file:com.hoccer.api.RESTfulApiTest.java
public RESTfulApiTest() { BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 3000); ConnManagerParams.setMaxTotalConnections(httpParams, 100); HttpConnectionParams.setStaleCheckingEnabled(httpParams, true); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); mHttpClient = new HttpClientWithKeystore(cm, httpParams); }
From source file:es.uja.photofirma.android.DoConnection.java
/** * /*from www . ja va 2s.co m*/ * @return DefaultHttpClient(ccm, params) */ public HttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); //aado timeout HttpConnectionParams.setConnectionTimeout(params, 6000); //timeout en establecer conexion HttpConnectionParams.setSoTimeout(params, 10000); //timeout en recibir respuesta SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:org.openremote.android.console.net.ORControllerServerSwitcher.java
/** * Detect the groupmembers of current server url */// www. j a v a2 s . co m public static boolean detectGroupMembers(Context context) { Log.i(LOG_CATEGORY, "Detecting group members with current controller server url " + AppSettingsModel.getCurrentServer(context)); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 5 * 1000); HttpConnectionParams.setSoTimeout(params, 5 * 1000); HttpClient httpClient = new DefaultHttpClient(params); String url = AppSettingsModel.getSecuredServer(context); HttpGet httpGet = new HttpGet(url + "/rest/servers"); if (httpGet == null) { Log.e(LOG_CATEGORY, "Create HttpRequest fail."); return false; } SecurityUtil.addCredentialToHttpRequest(context, httpGet); // TODO : fix the exception handling in this method -- it is ridiculous. try { URL uri = new URL(url); if ("https".equals(uri.getProtocol())) { Scheme sch = new Scheme(uri.getProtocol(), new SelfCertificateSSLSocketFactory(context), uri.getPort()); httpClient.getConnectionManager().getSchemeRegistry().register(sch); } HttpResponse httpResponse = httpClient.execute(httpGet); try { if (httpResponse.getStatusLine().getStatusCode() == Constants.HTTP_SUCCESS) { InputStream data = httpResponse.getEntity().getContent(); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document dom = builder.parse(data); Element root = dom.getDocumentElement(); NodeList nodeList = root.getElementsByTagName("server"); int nodeNums = nodeList.getLength(); List<String> groupMembers = new ArrayList<String>(); for (int i = 0; i < nodeNums; i++) { groupMembers.add(nodeList.item(i).getAttributes().getNamedItem("url").getNodeValue()); } Log.i(LOG_CATEGORY, "Detected groupmembers. Groupmembers are " + groupMembers); return saveGroupMembersToFile(context, groupMembers); } catch (IOException e) { Log.e(LOG_CATEGORY, "The data is from ORConnection is bad", e); } catch (ParserConfigurationException e) { Log.e(LOG_CATEGORY, "Cant build new Document builder", e); } catch (SAXException e) { Log.e(LOG_CATEGORY, "Parse data error", e); } } else { Log.e(LOG_CATEGORY, "detectGroupMembers Parse data error"); } } catch (IllegalStateException e) { Log.e(LOG_CATEGORY, "detectGroupMembers Parse data error", e); } catch (IOException e) { Log.e(LOG_CATEGORY, "detectGroupMembers Parse data error", e); } } catch (MalformedURLException e) { Log.e(LOG_CATEGORY, "Create URL fail:" + url); } catch (ConnectException e) { Log.e(LOG_CATEGORY, "Connection refused: " + AppSettingsModel.getCurrentServer(context), e); } catch (ClientProtocolException e) { Log.e(LOG_CATEGORY, "Can't Detect groupmembers with current controller server " + AppSettingsModel.getCurrentServer(context), e); } catch (SocketTimeoutException e) { Log.e(LOG_CATEGORY, "Can't Detect groupmembers with current controller server " + AppSettingsModel.getCurrentServer(context), e); } catch (IOException e) { Log.e(LOG_CATEGORY, "Can't Detect groupmembers with current controller server " + AppSettingsModel.getCurrentServer(context), e); } catch (IllegalArgumentException e) { Log.e(LOG_CATEGORY, "Host name can be null :" + AppSettingsModel.getCurrentServer(context), e); } return false; }
From source file:com.algos.droidactivator.BackendRequest.java
public HttpResponse execute() { HttpResponse response = null;//from w w w . j a v a 2 s.c o m // create an HTTP Client AndroidHttpClient client = AndroidHttpClient.newInstance("droidactivator"); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, connTimeout); HttpConnectionParams.setSoTimeout(params, socketTimeout); // create an HTTPGet request HttpGet request = new HttpGet(DroidActivator.getBackendURI()); //HttpPost request = new HttpPost(DroidActivator.getBackendURI()); // add request headers for (Entry<String, String> entry : this.properties.entrySet()) { request.setHeader(entry.getKey(), entry.getValue()); } // obtain a response try { response = client.execute(request); } catch (IOException e) { e.printStackTrace(); } client.close(); return response; }
From source file:com.eTilbudsavis.etasdk.network.impl.DefaultHttpNetwork.java
public HttpResponse performNetworking(Request<?> request) throws ClientProtocolException, IOException { // Start the interwebs work stuff DefaultHttpClient httpClient = new DefaultHttpClient(); request.addEvent("set-apache-routeplanner"); setHostNameVerifierAndRoutePlanner(httpClient); // Set timeouts request.addEvent(String.format("set-connection-timeout-%s", request.getTimeOut() * 2)); HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), request.getTimeOut()); HttpConnectionParams.setSoTimeout(httpClient.getParams(), request.getTimeOut()); // Get the right request type, and set body if necessary HttpRequestBase httpRequest = createRequest(request); setHeaders(request, httpRequest);/* w ww. java2 s . c om*/ request.addEvent("performing-http-request"); return httpClient.execute(httpRequest); }
From source file:kks.lib.helper.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. *//*from w ww .ja va2s . c om*/ public static AndroidHttpClient newInstance(String userAgent, int timeout) { 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, timeout); HttpConnectionParams.setSoTimeout(params, timeout); 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.jhlibrary.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. *///from w ww.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); // 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", new EasySSLSocketFactory(), 443)); //TODO schemeRegistry.register(new Scheme("mxiss", new EasySSLSocketFactory(), 8443)); 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:eu.geopaparazzi.library.routing.osmbonuspack.HttpConnection.java
public HttpConnection() { stream = null;// w ww .j av a2s .c o m entity = null; HttpParams httpParameters = new BasicHttpParams(); /* useful? HttpProtocolParams.setContentCharset(httpParameters, "UTF-8"); HttpProtocolParams.setHttpElementCharset(httpParameters, "UTF-8"); */ // Set the timeout in milliseconds until a connection is established. HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT_CONNECTION); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT_SOCKET); client = new DefaultHttpClient(httpParameters); //TODO: created here. Reuse to do for better perfs???... }
From source file:playn.android.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. *//*from ww w . ja v a2 s . c o m*/ 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); }