Example usage for org.apache.http.client ClientProtocolException getMessage

List of usage examples for org.apache.http.client ClientProtocolException getMessage

Introduction

In this page you can find the example usage for org.apache.http.client ClientProtocolException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.liato.bankdroid.banking.banks.BrummerKF.java

public Urllib login() throws LoginException, BankException {
    try {//from   ww  w.  ja  v  a 2 s . c  o  m
        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("Personnummer")) {
                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.AmericanExpress.java

@Override
public Urllib login() throws LoginException, BankException {
    try {/* ww  w  . ja  va  2 s .  c  o m*/
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());

        if (!response.contains("Your Personal Cards")) {
            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:com.liato.bankdroid.banking.banks.Coop.java

@Override
public Urllib login() throws LoginException, BankException {
    try {//from   w  ww  .ja va2 s  .  c  o m
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (response.contains("forfarande logga in med ditt personnummer")) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            if (prefs.getBoolean("debug_mode", false) && prefs.getBoolean("debug_coop_sendmail", false)) {
                Intent i = new Intent(android.content.Intent.ACTION_SEND);
                i.setType("plain/text");
                i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "android@nullbyte.eu" });
                i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Bankdroid - Coop Error");
                i.putExtra(android.content.Intent.EXTRA_TEXT, response);
                context.startActivity(i);
            }
            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:com.liato.bankdroid.banking.banks.ICABanken.java

public Urllib login() throws LoginException, BankException {
    try {//from   w w  w .java  2  s  .co  m
        LoginPackage lp = preLogin();
        String response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        Matcher matcher = reError.matcher(response);
        if (matcher.find()) {
            throw new LoginException(Html.fromHtml(matcher.group(1).trim()).toString());
        }
    } catch (ClientProtocolException e) {
        Log.d(TAG, "ClientProtocolException: " + e.getMessage());
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, "IOException: " + e.getMessage());
        throw new BankException(e.getMessage());
    }
    return urlopen;
}

From source file:com.liato.bankdroid.banking.banks.ICABanken.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());
    }//  w w  w  .j ava 2 s. c  om

    urlopen = login();
    String response = null;
    Matcher matcher;
    try {
        response = urlopen.open("https://mobil2.icabanken.se/account/overview.aspx");
        //response = urlopen.open("http://x.x00.us/android/bankdroid/icabanken_oversikt.htm");
        matcher = reBalanceSald.matcher(response);
        while (matcher.find()) {
            accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                    Helpers.parseBalance(matcher.group(3).trim()), matcher.group(1).trim()));
            balance = balance.add(Helpers.parseBalance(matcher.group(3)));
        }
        matcher = reBalanceDisp.matcher(response);
        while (matcher.find()) {
            accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                    Helpers.parseBalance(matcher.group(3).trim()), matcher.group(1).trim()));
            balance = balance.add(Helpers.parseBalance(matcher.group(3)));
        }
        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());
    }
}

From source file:org.activiti.rest.service.api.runtime.SerializableVariablesDiabledTest.java

public void assertResponseStatus(HttpUriRequest request, int expectedStatusCode) {
    CloseableHttpResponse response = null;
    try {//from   w ww .java  2  s.  co  m

        CredentialsProvider provider = new BasicCredentialsProvider();
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("kermit", "kermit");
        provider.setCredentials(AuthScope.ANY, credentials);
        HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();

        response = (CloseableHttpResponse) client.execute(request);
        int statusCode = response.getStatusLine().getStatusCode();
        Assert.assertEquals(expectedStatusCode, statusCode);

        if (client instanceof CloseableHttpClient) {
            ((CloseableHttpClient) client).close();
        }

        response.close();

    } catch (ClientProtocolException e) {
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }

}

From source file:com.github.matthesrieke.simplebroker.AbstractConsumer.java

