List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:com.Kuesty.services.RequestTask.java
@Override protected String doInBackground(String... uri) { HttpClient httpclient = new DefaultHttpClient(); // add request params StringBuffer url = new StringBuffer(uri[0]).append("?") .append(URLEncodedUtils.format(getParams(), "UTF-8")); HttpGet _get = new HttpGet(url.toString()); Log.i("url---->", url.toString()); // add request headers ArrayList<NameValuePair> _headers = getHeaders(); for (NameValuePair pair : _headers) { _get.addHeader(pair.getName(), pair.getValue()); }//w w w. java2 s . c om HttpResponse response; String responseString = null; // execute try { response = httpclient.execute(_get); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); if (isCancelled()) { rsh.onError("Task cancel"); } } else { //Closes the connection. response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { e.printStackTrace(); //rsh.onError(e.getMessage()); } catch (IOException e) { e.printStackTrace(); //rsh.onError(e.getMessage()); } return responseString; }
From source file:com.lenovo.h2000.services.LicenseServiceImpl.java
@Override public String upload(byte[] fileBytes, Map<String, String> headers) throws Exception { Map<String, String> params = new HashMap<String, String>(); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost( HttpConfig.parseBaseUrl(headers) + "license/import" + "?" + TypeUtil.mapToString(params)); String responseBody = ""; DataInputStream in = null;// w w w . j a v a 2 s . c o m try { ByteArrayEntity requestEntity = new ByteArrayEntity(fileBytes); requestEntity.setContentEncoding("UTF-8"); requestEntity.setContentType("application/octet-stream"); httpPost.setEntity(requestEntity); HttpResponse response = httpClient.execute(httpPost); response.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8"); HttpEntity responseEntity = response.getEntity(); responseBody = EntityUtils.toString(responseEntity); } catch (ClientProtocolException e) { e.printStackTrace(); _logger.error("throwing HttpClientUtil.doPost ClientProtocolException with " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); _logger.error("throwing HttpClientUtil.doPost IOException with " + e.getMessage()); } finally { httpClient.close(); if (in != null) { in.close(); } } return responseBody; }
From source file:net.duckling.ddl.util.RESTClient.java
public JsonObject httpGet(String url, List<NameValuePair> params) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); try {/*from w w w. j av a2s .c o m*/ RequestBuilder rb = RequestBuilder.get().setUri(new URI(url)); for (NameValuePair hp : params) { rb.addParameter(hp.getName(), hp.getValue()); } rb.addHeader("accept", "application/json"); HttpUriRequest uriRequest = rb.build(); HttpResponse response = httpclient.execute(uriRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(br); return je.getAsJsonObject(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } finally { httpclient.close(); } return null; }
From source file:com.vst.android.demo.mensajeria.GCMIntentService.java
/** * Registra el regID(ID que google asigna al dispositivo movil) *//*from w ww. j av a 2 s. com*/ @Override protected void onRegistered(Context context, String registrationId) { Log.v(GCMIntentService.class.getName(), "onRegistered seguridadService.registrarEnServidor :" + registrationId); Constantes.instance.regId = registrationId; try { int r = seguridadService.registrarEnServidor(registrationId, null, null, Constantes.tipo_registro_mobile.DESDE_CLASE_GCMINTENT_SERVICE); Log.v(GCMIntentService.class.getName(), "onRegistered r :" + r); GCMRegistrar.setRegisteredOnServer(context, true); switch (r) { case Constantes.respuestas_servidor.DISPOSITIVO_REGISTRADO: System.out.println("DISPOSITIVO_REGISTRADO"); break; case Constantes.respuestas_servidor.NUEVO_DISPOSITIVO_POR_USUARIO_REGISTRADO: System.out.println("NUEVO_DISPOSITIVO_POR_USUARIO_REGISTRADO"); break; case Constantes.respuestas_servidor.NUEVO_DISPOSITIVO_POR_NUEVO_USUARIO_REGISTRADO: System.out.println("NUEVO_DISPOSITIVO_POR_NUEVO_USUARIO_REGISTRADO"); break; case Constantes.respuestas_servidor.NUEVO_USUARIO_POR_DISPOSITIVO_REGISTRADO: System.out.println("NUEVO_USUARIO_POR_DISPOSITIVO_REGISTRADO"); break; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } }
From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.LikesImpl.java
/** * this business method deletes a specfic like item * it takes like id as an argument we can get like id * from any feed item.//from w ww.j av a 2s.c o m * @param outMap * @return */ private Map<String, String> delete() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCECRM_CHATTER_URL = "/services/data/v25.0/chatter/likes/" + args.get(ID); Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCECRM_CHATTER_URL, null, header); try { TransportMachinery.delete(tst); outMap.put(OUTPUT, DELETE_STRING + args.get(ID)); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return outMap; }
From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java
/** * Logout the user with given session id * /*from w ww . ja v a 2 s . c o m*/ * @param session_id * @return true, if logout succeeded */ public static boolean logout(String session_id) { listToParse.clear(); listToParse.add(new ParamObject("sid", session_id, false)); JsonObject object = null; try { object = JSonRequestProvider.doRequest(listToParse, "logout.php"); return object.get("successful").getAsBoolean(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; }
From source file:es.eucm.eadventure.tracking.prv.service.TrackingPoster.java
public boolean sendSnapshot(File file) { if (baseURL == null) return false; if (snapshotsPath == null) return false; boolean sent = false; try {//from ww w . j ava 2 s . c o m HttpClient httpclient = new DefaultHttpClient(); String url = baseURL + (baseURL.endsWith("/") ? "" : "/") + snapshotsPath; HttpPost httpput = new HttpPost(url); FileEntity myEntity = new FileEntity(file, "image/jpeg"); httpput.setEntity(myEntity); HttpResponse response; response = httpclient.execute(httpput); if (response != null && Integer.toString(response.getStatusLine().getStatusCode()).startsWith("2")) { sent = true; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return sent; }
From source file:me.willowcheng.makerthings.util.MjpegStreamer.java
public InputStream httpRequest(String url, String usr, String pwd) { HttpResponse res = null;//from w w w . ja v a 2 s .c om DefaultHttpClient httpclient = new DefaultHttpClient(); CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(usr, pwd)); httpclient.setCredentialsProvider(credProvider); Log.d(TAG, "1. Sending http request"); try { res = httpclient.execute(new HttpGet(URI.create(url))); Log.d(TAG, "2. Request finished, status = " + res.getStatusLine().getStatusCode()); if (res.getStatusLine().getStatusCode() == 401) { //You must turn off camera User Access Control before this will work return null; } Log.d(TAG, "content-type = " + res.getEntity().getContentType()); Log.d(TAG, "content-encoding = " + res.getEntity().getContentEncoding()); return res.getEntity().getContent(); } catch (ClientProtocolException e) { e.printStackTrace(); Log.d(TAG, "Request failed-ClientProtocolException", e); //Error connecting to camera } catch (IOException e) { e.printStackTrace(); Log.d(TAG, "Request failed-IOException", e); //Error connecting to camera } return null; }
From source file:com.rukman.emde.smsgroups.authenticator.GMSAuthenticator.java
@Override public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { Log.d(TAG, "Get Auth Token"); // If the caller requested an authToken type we don't support, then // return an error if (!authTokenType.equals(GMSApplication.AUTHTOKEN_TYPE)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType"); return result; }/* w w w .ja v a 2 s .c o m*/ // Extract the username and password from the Account Manager, and ask // the server for an appropriate AuthToken. final String password = AccountManager.get(mContext).getPassword(account); if (!TextUtils.isEmpty(password)) { try { final String authToken = NetworkUtilities.authenticate(account.name, password); if (!TextUtils.isEmpty(authToken)) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, GMSApplication.ACCOUNT_TYPE); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); return result; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } // If we get here, then we couldn't access the user's password - so we // need to re-prompt them for their credentials. We do that by creating // an intent to display our AuthenticatorActivity panel. final Intent intent = new Intent(mContext, GMSAuthenticatorActivity.class); intent.putExtra(GMSAuthenticatorActivity.PARAM_USERNAME, account.name); intent.putExtra(GMSAuthenticatorActivity.PARAM_AUTHTOKEN_TYPE, authTokenType); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.LikesImpl.java
/** * This method lists likes of an organization * @param outMap//from w ww . ja v a 2 s . c om * @return */ private Map<String, String> list() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CHATTER_CONVERSATION_URL = "/services/data/v25.0/chatter/feed-items/" + args.get(ID) + "/likes"; Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCE_CHATTER_CONVERSATION_URL, null, header); try { String response = TransportMachinery.get(tst).entityToString(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return outMap; }