List of usage examples for org.apache.http.params HttpConnectionParams setConnectionTimeout
public static void setConnectionTimeout(HttpParams httpParams, int i)
From source file:com.sfalma.trace.Sfalma.java
public static void submitError(int sTimeout, Date occuredAt, final String stacktrace) throws Exception { // Transmit stack trace with POST request try {/* w ww .ja va 2 s. com*/ Log.d(G.TAG, "Transmitting stack trace: " + stacktrace); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); // Lighty 1.4 has trouble with the expect header // (http://redmine.lighttpd.net/issues/1017), and a // potential workaround is only included in 1.4.21 // (http://www.lighttpd.net/2009/2/16/1-4-21-yes-we-can-do-another-release). HttpProtocolParams.setUseExpectContinue(params, false); if (sTimeout != 0) { HttpConnectionParams.setConnectionTimeout(params, sTimeout); HttpConnectionParams.setSoTimeout(params, sTimeout); } HttpPost httpPost = new HttpPost(G.URL); httpPost.addHeader("X-Sfalma-Api-Key", G.API_KEY); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("data", createJSON(G.APP_PACKAGE, G.APP_VERSION, G.PHONE_MODEL, G.ANDROID_VERSION, stacktrace, SfalmaHandler.isWifiOn(), SfalmaHandler.isMobileNetworkOn(), SfalmaHandler.isGPSOn(), occuredAt))); nvps.add(new BasicNameValuePair("hash", MD5(stacktrace))); httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); // we don't care about the actual response // only if we managed to reach the server HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); // maybe no internet? // save to send another day if (entity == null) { throw new Exception("no internet connection maybe"); } } catch (Exception e) { Log.e(G.TAG, "Error sending exception stacktrace", e); throw e; } }
From source file:com.android.volley.toolbox.http.HttpClientStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders); addHeaders(httpRequest, request.getHeaders()); addHeaders(httpRequest, additionalHeaders); onPrepareRequest(httpRequest);//w ww . jav a2 s.c o m 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:dictinsight.utils.io.HttpUtils.java
public static boolean postData(String[] keys, String[] values) { DefaultHttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setSoTimeout(params, 1000 * 60); HttpConnectionParams.setConnectionTimeout(params, 1000 * 5); if (null == SEND_MESSAGE_URL) SEND_MESSAGE_URL = FileUtils.getStringConfig("course-server.conf", "pushHost", "http://livetest.youdao.com/pushMsgSingle"); HttpPost post = new HttpPost(SEND_MESSAGE_URL); try {/*w w w . j a v a 2 s . co m*/ List<NameValuePair> nvps = new ArrayList<NameValuePair>(); if (keys != null && values != null) { if (keys.length != values.length) { return false; } else { for (int i = 0; i < keys.length; i++) { nvps.add(new BasicNameValuePair(keys[i], values[i])); } } } post.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = client.execute(post); int code = response.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK) { String strResult = EntityUtils.toString(response.getEntity()); JSONObject result = JSONObject.parseObject(strResult); if (result == null) { return false; } int suc = result.getIntValue(SUCCESS); return suc == 1; } } catch (Exception e) { e.printStackTrace(); } finally { post.releaseConnection(); } return false; }
From source file:org.eclipse.mylyn.commons.repositories.http.core.HttpUtil.java
public static void configureClient(AbstractHttpClient client, String userAgent) { HttpClientParams.setCookiePolicy(client.getParams(), CookiePolicy.BEST_MATCH); if (userAgent != null) { HttpProtocolParams.setUserAgent(client.getParams(), userAgent); }//from w w w . j a va 2 s .c om HttpProtocolParams.setUseExpectContinue(client.getParams(), true); client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); HttpConnectionParams.setConnectionTimeout(client.getParams(), CONNNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_TIMEOUT); //AuthParams.setCredentialCharset(client.getParams(), "UTF-8"); }
From source file:com.tangyu.component.service.sync.TYSyncService.java
protected TYResponseResult executePost(TYSyncNetConfigure config, List<? extends TYNameValuePair> data) { // Util.v("execute post"); HttpPost post = new HttpPost(config.remoteURL()); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, config.connectionTimeoutInMills()); HttpConnectionParams.setSoTimeout(params, config.soTimeoutInMills()); try {/*from w w w . jav a 2 s .co m*/ post.setHeader(config.header()); post.setEntity(new UrlEncodedFormEntity(data, config.encodeFormat())); HttpResponse httpResponse = new DefaultHttpClient(params).execute(post); TYResponseResult result = new TYResponseResult(httpResponse); result.isSuccess = httpResponse.getStatusLine().getStatusCode() == 200; result.content = EntityUtils.toString(httpResponse.getEntity()); return result; } catch (UnsupportedEncodingException e) { } catch (ClientProtocolException e) { } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.hlc.http.resetfull.network.HttpExecutor.java
/** * Builds the http params.// w ww . ja v a 2s . co m * * @param readTimeout the read timeout * @return the http params */ protected HttpParams buildHttpParams(int readTimeout) { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, readTimeout <= 0 ? READ_TIMEOUT : readTimeout); return httpParams; }
From source file:edu.usf.cutr.opentripplanner.android.tasks.ServerChecker.java
@Override protected String doInBackground(Server... params) { Server server = params[0];//from w w w . j av a 2s . c o m if (server == null) { Log.w(TAG, "Tried to get server info when no server was selected"); cancel(true); } String message = context.getResources().getString(R.string.server_checker_info_dialog_region) + " " + server.getRegion(); message += "\n" + context.getResources().getString(R.string.server_checker_info_dialog_language) + " " + server.getLanguage(); message += "\n" + context.getResources().getString(R.string.server_checker_info_dialog_contact) + " " + server.getContactName() + " (" + server.getContactEmail() + ")"; message += "\n" + context.getResources().getString(R.string.server_checker_info_dialog_url) + " " + server.getBaseURL(); // TODO - fix server info bounds message += "\n" + context.getResources().getString(R.string.server_checker_info_dialog_bounds) + " " + server.getBounds(); message += "\n" + context.getResources().getString(R.string.server_checker_info_dialog_reachable) + " "; int status = 0; try { HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = context.getResources().getInteger(R.integer.connection_timeout); HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); int timeoutSocket = context.getResources().getInteger(R.integer.socket_timeout); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); status = Http.get(server.getBaseURL() + "/plan").use(new DefaultHttpClient(httpParameters)).asResponse() .getStatusLine().getStatusCode(); } catch (IOException e) { Log.e(TAG, "Unable to reach server: " + e.getMessage()); message = context.getResources().getString(R.string.server_checker_error_message) + " " + e.getMessage(); return message; } if (status == HttpStatus.SC_OK) { message += context.getResources().getString(R.string.yes); isWorking = true; } else { message += context.getResources().getString(R.string.no); } return message; }
From source file:gtfsrt.provider.util.GtfsrtProviderImpl.java
/** * This method read the GTFS-RT feed available on the TriMet website, * and create another GTFS-RT feed with some modified trip updates. *//* w w w.j a v a2 s .co m*/ private void refreshGTFSRealtime() throws IOException { /* The FeedMessage.Builder is what we will use to build up our GTFS-RT feed */ FeedMessage.Builder tripUpdates = GtfsRealtimeLibrary.createFeedMessageBuilder(); try { /* Read the TriMet GTFS-RT feed */ HttpGet httpget = new HttpGet( "http://developer.trimet.org/ws/V1/TripUpdate/appID/C725DEA31C7A28B860DC29BBA"); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_CONNECTION); HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_SOCKET); DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setParams(httpParams); HttpResponse response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() != 200) return; HttpEntity entity = response.getEntity(); if (entity == null) return; InputStream is = entity.getContent(); if (is != null) { // Decode message FeedMessage feedMessage = FeedMessage.parseFrom(is); List<FeedEntity> feedEntityList = feedMessage.getEntityList(); // Header tripUpdates.setHeader(feedMessage.getHeader()); for (FeedEntity feedEntity : feedEntityList) { if (feedEntity.hasTripUpdate()) { TripUpdate update = feedEntity.getTripUpdate(); TripDescriptor trip = update.getTrip(); /* Deleting trip updates already contained in the original feed */ if (trips.containsKey(trip.getTripId())) continue; /** * Create a new feed entity to wrap the trip update and add it to the * GTFS-realtime trip updates feed. */ FeedEntity.Builder tripUpdateEntity = FeedEntity.newBuilder(); tripUpdateEntity.setId(feedEntity.getId()); tripUpdateEntity.setTripUpdate(update); tripUpdates.addEntity(tripUpdateEntity); } } Trip t; TripDescriptor.Builder tripDescriptor; TripUpdate.Builder tripUpdate; FeedEntity.Builder tripUpdateEntity; for (String s : trips.keySet()) { t = trips.get(s); tripDescriptor = TripDescriptor.newBuilder(); tripDescriptor.setTripId(s); tripUpdate = addDelayForTrip(tripDescriptor, t.getDelay(), t.getNb_sequences()); // update.getStopTimeUpdateCount()) ; tripUpdateEntity = FeedEntity.newBuilder(); tripUpdateEntity.setId(tripDescriptor.getTripId()); tripUpdateEntity.setTripUpdate(tripUpdate); tripUpdates.addEntity(tripUpdateEntity); } } } catch (Exception e) { System.err.println("Error while loading GTFS RT feed"); } /* Build out the final GTFS-realtime feed messages and save them */ _gtfsRealtimeProvider.setTripUpdates(tripUpdates.build()); }
From source file:www.image.ImageManager.java
/** * Downloads a file//from w ww. j a v a2 s .co m * @param url * @return * @throws IOException */ public Bitmap fetchImage(String url) throws IOException { Bitmap mbitmap = null; try { HttpGet get = new HttpGet(url); HttpConnectionParams.setConnectionTimeout(get.getParams(), CONNECTION_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(get.getParams(), SOCKET_TIMEOUT_MS); HttpResponse response = null; response = mClient.execute(get); HttpEntity entity = response.getEntity(); BufferedInputStream bis = new BufferedInputStream(entity.getContent(), 8 * 1024); mbitmap = scaleBitmap(bis, 120, 120); bis.close(); if (response.getStatusLine().getStatusCode() != 200) { mbitmap = mFailBitmap; } } catch (ClientProtocolException e) { throw new IOException("Invalid client protocol."); } catch (Exception e) { e.printStackTrace(); } return mbitmap; }