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

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.liato.bankdroid.banking.banks.FirstCard.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  v  a 2  s .  com*/
    urlopen = login();
    try {
        response = urlopen.open("https://www.firstcard.se/mkol/index.jsp");
        Matcher matcher = reAccounts.matcher(response);
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP            EXAMPLE DATA
             * 1: id            kdKPq4ghlcy9wpXymSzzS46wWQcS_0OT
             * 2: account number   1111 3333 7777 9999
             * 3: amount          9 824,08
             * 
             */
            accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                    Helpers.parseBalance(matcher.group(3)), 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) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        super.updateComplete();
    }
}

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

public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);
    Matcher matcher;//from  w  w  w.j a v  a 2  s . c  o  m
    try {
        String accountWebId = accountIds.get(Integer.parseInt(account.getId()));
        response = urlopen.open("https://m.handelsbanken.se/primary/_-" + accountWebId);
        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))));
        }

        // Sort transactions by date
        Collections.sort(transactions, new Comparator<Transaction>() {
            public int compare(Transaction t1, Transaction t2) {
                return t2.compareTo(t1);
            }
        });

        account.setTransactions(transactions);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:at.ac.tuwien.dsg.rSybl.cloudInteractionUnit.enforcementPlugins.governance.GovOpsPlugin.java

public String callPOSTMethod(String methodName, String reqType, String body) {
    try {// www  .j av  a 2 s  .  c  o m

        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpPost postRequest = new HttpPost(REST_API_URL + "/" + methodName);
        postRequest.addHeader("accept", reqType);
        HttpEntity entity = new ByteArrayEntity(body.getBytes("UTF-8"));
        postRequest.setEntity(entity);
        HttpResponse response = httpClient.execute(postRequest);
        if (response.getStatusLine().getStatusCode() != 200) {
            System.err.println("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()
                    + reqType + ":" + methodName);
        }
        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
        String o;
        System.out.println("============Output:============");
        String output = "";
        while ((o = br.readLine()) != null) {
            output += o;
        }
        return output;

    } catch (ClientProtocolException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

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

public Urllib login() throws LoginException, BankException {
    try {//w w w.  j  av a  2 s. com
        LoginPackage lp = preLogin();
        response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
        if (response.contains("Felaktigt anv")) {
            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:info.androidhive.androidsplashscreentimer.WOEIDUtils.java

private String fetchWOEIDxmlString(Context context, String queryString) {
    MyLog.d("fetch WOEID xml string");
    String qResult = "";

    HttpClient httpClient = NetworkUtils.createHttpClient();

    HttpGet httpGet = new HttpGet(queryString);

    try {/*w  w  w. j av  a  2 s  .c om*/
        HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            Reader in = new InputStreamReader(inputStream);
            BufferedReader bufferedreader = new BufferedReader(in);
            StringBuilder stringBuilder = new StringBuilder();

            String readLine = null;

            while ((readLine = bufferedreader.readLine()) != null) {
                MyLog.d(readLine);
                stringBuilder.append(readLine + "\n");
            }

            qResult = stringBuilder.toString();
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (ConnectTimeoutException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

    return qResult;
}

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

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);

    Matcher matcher;/*www .  j  a v  a  2s.c o  m*/
    try {
        response = urlopen.open(String.format("https://www.op.fi/?id=%s&tilinro=%s&ecb=1&srcpl=4",
                (account.getType() == Account.OTHER ? "12701" : "12401"), account.getId()));
        matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                    EXAMPLE DATA
             * 1: Book. date            21.01
             * 2: Trans. date           20.01
             * 3: Description           ITUNES-EURO LUXEMBOURG
             * 4: Transaction type      BANKKORTSBET.
             * 5: Amount in EUR         -3,99 
             * 
             */
            String[] date = Html.fromHtml(matcher.group(2)).toString().trim().split(".");
            Transaction transaction = new Transaction(Helpers.getTransactionDate(date[1], date[0]),
                    Html.fromHtml(matcher.group(3)).toString().trim(), Helpers.parseBalance(matcher.group(5)));
            transaction.setCurrency(account.getCurrency());
            transactions.add(transaction);
        }
        account.setTransactions(transactions);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.wso2.ml.client.MLClient.java

public CloseableHttpResponse createProject(JSONObject projectConf) {
    CloseableHttpClient httpClient = HttpClients.createDefault();

    HttpPost httpPost = new HttpPost(mlHost + "/api/projects");
    httpPost.setHeader(MLConstants.AUTHORIZATION_HEADER, getBasicAuthKey());
    httpPost.setHeader(MLConstants.CONTENT_TYPE, MLConstants.CONTENT_TYPE_APPLICATION_JSON);

    String projectName = projectConf.get("name").toString();
    String datasetName = projectConf.get("datasetName").toString();

    try {/*w  ww.  jav a 2  s.c  o  m*/
        String payload;
        if (projectName == null) {
            payload = "{\"description\" : \"Test Project\",\"datasetName\": \"" + datasetName + "\"}";
        } else if (datasetName == null) {
            payload = "{\"name\" : \"" + projectName + "\",\"description\" : \"Test Project\"}";
        } else {
            payload = "{\"name\" : \"" + projectName
                    + "\",\"description\" : \"Test Project\",\"datasetName\": \"" + datasetName + "\"}";
        }

        StringEntity params = new StringEntity(payload);
        httpPost.setEntity(params);
        return httpClient.execute(httpPost);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

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

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);

    String response = null;//w w w .ja v a  2 s .c  o m
    Matcher matcher;
    try {
        response = urlopen.open("https://www.edenred.se/sv/Apps/Employee/Start/Transaktioner/");
        matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();

        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                EXAMPLE DATA
             * 1: Trans. date       2012-06-01
             * 2: Specification     DANMARKSG  KISTA
             * 3: Amount            - 85 kr
             * 
             */

            transactions.add(new Transaction(matcher.group(1),
                    Html.fromHtml(matcher.group(2).trim()).toString(), Helpers.parseBalance(matcher.group(3))));
        }
        account.setTransactions(transactions);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.nolanofra.test.lazyLoader.MainActivity.java

public String executeGet(String url) {
    int timeout = 5000;
    HttpGet get;//  ww  w.  j  a  v a 2s  . c o m
    InputStream instream;
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeout);
    HttpClient client = new DefaultHttpClient();

    String jsonText = "";
    get = new HttpGet(url);
    HttpResponse response = null;
    instream = null;

    try {
        try {
            response = client.execute(get);
        } catch (ClientProtocolException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        int status = response.getStatusLine().getStatusCode();

        if (status == HttpStatus.SC_OK) {
            HttpEntity entity = response.getEntity();

            try {
                instream = entity.getContent();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            jsonText = convertStreamToString(instream);
        }
    } catch (Exception e) {
    }
    return jsonText;
}

From source file:messenger.PlurkApi.java

public String logout() {
    PlurkApi p = PlurkApi.getInstance();
    if (cookiestore == null)
        p.login();//from   w w w  .j a v  a  2s  . c o m
    DefaultHttpClient httpclient = new DefaultHttpClient();
    if (use_proxy) {
        HttpHost proxy = new HttpHost(PROXY_NAME, PROXY_PORT);
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    httpclient.setCookieStore(cookiestore);

    HttpResponse response = null;
    String responseString = null;
    try {
        HttpGet httpget = new HttpGet(getApiUri("/Users/logout?" + "api_key=" + API_KEY));
        response = httpclient.execute(httpget);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            cookiestore = httpclient.getCookieStore();
            responseString = EntityUtils.toString(response.getEntity());
            // pG^O 200 OK ~X
            // System.out.println(responseString);
            //
        } else {
            System.out.println(response.getStatusLine());
            responseString = EntityUtils.toString(response.getEntity());
            System.out.println(responseString);
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    httpclient.getConnectionManager().shutdown();
    return responseString;
}