@Override
public synchronized void consume(String cotent, ContentType contentType, String origin) {
    for (String url : getTargetUrls()) {
        HttpPost post = new HttpPost(url);

        post.setEntity(createEntity(cotent, contentType));
        HttpResponse response = null;// www  .  j  a va  2 s . c o m
        try {
            response = this.client.execute(post);
            logger.info("Content posted to " + url);
        } catch (ClientProtocolException e) {
            logger.warn(e.getMessage(), e);
        } catch (IOException e) {
            logger.warn(e.getMessage(), e);
        } finally {
            if ((response != null) && (response.getEntity() != null))
                try {
                    EntityUtils.consume(response.getEntity());
                } catch (IOException e) {
                    logger.warn(e.getMessage(), e);
                }
        }
    }
}

From source file:net.ccghe.emocha.async.UploadOneFile.java

public UploadOneFile(String path, String serverURL, FileTransmitter transmitter, MultipartEntity postData) {
    // configure connection
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 20 * Constants.ONE_SECOND);
    HttpConnectionParams.setSoTimeout(params, 20 * Constants.ONE_SECOND);
    HttpClientParams.setRedirecting(params, false);

    // setup client
    DefaultHttpClient client = new DefaultHttpClient(params);

    HttpPost post = new HttpPost(serverURL);

    int id = 0;/*from  w ww .  j a v a 2  s.c o  m*/
    postData.addPart("file" + id, new FileBody(new File(path)));
    try {
        postData.addPart("path" + id, new StringBody(path));
    } catch (UnsupportedEncodingException e1) {
        Log.e(Constants.LOG_TAG, "Encoding error while uploading file.");
    }

    // prepare response and return uploaded
    try {
        post.setEntity(postData);
        HttpResponse response = client.execute(post);

        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        String jsonResponse = Server.convertStreamToString(stream);
        stream.close();
        if (postData != null) {
            postData.consumeContent();
        }
        JSONObject jObject = new JSONObject(jsonResponse);

        Long ok = jObject.getLong("ok");

        if (ok > 0) {
            DBAdapter.markAsUploaded(path);
            Log.i(Constants.LOG_TAG, "Mark as uploaded: " + path);
        } else {
            Log.e(Constants.LOG_TAG, "Error uploading: " + path + " (json response not ok)");
        }
    } catch (ClientProtocolException e) {
        Log.e("EMOCHA", "ClientProtocolException ERR. " + e.getMessage());
    } catch (IOException e) {
        Log.e("EMOCHA", "IOException ERR. " + e.getMessage());
    } catch (Exception e) {
        Log.e("EMOCHA", "Exception ERR. " + e.getMessage());
    }

    /*
    // check response.
    // TODO: This isn't handled correctly.
    String serverLocation = null;
    Header[] h = response.getHeaders("Location");
    if (h != null && h.length > 0) {
       serverLocation = h[0].getValue();
    } else {
       // something should be done here...
       Log.e(Constants.LOG_TAG, "Location header was absent");
    }
    int responseCode = response.getStatusLine().getStatusCode();
    Log.e(Constants.LOG_TAG, "Response code:" + responseCode);
            
    // verify that your response came from a known server
    if (serverLocation != null && serverURL.contains(serverLocation)
    && responseCode == 201) {
       DBAdapter.markAsUploaded(path);
    }
    */
    transmitter.transmitComplete();
}

From source file:com.liato.bankdroid.banking.banks.PayPal.java

@Override
public Urllib login() throws LoginException, BankException {
    try {//  w  ww . j  a  v a2 s  . c o  m
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (response.contains("If you still can't log in")
                || response.contains("both your email address and password")) {
            throw new LoginException(res.getText(R.string.invalid_username_password).toString());
        }
        if (response.contains("your last action could not be completed")) {
            throw new BankException("Error: PPL92");
        }
    } catch (ClientProtocolException e) {
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        throw new BankException(e.getMessage());
    }
    return urlopen;
}

From source file:com.liato.bankdroid.banking.banks.DinersClub.java

public Urllib login() throws LoginException, BankException {
    try {/*from   w  w w  .j a  v  a 2s. c  o  m*/
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (response.contains("Har du glmt ditt lsenord")) {
            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;
}