List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:org.digitalcampus.oppia.task.APIRequestTask.java
@Override protected Payload doInBackground(Payload... params) { Payload payload = params[0];/* w w w . ja va 2 s . c o m*/ String responseStr = ""; HTTPConnectionUtils client = new HTTPConnectionUtils(ctx); String url = client.getFullURL(payload.getUrl()); HttpGet httpGet = new HttpGet(url); httpGet.addHeader(client.getAuthHeader()); try { // make request HttpResponse response = client.execute(httpGet); // read response InputStream content = response.getEntity().getContent(); BufferedReader buffer = new BufferedReader(new InputStreamReader(content), 1024); String s = ""; while ((s = buffer.readLine()) != null) { responseStr += s; } switch (response.getStatusLine().getStatusCode()) { // TODO check the unauthorised response code... case 400: // unauthorised payload.setResult(false); payload.setResultResponse(ctx.getString(R.string.error_login)); break; case 200: payload.setResult(true); payload.setResultResponse(responseStr); break; default: payload.setResult(false); payload.setResultResponse(ctx.getString(R.string.error_connection)); } } catch (ClientProtocolException e) { e.printStackTrace(); payload.setResult(false); payload.setResultResponse(ctx.getString(R.string.error_connection)); } catch (IOException e) { e.printStackTrace(); payload.setResult(false); payload.setResultResponse(ctx.getString(R.string.error_connection)); } return payload; }
From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.PeopleFeedImpl.java
/** * This method Returns a URL to the feed-items for * all the people the current user is following. * @param outMap// w ww .ja v a 2 s. c o m * @return */ private Map<String, String> list() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v26.0/chatter/feeds/people/" + 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) + SALESFORCE_CHATTER_ACTIVITY_URL, null, header); try { String response = TransportMachinery.get(tst).entityToString(); outMap.put(OUTPUT, response); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return outMap; }
From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.PeopleFeedImpl.java
/** * This method Returns all the feed items from * all the people the current user follows. * @param outMap/*from www.ja v a 2 s.c o m*/ * @return */ private Map<String, String> feed() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v26.0/chatter/feeds/people/" + args.get(ID) + "/feed-items"; 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_ACTIVITY_URL, null, header); try { String response = TransportMachinery.get(tst).entityToString(); outMap.put(OUTPUT, response); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return outMap; }
From source file:com.mobileaffairs.seminar.videolib.VideoLibSyncAdapter.java
private byte[] readImage(String url) { HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try {/*from ww w. j a v a 2 s . c o m*/ HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); byte[] imageBytes = EntityUtils.toByteArray(entity); return imageBytes; } else { Log.e("readImage", "Failed to download file"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.RecordFeedImpl.java
/** * This business method Returns a URL to the feed-items for all * the records the current user is following, or a URL to all * the feed-items of the specified recordId. * @param outMap(User ID)//from www . j a v a2 s .com * @return */ private Map<String, String> list() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v26.0/chatter/records/" + 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) + SALESFORCE_CHATTER_ACTIVITY_URL, null, header); try { String response = TransportMachinery.get(tst).entityToString(); outMap.put(OUTPUT, response); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return outMap; }
From source file:servlet.SecurityServlet.java
private String getFacebookAccessToken(String faceCode) { String token = null;//from ww w. ja v a 2 s . c o m if (faceCode != null && !"".equals(faceCode)) { String appId = "303525776508598"; String redirectUrl = "http://localhost:8080/Facebook_Login/index.sec"; String faceAppSecret = "9a11d42ee3086b9e62affd4005e9e85d"; String newUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&redirect_uri=" + redirectUrl + "&client_secret=" + faceAppSecret + "&code=" + faceCode; HttpClient httpclient = new DefaultHttpClient(); try { HttpGet httpget = new HttpGet(newUrl); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpget, responseHandler); token = StringUtils.removeEnd(StringUtils.removeStart(responseBody, "access_token="), "&expires=5180795"); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { httpclient.getConnectionManager().shutdown(); } } return token; }
From source file:com.quackware.handsfreemusic.YouTubeUtility.java
public YouTubeUtility(String youtubeVideoId) { String realYoutubeUrl = ""; try {//from w w w . j ava2 s . c o m realYoutubeUrl = calculateYouTubeUrl(youtubeVideoId); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } setYoutubeUrl(realYoutubeUrl); }
From source file:com.sourcey.materiallogindemo.MasterActivity.java
private String getHttpPost(String url, List<NameValuePair> params) { StringBuilder str = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); try {//from w w w.ja v a 2 s . c o m httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = client.execute(httpPost); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { // Status OK HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { str.append(line); } } else { Log.e("Log", "Failed to download result.."); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return str.toString(); }
From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.RecordFeedImpl.java
/** * This business method Returns the feed-items for all the records the current, * signed-in user is following, or all the feed-items of the specified recordId. * @param outMap(User id)/* w w w . ja v a2s .c om*/ * @return */ private Map<String, String> view() { Map<String, String> outMap = new HashMap<>(); final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v26.0/chatter/records/" + args.get(ID) + "/followers"; 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_ACTIVITY_URL, null, header); try { String response = TransportMachinery.get(tst).entityToString(); outMap.put(OUTPUT, response); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } ; return outMap; }
From source file:com.birt.airvantage.AVRequest.java
private String getRequest(String url) { try {/* ww w . j av a2s . c o m*/ Response ex = Request.Get(url).execute(); return ex.handleResponse(new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws IOException { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } if (entity == null) throw new ClientProtocolException("No data"); return IOUtils.toString(entity.getContent()); } }); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }