List of usage examples for org.apache.http.client ClientProtocolException printStackTrace
public void printStackTrace()
From source file:uk.ac.bbsrc.tgac.miso.core.service.integration.ws.pacbio.PacBioService.java
public String getPrimaryAnalysisStatus(String plateId, String sampleWellId) { HttpGet httpget = new HttpGet( baseRestUri.toString() + "/Jobs/PrimaryAnalysis/" + plateId + "/" + sampleWellId + "/Status"); try {/* ww w.ja v a 2 s.com*/ HttpResponse response = httpclient.execute(httpget); String out = parseEntity(response.getEntity()); JSONObject j = JSONObject.fromObject(out); if (j.has("Status")) { return j.getString("Status"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:uk.ac.bbsrc.tgac.miso.core.service.integration.ws.pacbio.PacBioService.java
public String getPrimaryAnalysisJob(String plateId, String sampleWellId, Date fromDate) { try {//from w ww . ja v a2 s . c om String d = startDateFormat.format(fromDate); HttpGet httpget = new HttpGet(baseRestUri.toString() + "Jobs/PrimaryAnalysis/Query?after=" + d); HttpResponse response = httpclient.execute(httpget); String out = parseEntity(response.getEntity()); JSONArray a = JSONArray.fromObject(out); for (JSONObject j : (Iterable<JSONObject>) a) { if (j.getString("Plate").equals(plateId) && j.getString("Well").equals(sampleWellId)) { return j.toString(); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:uk.codingbadgers.SurvivalPlus.error.ReportExceptionRunnable.java
public boolean run() { try {/*from ww w . j a v a2s .c o m*/ List<NameValuePair> data = new ArrayList<NameValuePair>(); data.add(new BasicNameValuePair("password", DigestUtils.md5Hex(SurvivalPlus.getConfigurationManager().getCrashPassword()))); data.add(new BasicNameValuePair("project", "bFundamentals")); data.add(new BasicNameValuePair("cause", getException(throwable))); data.add(new BasicNameValuePair("message", getMessage(throwable))); data.add(new BasicNameValuePair("st", buildStackTrace(throwable))); HttpPost post = new HttpPost("http://server.mcbadgercraft.com/crash/report.php"); post.setEntity(new UrlEncodedFormEntity(data)); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse responce = client.execute(post); String result = EntityUtils.toString(responce.getEntity()); if (SurvivalPlus.getConfigurationManager().isDebugEnabled()) System.out.println(result); JSONObject object = (JSONObject) new JSONParser().parse(result); boolean success = (Boolean) object.get("success"); if (!success) System.err.println(object.get("error")); return success; } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:uk.submergedcode.SubmergedCore.error.ReportExceptionRunnable.java
public boolean run() { try {//from w w w . ja v a2s .c om List<NameValuePair> data = new ArrayList<NameValuePair>(); data.add(new BasicNameValuePair("password", DigestUtils.md5Hex(SubmergedCore.getConfigurationManager().getCrashPassword()))); data.add(new BasicNameValuePair("project", "SubmergedCore")); data.add(new BasicNameValuePair("cause", getException(throwable))); data.add(new BasicNameValuePair("message", getMessage(throwable))); data.add(new BasicNameValuePair("st", buildStackTrace(throwable))); HttpPost post = new HttpPost("http://server.mcbadgercraft.com/crash/report.php"); post.setEntity(new UrlEncodedFormEntity(data)); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse responce = client.execute(post); String result = EntityUtils.toString(responce.getEntity()); if (SubmergedCore.getConfigurationManager().isDebugEnabled()) System.out.println(result); JSONObject object = (JSONObject) new JSONParser().parse(result); boolean success = (Boolean) object.get("success"); if (!success) System.err.println(object.get("error")); return success; } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:com.gmail.at.faint545.services.DataQueueService.java
@Override protected void onHandleIntent(Intent intent) { String url = intent.getStringExtra("url"); String api = intent.getStringExtra("api"); StringBuilder results = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(url); ArrayList<NameValuePair> arguments = new ArrayList<NameValuePair>(); arguments.add(new BasicNameValuePair(SabnzbdConstants.APIKEY, api)); arguments.add(new BasicNameValuePair(SabnzbdConstants.OUTPUT, SabnzbdConstants.OUTPUT_JSON)); arguments.add(new BasicNameValuePair(SabnzbdConstants.MODE, SabnzbdConstants.MODE_QUEUE)); try {//from w w w. j av a 2 s .co m request.setEntity(new UrlEncodedFormEntity(arguments)); HttpResponse result = client.execute(request); InputStream inStream = result.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(inStream), 8); String line; while ((line = br.readLine()) != null) { if (line.length() > 0) { results.append(line); } } br.close(); inStream.close(); Bundle extras = intent.getExtras(); Messenger messenger = (Messenger) extras.get("messenger"); Message message = Message.obtain(); Bundle resultsBundle = new Bundle(); resultsBundle.putString("results", results.toString()); message.setData(resultsBundle); messenger.send(message); stopSelf(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } }
From source file:com.anteam.demo.logback.appender.HttpAppender.java
@Override protected void append(E event) { System.out.println(((LoggingEvent) event).getFormattedMessage()); StringEntity stringEntity = new StringEntity(event.toString(), ContentType.create("text/plain", "UTF-8")); HttpPost post = new HttpPost(url); post.setEntity(stringEntity);//from w ww . jav a2s . com HttpResponse response = null; try { response = httpclient.execute(post); } catch (ClientProtocolException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } // Examine the response status System.out.println(response.getStatusLine()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { InputStream instream = null; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response System.out.println(reader.readLine()); } catch (Exception ex) { post.abort(); } finally { try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.mitchtodd.myweatherapp.webservices.MyWeather2Service.java
public Weather requestWeather(String zipCode) { Weather weather = null;//from w ww .j a va 2s. co m StringBuilder builder = new StringBuilder(); int timeoutConnection = 5000; HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpClient client = new DefaultHttpClient(httpParameters); String requestUrl = createRequestUrl(zipCode); HttpGet httpGet = new HttpGet(requestUrl); try { HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } weather = new Weather(builder.toString()); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return weather; }
From source file:uk.ac.horizon.ubihelper.ui.TestActivity.java
protected void doTest() { DefaultHttpClient httpClient = new DefaultHttpClient(); String url = "http://127.0.0.1:8180/ubihelper"; HttpPost httppost = new HttpPost(url); String request = "[{\"name\":\"magnetic\",\"period\":0.5,\"count\":1,\"timeout\":20}," + "{\"name\":\"accelerometer\",\"period\":0.5,\"count\":1,\"timeout\":20}]"; setText("POST " + url + "\n" + request); try {/*from w w w . j a v a2s . c om*/ httppost.setEntity(new StringEntity(request, "UTF-8")); HttpResponse response = httpClient.execute(httppost); final int status = response.getStatusLine().getStatusCode(); final String message = response.getStatusLine().getReasonPhrase(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); response.getEntity().writeTo(baos); final String resp = baos.toString("UTF-8"); append("\nGot " + status + " (" + message + "): " + resp); } catch (ClientProtocolException e) { e.printStackTrace(); append("\nError: " + e); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); append("\nError: " + e1); } catch (IOException e) { e.printStackTrace(); append("\nError: " + e); } }
From source file:org.thiesen.jiffs.jobs.fullpage.PageLoader.java
@Override public void run() { final URI link = _story.getLink(); final HttpGet get = new HttpGet(link); final HttpClient client = new DefaultHttpClient(); try {/*from ww w .j a va 2 s . c o m*/ final String page = client.execute(get, new BasicResponseHandler()); _story.setFullPage(page); _storyDAO.update(_story); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { client.getConnectionManager().shutdown(); } }
From source file:com.jpa.MyHttpClient.java
public String getContent(String url) { String out = ""; HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpResponse response = null;//from w w w . j a v a 2s. c o m try { response = httpclient.execute(httpget); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } HttpEntity entity = response.getEntity(); if (entity != null) { try { out = EntityUtils.toString(entity); Log.d("INFO", out); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return out; }