List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:com.nextgis.uikobserver.HttpSendData.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(mContext)) { String sPostBody = urls[0]; // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://gis-lab.info:8090/"); HttpParams params = httppost.getParams(); params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); HttpContext localContext = new BasicHttpContext(); try {/*from ww w . j ava2 s . c om*/ StringEntity se = new StringEntity(sPostBody, "UTF8"); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); httppost.setHeader("Content-type", "application/json"); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost, localContext); Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean("error", false); } else { bundle.putBoolean("error", true); } bundle.putInt("src", mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } catch (ClientProtocolException e) { mError = e.getMessage(); cancel(true); } catch (IOException e) { mError = e.getMessage(); cancel(true); } } else { Bundle bundle = new Bundle(); bundle.putBoolean("error", true); bundle.putString("err_msq", mContext.getString(R.string.sNetworkUnreach)); bundle.putInt("src", mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } return null; }
From source file:de.dhbw.organizer.calendar.backend.manager.NetworkManager.java
/** * this function tests to download the file from the given URL and returns * the HTTP status code/*from www. j a va2 s . co m*/ * * @param url * @return http status code, or 0 by any error */ public int testHttpUrl(String url) { if (isOnline()) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); if (!httpGet.containsHeader("Accept-Encoding")) { httpGet.addHeader("Accept-Encoding", "gzip"); } HttpResponse httpResponse = null; try { httpResponse = httpClient.execute(httpGet); int httpStatus = httpResponse.getStatusLine().getStatusCode(); Log.i(TAG, "url = " + url + " HTTP: " + httpStatus); return httpStatus; } catch (ClientProtocolException e) { e.printStackTrace(); Log.e(TAG, "ERROR: " + e.getMessage()); return 0; } catch (IOException e) { Log.e(TAG, "ERROR: " + e.getMessage()); e.printStackTrace(); return 0; } catch (IllegalStateException e) { Log.e(TAG, "ERROR: " + e.getMessage()); e.printStackTrace(); return 0; } } else return 0; }
From source file:org.godotengine.godot.utils.HttpRequester.java
private String request(HttpUriRequest request) { // Log.d("XXX", "Haciendo request a: " + request.getURI() ); Log.d("PPP", "Haciendo request a: " + request.getURI()); long init = new Date().getTime(); HttpClient httpclient = getNewHttpClient(); HttpParams httpParameters = httpclient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 0); HttpConnectionParams.setSoTimeout(httpParameters, 0); HttpConnectionParams.setTcpNoDelay(httpParameters, true); try {/*from w w w . j a v a 2 s . c o m*/ HttpResponse response = httpclient.execute(request); Log.d("PPP", "Fin de request (" + (new Date().getTime() - init) + ") a: " + request.getURI()); // Log.d("XXX1", "Status:" + response.getStatusLine().toString()); if (response.getStatusLine().getStatusCode() == 200) { String strResponse = EntityUtils.toString(response.getEntity()); // Log.d("XXX2", strResponse); return strResponse; } else { Log.d("XXX3", "Response status code:" + response.getStatusLine().getStatusCode() + "\n" + EntityUtils.toString(response.getEntity())); return null; } } catch (ClientProtocolException e) { Log.d("XXX3", e.getMessage()); } catch (IOException e) { Log.d("XXX4", e.getMessage()); } return null; }
From source file:com.adam.aslfms.service.Scrobbler.java
/** * //from w w w .ja v a 2 s . c o m * @return a {@link ScrobbleResult} struct with some info * @throws BadSessionException * @throws TemporaryFailureException */ public void scrobbleCommit(HandshakeResult hInfo, Track[] tracks) throws BadSessionException, TemporaryFailureException { DefaultHttpClient http = new DefaultHttpClient(); HttpPost request = new HttpPost(hInfo.scrobbleUri); List<BasicNameValuePair> data = new LinkedList<BasicNameValuePair>(); data.add(new BasicNameValuePair("s", hInfo.sessionId)); for (int i = 0; i < tracks.length; i++) { Track track = tracks[i]; String is = "[" + i + "]"; data.add(new BasicNameValuePair("a" + is, track.getArtist())); data.add(new BasicNameValuePair("b" + is, track.getAlbum())); data.add(new BasicNameValuePair("t" + is, track.getTrack())); data.add(new BasicNameValuePair("i" + is, Long.toString(track.getWhen()))); data.add(new BasicNameValuePair("o" + is, track.getSource())); data.add(new BasicNameValuePair("l" + is, Integer.toString(track.getDuration()))); data.add(new BasicNameValuePair("n" + is, track.getTrackNr())); data.add(new BasicNameValuePair("m" + is, track.getMbid())); data.add(new BasicNameValuePair("r" + is, track.getRating())); } try { request.setEntity(new UrlEncodedFormEntity(data, "UTF-8")); ResponseHandler<String> handler = new BasicResponseHandler(); String response = http.execute(request, handler); String[] lines = response.split("\n"); if (response.startsWith("OK")) { Log.i(TAG, "Scrobble success: " + getNetApp().getName()); } else if (response.startsWith("BADSESSION")) { throw new BadSessionException("Scrobble failed because of badsession"); } else if (response.startsWith("FAILED")) { String reason = lines[0].substring(7); throw new TemporaryFailureException("Scrobble failed: " + reason); } else { throw new TemporaryFailureException("Scrobble failed weirdly: " + response); } } catch (ClientProtocolException e) { throw new TemporaryFailureException(TAG + ": " + e.getMessage()); } catch (IOException e) { throw new TemporaryFailureException(TAG + ": " + e.getMessage()); } finally { http.getConnectionManager().shutdown(); } }
From source file:com.liato.bankdroid.banking.banks.DanskeBank.java
@Override public Urllib login() throws LoginException, BankException { try {// w w w . j a v a2 s. c om LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("et personnummer eller servicekod du angett")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:org.cloudsimulator.controller.ServiceMetricController.java
public void sendXmlRdfOfServiceMetricToKB() { ResponseMessageString responseMessage; hideSendForm();/*from w ww. j av a 2 s . c o m*/ try { responseMessage = KBDAO.sendXMLToKB("POST", this.ipOfKB, "serviceMetric", "", this.createdXmlRdfServiceMetric); if (responseMessage != null) { if (responseMessage.getResponseCode() < 400) { this.sendDone = "done"; } else { this.sendDone = "error"; } if (responseMessage.getResponseBody() != null) { this.alertMessage = "<strong>Response Code </strong>: " + responseMessage.getResponseCode() + " <strong>Reason</strong>: " + responseMessage.getReason() + "<br />" + responseMessage.getResponseBody().replace("\n", "<br />"); } else { this.alertMessage = "<strong>Response Code </strong>: " + responseMessage.getResponseCode() + " <strong>Reason</strong>: " + responseMessage.getReason() + "<br />"; } } } catch (ClientProtocolException e) { LOGGER.error(e.getMessage(), e); this.sendDone = "exception"; this.alertMessage = e.toString(); } catch (IOException e) { LOGGER.error(e.getMessage(), e); this.sendDone = "exception"; this.alertMessage = e.toString(); } }
From source file:com.nextgis.metroaccess.MetaDownloader.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(moContext)) { try {/*from ww w . ja va 2 s. co m*/ String sURL = urls[0]; moHTTPGet = new HttpGet(sURL); Log.d(TAG, "HTTPGet URL " + sURL); HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 1500; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpClient Client = new DefaultHttpClient(httpParameters); HttpResponse response = Client.execute(moHTTPGet); if (response == null) return null; HttpEntity entity = response.getEntity(); if (moEventReceiver != null) { if (entity != null) { Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean(BUNDLE_ERRORMARK_KEY, false); msContent = EntityUtils.toString(entity, HTTP.UTF_8); bundle.putString(BUNDLE_PAYLOAD_KEY, msContent); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); } else { bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkGetErr)); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); } Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } else { msError = moContext.getString(R.string.sNetworkUnreachErr); } } } catch (ClientProtocolException e) { msError = e.getMessage(); //cancel(true); } catch (IOException e) { msError = e.getMessage(); //cancel(true); } } else { if (moEventReceiver != null) { Bundle bundle = new Bundle(); bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, moContext.getString(R.string.sNetworkUnreachErr)); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } } return null; }
From source file:com.liato.bankdroid.banking.banks.DinersClub.java
@Override public void update() throws BankException, LoginException, BankChoiceException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }//from w w w . j a va2s. c om urlopen = login(); if (!"https://secure.dinersclub.se/dcs/eSaldo/Default.aspx".equalsIgnoreCase(urlopen.getCurrentURI())) { try { response = urlopen.open("https://secure.dinersclub.se/dcs/eSaldo/Default.aspx"); } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } } Matcher matcher = reBalance.matcher(response); if (matcher.find()) { /* * Capture groups: * GROUP EXAMPLE DATA * 1: Name Privatkort * 2: Card number 1234 789456 741 * 3: Balance 3.331,79 kr * */ accounts.add(new Account(Html.fromHtml(matcher.group(1)).toString().trim(), Helpers.parseBalance(matcher.group(3)), "1")); balance = balance.add(Helpers.parseBalance(matcher.group(3))); } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } /* Detect invoice dates - needed to find the transactions */ matcher = reInvoices.matcher(response); if (matcher.find()) { invoiceUrl = matcher.group(1); } else { invoiceUrl = null; } super.updateComplete(); }
From source file:com.liato.bankdroid.banking.banks.Statoil.java
@Override public void update() throws BankException, LoginException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }/*from w ww . jav a 2 s. c om*/ urlopen = login(); Matcher matcher; try { if (!"https://applications.sebkort.com/nis/stse/main.do".equals(urlopen.getCurrentURI())) { response = urlopen.open("https://applications.sebkort.com/nis/stse/main.do"); } matcher = reAccounts.matcher(response); /* * Capture groups: * GROUP EXAMPLE DATA * 1: amount 10 579,43 * */ if (matcher.find()) { Account account = new Account("Kpgrns", Helpers.parseBalance(matcher.group(1)), "3"); account.setType(Account.OTHER); accounts.add(account); } if (matcher.find()) { Account account = new Account("Saldo", Helpers.parseBalance(matcher.group(1)), "2"); account.setType(Account.OTHER); accounts.add(account); } if (matcher.find()) { Account account = new Account("Disponibelt belopp", Helpers.parseBalance(matcher.group(1)), "1"); account.setType(Account.CCARD); accounts.add(account); balance = balance.add(Helpers.parseBalance(matcher.group(1))); } Collections.reverse(accounts); if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } finally { super.updateComplete(); } }