List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:org.vuphone.assassins.android.http.HTTPGetter.java
private static HashMap<String, Double> handleGameAreaResponse(HttpGet get) { HttpResponse resp;//from w w w . ja v a2 s. c om // Execute the get try { resp = c.execute(get); } catch (ClientProtocolException e1) { e1.printStackTrace(); Log.e(VUphone.tag, pre + "HTTP error while executing post"); return null; } catch (SocketException se) { // If we have no Internet connection, we don't want to wipe the // existing list of land mines by returning null. Log.e(VUphone.tag, pre + "SocketException: Invalid Internet " + "Connection"); se.printStackTrace(); return null; } catch (IOException e1) { e1.printStackTrace(); Log.e(VUphone.tag, pre + "HTTP error in server response"); return null; } catch (Exception e) { Log.e(VUphone.tag, pre + "An unknown exception was thrown"); e.printStackTrace(); return null; } Log.i(VUphone.tag, pre + "HTTP operation complete. Processing response."); // Convert Response Entity to usable format ByteArrayOutputStream bao = new ByteArrayOutputStream(); try { resp.getEntity().writeTo(bao); Log.v(VUphone.tag, pre + "Http response: " + bao); } catch (IOException e) { e.printStackTrace(); Log.e(VUphone.tag, pre + "Unable to write response to byte[]"); return null; } if (bao.size() == 0) { Log.w(VUphone.tag, pre + "Response was completely empty, " + "are you sure you are using the " + "same version client and server? " + "At the least, there should have " + "been empty XML here"); } HashMap<String, Double> data = new HashMap<String, Double>(); String response = bao.toString(); String[] vals = response.split("&"); for (int i = 0; i < vals.length; i++) { String[] val = vals[i].split("="); data.put(val[0], Double.valueOf(val[1])); } return data; }
From source file:com.photon.phresco.nativeapp.eshop.net.NetworkManager.java
public static boolean checkHttpURLStatus(final String url) { boolean httpStatusFlag = false; HttpClient httpclient = new DefaultHttpClient(); // Prepare a request object HttpGet httpget = new HttpGet(url); // Execute the request HttpResponse response;//ww w . j a va 2 s.com try { response = httpclient.execute(httpget); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpURLConnection.HTTP_OK) { httpStatusFlag = true; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return httpStatusFlag; }
From source file:com.thed.zephyr.jenkins.utils.rest.Cycle.java
public static Long deleteCycle(ZephyrConfigModel zephyrData) { Long cycleId = 0L;//from w w w.j ava 2s.co m HttpResponse response = null; try { String deleteCycleURL = URL_DELETE_CYCLE.replace("{SERVER}", zephyrData.getRestClient().getUrl()) .replace("{id}", zephyrData.getCycleId() + ""); HttpDelete createCycleRequest = new HttpDelete(deleteCycleURL); response = zephyrData.getRestClient().getHttpclient().execute(createCycleRequest, zephyrData.getRestClient().getContext()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); String string = null; try { string = EntityUtils.toString(entity); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { try { throw new ClientProtocolException("Unexpected response status: " + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } return cycleId; }
From source file:com.technion.studybuddy.GCM.ServerUtilities.java
public static GoogleHttpContext getContext(Context activity, String baseUrl) throws NotRegisteredException { if (!isRegistered(activity)) throw new NotRegisteredException(); try {// w w w . j a v a2 s . c o m return Constants.debug ? new GoogleHttpContextDev(activity, baseUrl) : new GoogleHttpContextProduction(activity, baseUrl); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (OperationCanceledException e) { e.printStackTrace(); } catch (AuthenticatorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (AccessException e) { e.printStackTrace(); } return null; }
From source file:javaSeed.utils.jiraConnection.Cycle.java
public static Long deleteCycle(ZephyrConfigModel zephyrData) { Long cycleId = 0L;//www . ja v a2 s . c o m HttpResponse response = null; try { String deleteCycleURL = URL_DELETE_CYCLE.replace("{SERVER}", zephyrData.getRestClient().getUrl()) .replace("{id}", zephyrData.getCycleId() + ""); HttpDelete createCycleRequest = new HttpDelete(deleteCycleURL); response = zephyrData.getRestClient().getHttpclient().execute(createCycleRequest, zephyrData.getRestClient().getContext()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); @SuppressWarnings("unused") String string = null; try { string = EntityUtils.toString(entity); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { try { throw new ClientProtocolException("Unexpected response status: " + statusCode); } catch (ClientProtocolException e) { e.printStackTrace(); } } return cycleId; }
From source file:messenger.YahooFinanceAPI.java
public static String httppost(String url, List<NameValuePair> header, String refer, boolean cookie) { DefaultHttpClient httpclient = new DefaultHttpClient(); if (cookie)/*from w w w .ja va2 s. c o m*/ httpclient.setCookieStore(cookiestore); else if (cookiestore1 != null) httpclient.setCookieStore(cookiestore1); if (use_proxy) { HttpHost proxy = new HttpHost(PROXY_NAME, PROXY_PORT); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } HttpPost httpPost = new HttpPost(url); httpPost.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); Header[] headers = { new BasicHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"), new BasicHeader("Content-Type", "application/x-www-form-urlencoded"), new BasicHeader("Origin", "http://aomp.judicial.gov.tw"), new BasicHeader("Referer", refer), new BasicHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.55 Safari/534.3") }; httpPost.setHeaders(headers); try { httpPost.setEntity(new UrlEncodedFormEntity(header, "Big5")); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } HttpResponse response = null; String responseString = null; try { response = httpclient.execute(httpPost); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { if (cookie) cookiestore = httpclient.getCookieStore(); else cookiestore1 = httpclient.getCookieStore(); responseString = EntityUtils.toString(response.getEntity()); // pG^O 200 OK ~X // System.out.println(responseString); // } else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { Header[] urlh = response.getAllHeaders(); System.out.println(urlh.toString()); } else { System.out.println(response.getStatusLine()); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return responseString; }
From source file:com.thed.zephyr.jenkins.utils.rest.Cycle.java
public static Map<Long, String> getAllCyclesByVersionId(long versionId, RestClient restClient, String projectId) {// ww w . j ava2 s. c o m Map<Long, String> cycles = new TreeMap<Long, String>(); HttpResponse response = null; final String url = URL_GET_CYCLES.replace("{SERVER}", restClient.getUrl()).replace("{projectId}", projectId) .replace("{versionId}", versionId + ""); try { response = restClient.getHttpclient().execute(new HttpGet(url), restClient.getContext()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); String string = null; try { string = EntityUtils.toString(entity); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { JSONObject projObj = new JSONObject(string); for (int i = 0; i < projObj.length(); i++) { Iterator<String> keys = projObj.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (/*!key.trim().equals("-1") && */!key.trim().equals("recordsCount")) { JSONObject cycleObject = projObj.getJSONObject(key); String cycleName = cycleObject.getString("name"); long id = Long.parseLong(key); cycles.put(id, cycleName); } } } } catch (JSONException e) { e.printStackTrace(); } } return cycles; }
From source file:edu.tum.cs.ias.knowrob.BarcodeWebLookup.java
public static String lookUpUpcDatabase(String ean) { String res = ""; if (ean != null && ean.length() > 0) { HttpClient httpclient = new DefaultHttpClient(); try {/* w ww. j ava 2 s . co m*/ HttpGet httpget = new HttpGet("http://www.upcdatabase.com/item/" + ean); httpget.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); // Create a response handler ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() { public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException { HttpEntity entity = response.getEntity(); if (entity != null) { return EntityUtils.toByteArray(entity); } else { return null; } } }; String responseBody = new String(httpclient.execute(httpget, handler), "UTF-8"); // return null if not found if (responseBody.contains("Item Not Found")) return null; else if (responseBody.contains("Item Record")) { // Parse response document Matcher matcher = Pattern.compile("<tr><td>Description<\\/td><td><\\/td><td>(.*)<\\/td><\\/tr>") .matcher(responseBody); if (matcher.find()) { res = matcher.group(1); } } } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } catch (ClientProtocolException cpe) { cpe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (httpclient != null) { httpclient.getConnectionManager().shutdown(); } } } return res; }
From source file:javaSeed.utils.jiraConnection.Cycle.java
public static String getCyclesIDByName(String versionId, String projectId, String CycleName, RestClient restClient) {/*ww w . ja v a 2s . com*/ HashMap<String, String> cycles = new HashMap<String, String>(); String TrueCycleID = null; HttpResponse response = null; final String url = URL_GET_CYCLES.replace("{SERVER}", restClient.getUrl()).replace("{projectId}", projectId) .replace("{versionId}", versionId + ""); try { response = restClient.getHttpclient().execute(new HttpGet(url), restClient.getContext()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); String string = null; try { string = EntityUtils.toString(entity); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { JSONObject projObj = new JSONObject(string); for (int i = 0; i < projObj.length(); i++) { @SuppressWarnings("unchecked") Iterator<String> keys = projObj.keys(); while (keys.hasNext()) { String key = (String) keys.next(); if (/*!key.trim().equals("-1") && */!key.trim().equals("recordsCount")) { JSONObject cycleObject = projObj.getJSONObject(key); String cycleName = cycleObject.getString("name"); cycles.put(cycleName, key); } } } if (cycles.get(CycleName) == null) { return null; } else { TrueCycleID = cycles.get(CycleName).toString(); } } catch (JSONException e) { e.printStackTrace(); } } return TrueCycleID; }
From source file:edu.tum.cs.ias.knowrob.BarcodeWebLookup.java
public static String lookUpEANsearch(String ean) { String res = ""; if (ean != null && ean.length() > 0) { HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); //httpclient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-16"); try {/* w w w . ja v a 2s. c o m*/ HttpGet httpget = new HttpGet("http://www.ean-search.org/perl/ean-search.pl?ean=" + ean + "&os=1"); httpget.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); httpget.getParams().setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, "ASCII"); System.out.println(httpget.getURI()); // Create a response handler ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() { public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException { HttpEntity entity = response.getEntity(); if (entity != null) { return EntityUtils.toByteArray(entity); } else { return null; } } }; byte[] response = httpclient.execute(httpget, handler); // String responseBody = httpclient.execute(httpget, handler); // new HeapByteBuffer(responseBody.getBytes(), 0, responseBody.getBytes().length)); // // Charset a = Charset.forName("UTF-8"); // a.newEncoder().encode(responseBody.getBytes()); // // System.out.println(responseBody); // Parse response document res = response.toString(); } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } catch (ClientProtocolException cpe) { cpe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (httpclient != null) { httpclient.getConnectionManager().shutdown(); } } } return res; }