List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:net.atoom.android.tt2.HttpConnection.java
public synchronized boolean isPageModified(final String pageUrl, final String eTag) { HttpHead httpUriRequest = new HttpHead(pageUrl); try {/*from www . ja va 2 s .c om*/ HttpResponse httpResponse = myHttpClient.execute(httpUriRequest); if (httpResponse.getStatusLine().getStatusCode() != HTTP_OK) { if (LogBridge.isLoggable()) LogBridge.w("Invalid statuscode for: " + pageUrl); return false; } Header eTagHeader = httpResponse.getFirstHeader(ETAG_HEADER); if (eTagHeader != null && eTagHeader.getValue().equals(eTag)) { if (LogBridge.isLoggable()) LogBridge.i("Page not modified: " + pageUrl + " (" + eTag + ")"); return true; } } catch (ClientProtocolException e) { if (LogBridge.isLoggable()) LogBridge.w("Failed to check page: " + e.getMessage()); } catch (IOException e) { if (LogBridge.isLoggable()) LogBridge.w("Failed to check page: " + e.getMessage()); } if (LogBridge.isLoggable()) LogBridge.i("Page is modified: " + pageUrl + "/ (" + eTag + ")"); return false; }
From source file:com.liato.bankdroid.banking.banks.ResursBank.java
@Override public Urllib login() throws LoginException, BankException { try {//w w w . j a va 2 s . c om LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("vid inloggningen")) { 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.wso2.am.integration.tests.rest.MalformedRequestTest.java
@Test(groups = "wso2.am", description = "Check if a malformed request breaks the system") public void testMalformedPostWithMessageBuilding() { HttpClient httpclient = HttpClientBuilder.create().build(); HttpPost httppost = new HttpPost(getGatewayURLNhttp() + "response"); httppost.addHeader(new Header() { @Override/* w ww .j av a2 s. c o m*/ public String getName() { return "Content-Type"; } @Override public String getValue() { return "application/xml"; } @Override public HeaderElement[] getElements() throws ParseException { return new HeaderElement[0]; } }); String malformedBody = "<request>Request<request>"; HttpResponse response = null; try { HttpEntity entity = new ByteArrayEntity(malformedBody.getBytes("UTF-8")); httppost.setEntity(entity); response = httpclient.execute(httppost); } catch (ClientProtocolException e) { //Fail the test case. Assert.assertTrue(false, e.getMessage()); } catch (UnsupportedEncodingException e) { //Fail the test case. Assert.assertTrue(false, e.getMessage()); } catch (IOException e) { //Fail the test case. Assert.assertTrue(false, e.getMessage()); } Assert.assertNotNull(response, "Received null response for malformed post"); Assert.assertEquals(response.getStatusLine().getStatusCode(), 500, "Did not receive an http 500 for the malformed request"); }
From source file:com.liato.bankdroid.banking.banks.ICA.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 w w. j av a2s . c o m*/ urlopen = login(); String response = null; Matcher matcher; try { response = urlopen.open("https://www.ica.se/Mina-sidor/Konto--Saldo/"); matcher = reAccounts.matcher(response); if (matcher.find()) { Account account = new Account("ICA Kort", Helpers.parseBalance(matcher.group(1)), "1"); balance = balance.add(Helpers.parseBalance(matcher.group(1))); matcher = reTransactions.matcher(response); ArrayList<Transaction> transactions = new ArrayList<Transaction>(); while (matcher.find()) { transactions.add(new Transaction(matcher.group(1).trim(), Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(3)))); } account.setTransactions(transactions); accounts.add(account); } 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(); } }
From source file:com.liato.bankdroid.banking.banks.TrustBuddy.java
public Urllib login() throws LoginException, BankException { try {/* ww w . ja v a 2s .c om*/ LoginPackage lp = preLogin(); String response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); Matcher matcher = reError.matcher(response); if (matcher.find()) { String errormsg = Html.fromHtml(matcher.group(1).trim()).toString(); if (errormsg.contains("Felaktigt")) { throw new LoginException(errormsg); } else { throw new BankException(errormsg); } } } catch (ClientProtocolException e) { Log.e(TAG, "ClientProtocolException: " + e.getMessage()); throw new BankException(e.getMessage()); } catch (IOException e) { Log.e(TAG, "IOException: " + e.getMessage()); throw new BankException(e.getMessage()); } return urlopen; }
From source file:com.liato.bankdroid.banking.banks.Vasttrafik.java
@Override public Urllib login() throws LoginException, BankException { try {//from ww w . j a v a2s .co m LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (!response.contains("<span class=\"loggedInAs\">")) { 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.openremote.android.console.util.AsyncGroupLoader.java
@Override public void run() { synchronized (this) { String server = AppSettingsModel.getSecuredServer(context); if (!TextUtils.isEmpty(server)) { HttpResponse response = null; try { URL url = new URL(server + "/rest/device/group"); HttpGet request = new HttpGet(url.toString()); HttpClient client = new DefaultHttpClient(); Scheme sch = new Scheme(url.getProtocol(), new SelfCertificateSSLSocketFactory(context), url.getPort());//from w ww .j a va2 s. co m client.getConnectionManager().getSchemeRegistry().register(sch); response = client.execute(request); } catch (ClientProtocolException e) { Log.e(LOG_CATEGORY + " run:", e.getMessage()); } catch (IOException e) { Log.e(LOG_CATEGORY + " run:", e.getMessage()); } String group = ""; if (response != null && response.getStatusLine().getStatusCode() == 200) { String tmp; try { BufferedReader in = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); while ((tmp = in.readLine()) != null) { group += tmp; } } catch (IOException e) { Log.e(LOG_CATEGORY + " urlConnectionDidReceiveData:", e.getMessage()); } } AppSettingsModel.setGroup(context, group); } done = true; notify(); } }
From source file:com.liato.bankdroid.banking.banks.MobilbankenBase.java
@Override public Urllib login() throws LoginException, BankException { try {/*from w w w . j a va 2s .com*/ LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("eller pinkod")) { 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:net.atoom.android.tt2.HttpConnection.java
public synchronized PageEntity loadPage(final String pageUrl) { HttpGet httpUriRequest = new HttpGet(pageUrl); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {// w w w .j av a2s . c om HttpResponse httpResponse = myHttpClient.execute(httpUriRequest); // this happens... if (httpResponse.getStatusLine().getStatusCode() != HTTP_OK) { if (LogBridge.isLoggable()) LogBridge.w("Invalid statuscode for: " + pageUrl); return null; } HttpEntity httpEntity = httpResponse.getEntity(); httpEntity.writeTo(baos); String eTag = httpResponse.getFirstHeader(ETAG_HEADER).getValue(); String htmlData = baos.toString(DEFAULT_ENCODING); // this happens too.. if (htmlData.equals("")) { if (LogBridge.isLoggable()) LogBridge.w("Empty responsebody for: " + pageUrl); return null; } return new PageEntity(pageUrl, htmlData, eTag); } catch (ClientProtocolException e) { if (LogBridge.isLoggable()) LogBridge.w("Failed to load page: " + e.getMessage()); } catch (IOException e) { if (LogBridge.isLoggable()) LogBridge.w("Failed to load page: " + e.getMessage()); } return null; }
From source file:com.liato.bankdroid.banking.banks.Steam.java
@Override public Urllib login() throws LoginException, BankException { try {/*from ww w .j av a2s . co m*/ LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("Enter the characters above")) { throw new BankException( "You have entered the wrong username/password too many times and Steam now requires you to enter a CAPTCHA.\nPlease wait 10 minutes before logging in again."); } if (response.contains("Incorrect login.")) { 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; }