List of usage examples for org.apache.http.params CoreConnectionPNames CONNECTION_TIMEOUT
String CONNECTION_TIMEOUT
To view the source code for org.apache.http.params CoreConnectionPNames CONNECTION_TIMEOUT.
Click Source Link
From source file:cl.mmoscoso.geocomm.sync.GeoCommRegisterAsyncTask.java
@Override protected Boolean doInBackground(Void... params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); try {//from ww w .j av a 2s . com // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("username", this.name)); nameValuePairs.add(new BasicNameValuePair("password", this.pass)); nameValuePairs.add(new BasicNameValuePair("email", this.e_mail)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); switch (responseCode) { case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); //Log.i(TAGNAME, responseBody); JSONObject jObj; try { //Log.i(TAGNAME, "tamao: "+ responseBody); jObj = new JSONObject(responseBody); Log.i(TAGNAME, "tamao22: " + jObj.getInt("status")); this.status = jObj.getInt("status"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return true; }
From source file:cn.edu.szjm.support.http.IgnitedHttpRequestBase.java
public IgnitedHttpRequest withTimeout(int timeout) { oldSocketTimeout = httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, IgnitedHttp.DEFAULT_SOCKET_TIMEOUT); oldConnTimeout = httpClient.getParams().getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, IgnitedHttp.DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT); ignitedHttp.setSocketTimeout(timeout); ignitedHttp.setConnectionTimeout(timeout); timeoutChanged = true;//from w w w .ja v a 2s . co m return this; }
From source file:cl.mmoscoso.geocomm.sync.GeoCommDeletePointAsyncTask.java
@Override protected Boolean doInBackground(Void... params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); //http://172.16.50.35/~ramirez/testAddPoint.php //http://172.16.57.132/~laost/Symfony/web/app_dev.php/addPoint/ try {/*w w w .ja va 2 s. c o m*/ // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("id", Integer.toString(this.id_point))); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); Log.i(TAGNAME, "ERROR: " + responseCode); switch (responseCode) { default: Log.i(TAGNAME, "ERROR"); //Toast.makeText(this.context,R.string.error_not200code, Toast.LENGTH_SHORT).show(); break; case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); //Log.i(TAGNAME, responseBody); JSONObject jObj; try { Log.i(TAGNAME, "tamao: " + responseBody); jObj = new JSONObject(responseBody); this.status = jObj.getInt("status"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return true; }
From source file:org.jboss.arquillian.android.drone.impl.SelendroidHelper.java
/** * Waits for Selendroid start. After installation and execution of instrumentation command, we repeatedly send http request * to status page to get response code of 200 - server is up and running and we can proceed safely. *///from www .ja va2 s .c o m public void waitForServerHTTPStart() { HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIME_OUT_SECONDS * 1000); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIME_OUT_SECONDS * 1000); HttpGet httpGet = new HttpGet(getSelendroidStatusURI()); boolean connectionSuccess = false; for (int i = NUM_CONNECTION_RETIRES; i > 0; i--) { try { HttpResponse response = httpClient.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { connectionSuccess = true; break; } logger.log(Level.INFO, "Response was not 200, response was: " + statusCode + ". Repeating " + i + " times."); } catch (ClientProtocolException e) { logger.log(Level.WARNING, e.getMessage()); } catch (IOException e) { logger.log(Level.WARNING, e.getMessage()); } } httpClient.getConnectionManager().shutdown(); if (!connectionSuccess) { throw new AndroidExecutionException("Unable to get successful connection from Selendroid http server."); } }
From source file:cl.mmoscoso.geocomm.sync.GeoCommGetRoutesAsyncTask.java
@Override protected Boolean doInBackground(String... params) { // TODO Auto-generated method stub HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); Log.i(TAGNAME, "Try to connect to " + this.hostname); try {/* w w w. j a va 2 s . c om*/ Log.i(TAGNAME, "Post Request"); HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); Log.i(TAGNAME, "CODE: " + responseCode); switch (responseCode) { default: //Toast.makeText(this.context,R.string.error_not200code, Toast.LENGTH_SHORT).show(); Log.i(TAGNAME, "Error"); break; case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); //Log.i(TAGNAME, responseBody); JSONObject jObj, ruta; try { Log.i(TAGNAME, "Reading JSONResponse"); //Log.i(TAGNAME, responseBody); jObj = new JSONObject(responseBody); for (int i = 0; i < jObj.length(); i++) { ruta = new JSONObject(jObj.getString(jObj.names().getString(i))); list_routes.add(new GeoCommRoute(ruta.getString("name"), ruta.getString("owner"), ruta.getInt("id"), ruta.getInt("totalPoints"), ruta.getString("description"), ruta.getBoolean("public"))); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block Log.e(TAGNAME, e.toString()); return false; } catch (IOException e) { // TODO Auto-generated catch block Log.e(TAGNAME, e.toString()); return false; } return true; }
From source file:io.kyligence.benchmark.loadtest.client.RestClient.java
private void init(String host, int port, String userName, String password) { this.host = host; this.port = port; this.userName = userName; this.password = password; this.baseUrl = "http://" + host + ":" + port + "/kylin/api"; client = new DefaultHttpClient(); if (userName != null && password != null) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); provider.setCredentials(AuthScope.ANY, credentials); client.setCredentialsProvider(provider); }/*from w w w .j ava 2 s .c o m*/ client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, ONE_HOUR_IN_MS); client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, ONE_HOUR_IN_MS); }
From source file:org.xwiki.contrib.authentication.http.XWikiHTTPAuthenticator.java
private boolean checkAuth(String username, String password, URI uri) throws ClientProtocolException, IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "XWik"); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); HttpGet httpget = new HttpGet(uri); HttpResponse response = httpClient.execute(httpget); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; }
From source file:cl.mmoscoso.geocomm.sync.GeoCommCreateRouteAsyncTask.java
@Override protected Boolean doInBackground(Void... params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); try {/* w ww . j av a2s .c o m*/ // Add your data Log.i(TAGNAME, "PUBLIC: " + this.is_public); Log.i(TAGNAME, "NAME: " + this.name); Log.i(TAGNAME, "DESC: " + this.desc); Log.i(TAGNAME, "OWNER: " + this.id_user); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("name", this.name)); nameValuePairs.add(new BasicNameValuePair("description", this.desc)); nameValuePairs.add(new BasicNameValuePair("id", Integer.toString(this.id_user))); nameValuePairs.add(new BasicNameValuePair("public", Boolean.toString(this.is_public))); //nameValuePairs.add(new BasicNameValuePair("id", "1")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); Log.i(TAGNAME, "ERROR: " + responseCode); switch (responseCode) { default: Log.i(TAGNAME, "ERROR"); //Toast.makeText(this.context,R.string.error_not200code, Toast.LENGTH_SHORT).show(); break; case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); Log.i(TAGNAME, responseBody); JSONObject jObj; try { Log.i(TAGNAME, "Status: " + this.is_public); jObj = new JSONObject(responseBody); this.status = jObj.getInt("status"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return true; }
From source file:cl.mmoscoso.geocomm.sync.GeoCommLogInAsyncTask.java
@Override protected Boolean doInBackground(Void... params) { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); HttpPost httppost = new HttpPost(this.hostname); try {//from w w w . j a v a 2 s. co m // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("username", this.name)); nameValuePairs.add(new BasicNameValuePair("password", this.pass)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); //int responseCode = 201; switch (responseCode) { case 200: HttpEntity entity = response.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity); //Log.i(TAGNAME, responseBody); JSONObject jObj, point; try { //Log.i(TAGNAME, "tamao: "+ responseBody); jObj = new JSONObject(responseBody); this.value_login = jObj.getInt("status"); this.id_user = jObj.getInt("id"); //Log.i(TAGNAME, "Value: "+ this.value_login ); //this.name_user = jObj.getString("name"); //this.id_user = jObj.getInt("id"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; default: Log.i(TAGNAME, "Error"); //Toast.makeText(this.context,"ERROR!!", Toast.LENGTH_SHORT).show(); break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return true; }
From source file:monasca.common.middleware.HttpClientPoolFactory.java
HttpClientPoolFactory(String host, int port, boolean useHttps, int timeout, boolean clientAuth, String keyStore, String keyPass, String trustStore, String trustPass, String adminToken, int maxActive, long timeBetweenEvictionRunsMillis, long minEvictableIdleTimeMillis) { // Setup auth URL String protocol = useHttps ? "https://" : "http://"; String urlStr = protocol + host + ":" + port; uri = URI.create(urlStr);//from w w w . j a v a 2 s .c o m // Setup connection pool SchemeRegistry schemeRegistry = new SchemeRegistry(); if (protocol.startsWith("https")) { SSLSocketFactory sslf = sslFactory(keyStore, keyPass, trustStore, trustPass, clientAuth); schemeRegistry.register(new Scheme("https", port, sslf)); } else { schemeRegistry.register(new Scheme("http", port, PlainSocketFactory.getSocketFactory())); } connMgr = new PoolingClientConnectionManager(schemeRegistry, minEvictableIdleTimeMillis, TimeUnit.MILLISECONDS); connMgr.setMaxTotal(maxActive); connMgr.setDefaultMaxPerRoute(maxActive); // Http connection timeout HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); // Create a single client client = new DefaultHttpClient(connMgr, params); // Create and start the connection pool cleaner cleaner = new HttpPoolCleaner(connMgr, timeBetweenEvictionRunsMillis, minEvictableIdleTimeMillis); new Thread(cleaner).start(); }