List of usage examples for org.apache.http.params HttpConnectionParams setSoTimeout
public static void setSoTimeout(HttpParams httpParams, int i)
From source file:org.bfr.querytools.spectrumbridge.SpectrumBridgeQuery.java
private static HttpClient createClient() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); HttpClient client = new DefaultHttpClient(params); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10 * 1000); HttpConnectionParams.setSoTimeout(client.getParams(), 10 * 1000); return client; }
From source file:net.alchemiestick.katana.winehqappdb.WineSearch.java
@Override protected void onPreExecute() { String str = "Starting to get data from server"; tvlist.clear();//from w w w.j a v a2s.c o m tvlist.add(new str_link(str, "")); try { httpClient = AndroidHttpClient.newInstance("WineHQ/1.0 App Browser"); HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), TIMEOUT_MS); HttpConnectionParams.setSoTimeout(httpClient.getParams(), TIMEOUT_MS); } catch (Exception e) { str = "Couldn't set Params0"; tvlist.add(new str_link(str, "")); } }
From source file:CB_Utils.http.HttpUtils.java
/** * Executes a HTTP request and returns the response as a string. As a HttpRequestBase is given, a HttpGet or HttpPost be passed for * execution.<br>//w w w . j a va2 s. c o m * <br> * Over the ICancel interface cycle is queried in 200 mSec, if the download should be canceled!<br> * Can be NULL * * @param httprequest * HttpRequestBase * @param icancel * ICancel interface (maybe NULL) * @return * @throws IOException * @throws ClientProtocolException * @throws ConnectTimeoutException */ public static String Execute(final HttpRequestBase httprequest, final ICancel icancel) throws IOException, ClientProtocolException, ConnectTimeoutException { httprequest.setHeader("Accept", "application/json"); httprequest.setHeader("Content-type", "application/json"); // 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); final AtomicBoolean ready = new AtomicBoolean(false); if (icancel != null) { Thread cancelChekThread = new Thread(new Runnable() { @Override public void run() { do { try { Thread.sleep(200); } catch (InterruptedException e) { } if (icancel.cancel()) httprequest.abort(); } while (!ready.get()); } }); cancelChekThread.start();// start abort chk thread } HttpResponse response = httpClient.execute(httprequest); ready.set(true);// cancel abort chk thread BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { if (Plattform.used == Plattform.Server) line = new String(line.getBytes("ISO-8859-1"), "UTF-8"); result += line + "\n"; } return result; }
From source file:org.deviceconnect.message.basic.conn.AbstractHttpConnection.java
@Override public void setSocketTimeout(final int timeout) { mLogger.entering(getClass().getName(), "setSocketTimeout", timeout); HttpConnectionParams.setSoTimeout(getParams(), timeout); mLogger.exiting(getClass().getName(), "setSocketTimeout"); }
From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java
private static HttpClient getHttpClient() { HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 28000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); int timeoutSocket = 28000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); return new DefaultHttpClient(httpParameters); }
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. jav a2s. c o 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:eu.masconsult.bgbanking.banks.fibank.ebanking.EFIBankClient.java
/** * Configures the httpClient to connect to the URL provided. *///from w w w.j a v a2 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:net.alchemiestick.katana.winehqappdb.Metrics.java
@Override protected void onPreExecute() { try {/*from w w w. ja v 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: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:io.personium.core.utils.HttpClientFactory.java
/** * HTTPClient?.// ww w .ja v a 2s . com * @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; }