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.FirstCard.java

@Override
public Urllib login() throws LoginException, BankException {
    try {/* w  w w . j ava 2 s  . co  m*/
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (response.contains("Logga in med din kod")) {
            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.AbsIkanoPartner.java

@Override
public Urllib login() throws LoginException, BankException {
    try {/*from w  w  w  .  ja  v  a2s.  c om*/
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (response.contains("eller personnumme") || response.contains("elaktigt personnummer")
                || response.contains("ontrollera personnummer") || response.contains("elaktig inloggningskod")
                || response.contains("elaktig sjlvbetjningskod")) {
            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.Osuuspankki.java

@Override
public Urllib login() throws LoginException, BankException {
    try {/*from  w w w.  j  a v a  2s  . c om*/
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());

        if (response.contains("du nya koder genom att bes")) {
            throw new LoginException(res.getText(R.string.invalid_username_password).toString());
        }
    } catch (ClientProtocolException e) {
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new BankException(e.getMessage());
    }
    return urlopen;
}

From source file:org.apache.airavata.client.secure.client.OAuthTokenRetrievalClient.java

/**
 * Retrieve the OAuth Access token via the specified grant type.
 * @param consumerId/*www.j  a v a 2  s.c om*/
 * @param consumerSecret
 * @param userName
 * @param password
 * @param grantType
 * @return
 * @throws SecurityException
 */
public String retrieveAccessToken(String consumerId, String consumerSecret, String userName, String password,
        int grantType) throws AiravataSecurityException {

    HttpPost postMethod = null;
    try {
        //initialize trust store to handle SSL handshake with WSO2 IS properly.
        TrustStoreManager trustStoreManager = new TrustStoreManager();
        SSLContext sslContext = trustStoreManager.initializeTrustStoreManager(Properties.TRUST_STORE_PATH,
                Properties.TRUST_STORE_PASSWORD);
        //create https scheme with the trust store
        org.apache.http.conn.ssl.SSLSocketFactory sf = new org.apache.http.conn.ssl.SSLSocketFactory(
                sslContext);
        Scheme httpsScheme = new Scheme("https", sf, Properties.authzServerPort);

        HttpClient httpClient = new DefaultHttpClient();
        //set the https scheme in the httpclient
        httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme);

        postMethod = new HttpPost(Properties.oauthTokenEndPointURL);
        //build the HTTP request with relevant params for resource owner credential grant type
        String authInfo = consumerId + ":" + consumerSecret;
        String authHeader = new String(Base64.encodeBase64(authInfo.getBytes()));

        postMethod.setHeader("Content-Type", "application/x-www-form-urlencoded");
        postMethod.setHeader("Authorization", "Basic " + authHeader);

        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();

        if (grantType == 1) {
            urlParameters.add(new BasicNameValuePair("grant_type", "password"));
            urlParameters.add(new BasicNameValuePair("username", userName));
            urlParameters.add(new BasicNameValuePair("password", password));

        } else if (grantType == 2) {
            urlParameters.add(new BasicNameValuePair("grant_type", "client_credentials"));
        }

        postMethod.setEntity(new UrlEncodedFormEntity(urlParameters));

        HttpResponse response = httpClient.execute(postMethod);

        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        StringBuilder result = new StringBuilder();
        String line = "";
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }

        JSONParser parser = new JSONParser();
        JSONObject jsonObject = (JSONObject) parser.parse(result.toString());
        return (String) jsonObject.get("access_token");
    } catch (ClientProtocolException e) {
        throw new AiravataSecurityException(e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new AiravataSecurityException(e.getMessage(), e);
    } catch (IOException e) {
        throw new AiravataSecurityException(e.getMessage(), e);
    } catch (ParseException e) {
        throw new AiravataSecurityException(e.getMessage(), e);
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
    }
}

From source file:com.liato.bankdroid.banking.banks.Avanza.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 . ja  v  a2 s. com*/
    Urllib urlopen = login();
    String response = null;
    Matcher matcher;
    try {
        response = urlopen.open("https://www.avanza.se/aza/depa/sammanfattning/sammanfattning.jsp");

        matcher = reAccounts.matcher(response);
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                EXAMPLE DATA
             * 1: ID                3505060
             * 2: Type              Aktie- och fondkonto Premium Silver
             * 3: % since purchase  1,90
             * 4: Amount in SEK     820
             *    
             */
            accounts.add(new Account(Html.fromHtml(matcher.group(1)).toString().trim(),
                    Helpers.parseBalance(matcher.group(4)), matcher.group(1).trim()));
            balance = balance.add(Helpers.parseBalance(matcher.group(4)));
        }
        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.BetterGlobe.java

public Urllib login() throws LoginException, BankException {
    try {//from  w  w w .  j  a v  a  2 s .c om
        LoginPackage lp = preLogin();
        String response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
    } 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.TicketRikskortet.java

public Urllib login() throws LoginException, BankException {
    try {//from ww  w .jav  a 2 s  .  c  o m
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (response.contains("Inloggningen misslyckades")) {
            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.vsearchd.crawler.backend.BackendSessionHTTPS.java

private void handleOutputMessage() throws Exception {

    try {//from   www  .  ja va2 s  .com
        para.clear();

        for (OutputField field : this.message.getFields()) {
            para.add(new BasicNameValuePair(field.getName(), URLEncoder.encode(field.getValue(), "UTF-8")));
        }

        url = "https://" + this.getBackendServer().getHost() + ":"
                + String.valueOf(this.getBackendServer().getPort()) + "/"
                + this.getBackendServer().getFilePath();
        httpclient.getConnectionManager().getSchemeRegistry().register(this.getHttpSslTheme(url));

        formEntity = new UrlEncodedFormEntity(para);
        httppost.setURI(new URI(url));

        httppost.setEntity(formEntity);
        response = httpclient.execute(httppost);

        entity = response.getEntity();
        log.debug(response.getStatusLine().getReasonPhrase());

        instr = entity.getContent();
        while (instr.read() > -1)
            ;
        instr.close();

    } catch (ClientProtocolException e) {
        log.error(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage());
    } catch (URISyntaxException e) {
        log.error(e.getMessage());
    }
}

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

@Override
public Urllib login() throws LoginException, BankException {
    try {/* w ww . j ava2s . co m*/
        //LoginPackage lp = preLoginNonMobile();
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (response.contains("Felaktigt 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;
}

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

@Override
public Urllib login() throws LoginException, BankException {

    try {/*ww w.  j a  v a  2s .  c  o m*/
        LoginPackage lp = preLogin();
        String response = urlopen.open(lp.getLoginTarget(), lp.getPostData());

        if (response.contains("misslyckats")) {
            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;
}