List of usage examples for org.apache.http.params HttpConnectionParams setConnectionTimeout
public static void setConnectionTimeout(HttpParams httpParams, int i)
From source file:org.elegosproject.romupdater.DownloadManager.java
public static boolean sendAnonymousData() { String link = "http://www.elegosproject.org/android/upload.php"; String data;// ww w . j a v a 2 s . c o m SharedData shared = SharedData.getInstance(); String romName = shared.getRepositoryROMName(); String romVersion = shared.getDownloadVersion(); String romPhone = shared.getRepositoryModel(); String romRepository = shared.getRepositoryUrl(); if (romName.equals("") || romVersion.equals("") || romPhone.equals("") || romRepository.equals("")) { Log.e(TAG, "Internal error - missing system variables."); return false; } if (!checkHttpFile(link)) return false; try { data = URLEncoder.encode("phone", "UTF-8") + "=" + URLEncoder.encode(romPhone, "UTF-8"); data += "&" + URLEncoder.encode("rom_name", "UTF-8") + "=" + URLEncoder.encode(romName, "UTF-8"); data += "&" + URLEncoder.encode("rom_version", "UTF-8") + "=" + URLEncoder.encode(romVersion, "UTF-8"); data += "&" + URLEncoder.encode("rom_repository", "UTF-8") + "=" + URLEncoder.encode(romRepository, "UTF-8"); HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 3000); URL url = new URL(link); url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "ROMUpdater"); conn.setDoOutput(true); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.println(data); out.close(); int status = Integer.parseInt(conn.getHeaderField("ROMUpdater-status")); if (status == 1) return true; Log.e(TAG, "It was impossible to send data to the stastistics server (" + conn.getHeaderField("ROMUpdater-error") + ")."); return false; } catch (Exception e) { Log.e(TAG, "It was impossible to send data to the stastistics server."); Log.e(TAG, "Error: " + e.toString()); return false; } }
From source file:net.ccghe.emocha.async.UploadOneFile.java
public UploadOneFile(String path, String serverURL, FileTransmitter transmitter, MultipartEntity postData) { // configure connection HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 20 * Constants.ONE_SECOND); HttpConnectionParams.setSoTimeout(params, 20 * Constants.ONE_SECOND); HttpClientParams.setRedirecting(params, false); // setup client DefaultHttpClient client = new DefaultHttpClient(params); HttpPost post = new HttpPost(serverURL); int id = 0;/*w w w .java 2 s .co m*/ postData.addPart("file" + id, new FileBody(new File(path))); try { postData.addPart("path" + id, new StringBody(path)); } catch (UnsupportedEncodingException e1) { Log.e(Constants.LOG_TAG, "Encoding error while uploading file."); } // prepare response and return uploaded try { post.setEntity(postData); HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); String jsonResponse = Server.convertStreamToString(stream); stream.close(); if (postData != null) { postData.consumeContent(); } JSONObject jObject = new JSONObject(jsonResponse); Long ok = jObject.getLong("ok"); if (ok > 0) { DBAdapter.markAsUploaded(path); Log.i(Constants.LOG_TAG, "Mark as uploaded: " + path); } else { Log.e(Constants.LOG_TAG, "Error uploading: " + path + " (json response not ok)"); } } catch (ClientProtocolException e) { Log.e("EMOCHA", "ClientProtocolException ERR. " + e.getMessage()); } catch (IOException e) { Log.e("EMOCHA", "IOException ERR. " + e.getMessage()); } catch (Exception e) { Log.e("EMOCHA", "Exception ERR. " + e.getMessage()); } /* // check response. // TODO: This isn't handled correctly. String serverLocation = null; Header[] h = response.getHeaders("Location"); if (h != null && h.length > 0) { serverLocation = h[0].getValue(); } else { // something should be done here... Log.e(Constants.LOG_TAG, "Location header was absent"); } int responseCode = response.getStatusLine().getStatusCode(); Log.e(Constants.LOG_TAG, "Response code:" + responseCode); // verify that your response came from a known server if (serverLocation != null && serverURL.contains(serverLocation) && responseCode == 201) { DBAdapter.markAsUploaded(path); } */ transmitter.transmitComplete(); }
From source file:net.alchemiestick.katana.winehqappdb.Metrics.java
@Override protected void onPreExecute() { try {//from www.j av a 2 s.c o m httpClient = AndroidHttpClient.newInstance("WineHQ/1.0 App Browser"); HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), TIMEOUT_MS); HttpConnectionParams.setSoTimeout(httpClient.getParams(), TIMEOUT_MS); } catch (Exception e) { } }
From source file:eu.masconsult.bgbanking.banks.fibank.ebanking.EFIBankClient.java
/** * Configures the httpClient to connect to the URL provided. *//*from w ww . j ava 2 s.c o m*/ private static DefaultHttpClient getHttpClient() { DefaultHttpClient 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); httpClient.addRequestInterceptor(new DumpHeadersRequestInterceptor()); httpClient.addResponseInterceptor(new DumpHeadersResponseInterceptor()); return httpClient; }
From source file:com.dimasdanz.kendalipintu.util.JSONParser.java
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { try {// ww w . j a va 2s .c o m HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(httpParameters, so_timeout); HttpConnectionParams.setConnectionTimeout(httpParameters, co_timeout); if (method == "POST") { DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if (method == "GET") { DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (SocketTimeoutException e) { Log.e("SocketTimeoutException", "SocketTimeoutException"); e.printStackTrace(); return null; } catch (UnsupportedEncodingException e) { Log.e("UnsupportedEncodingException", "UnsupportedEncodingException"); e.printStackTrace(); return null; } catch (ClientProtocolException e) { Log.e("ClientProtocolException", "ClientProtocolException"); e.printStackTrace(); return null; } catch (IOException e) { Log.e("IOException", "IOException"); e.printStackTrace(); return null; } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Buffer Error : " + e.toString()); return null; } try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); return null; } return jObj; }
From source file:io.personium.core.utils.HttpClientFactory.java
/** * HTTPClient?.//from w w w .j a va 2 s .c om * @param type * @return ???HttpClient */ public static HttpClient create(final String type) { if (TYPE_DEFAULT.equalsIgnoreCase(type)) { return new DefaultHttpClient(); } SSLSocketFactory sf = null; try { if (TYPE_INSECURE.equalsIgnoreCase(type)) { sf = createInsecureSSLSocketFactory(); } } catch (Exception e) { return null; } SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", PORTHTTPS, sf)); schemeRegistry.register(new Scheme("http", PORTHTTP, PlainSocketFactory.getSocketFactory())); HttpParams params = new BasicHttpParams(); ClientConnectionManager cm = new SingleClientConnManager(schemeRegistry); // ClientConnectionManager cm = new // ThreadSafeClientConnManager(schemeRegistry); HttpClient hc = new DefaultHttpClient(cm, params); HttpParams params2 = hc.getParams(); int timeout = TIMEOUT; HttpConnectionParams.setConnectionTimeout(params2, timeout); // ? HttpConnectionParams.setSoTimeout(params2, timeout); // ?? return hc; }
From source file:com.liuguangqiang.download.core.AsyncDownload.java
private void init() { mDownloadQueue = new DownloadQueue(); executorService = mConfiguration.executorService; mHttpClient = AndroidHttpClient.newInstance(Constants.USER_AGENT); mHttpParams = mHttpClient.getParams(); mHttpParams.setParameter(ClientPNames.HANDLE_REDIRECTS, true); HttpConnectionParams.setConnectionTimeout(mHttpParams, mConfiguration.connectionTimeout); HttpConnectionParams.setSoTimeout(mHttpParams, mConfiguration.socketTimeout); }
From source file:com.zekke.services.http.RequestBuilder.java
public RequestBuilder(String url) { httpClient = new DefaultHttpClient(); HttpParams httpParams = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, DEFAULT_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_TIMEOUT); formParams = new ArrayList<NameValuePair>(0); headers = new ArrayList<BasicHeader>(0); this.url = url; }
From source file:edu.vanderbilt.android.vuparking.network.ParkingClient.java
public ParkingClient(Context context) { mContext = context;/*from www . j a v a 2 s .co m*/ HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds. int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) int timeoutSocket = 5000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); client = new DefaultHttpClient(httpParameters); }
From source file:org.camunda.bpm.AbstractWebappIntegrationTest.java
@Before public void createClient() throws Exception { testProperties = new TestProperties(); String applicationContextPath = getApplicationContextPath(); APP_BASE_PATH = testProperties.getApplicationPath("/" + applicationContextPath); LOGGER.info("Connecting to application " + APP_BASE_PATH); ClientConfig clientConfig = new DefaultApacheHttpClient4Config(); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = ApacheHttpClient4.create(clientConfig); defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient(); HttpParams params = defaultHttpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, 3 * 60 * 1000); HttpConnectionParams.setSoTimeout(params, 10 * 60 * 1000); }