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

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);
    if (!urlopen.acceptsInvalidCertificates()) { //Should never happen, but we'll check it anyway.
        urlopen = login();//from   w  w  w . j ava  2s  .  c  om
    }
    if (account.getType() != Account.CCARD)
        return;
    String response = null;
    Matcher matcher;
    try {
        Log.d(TAG, "Opening: https://applications.sebkort.com/nis/stse/getPendingTransactions.do");
        response = urlopen.open("https://applications.sebkort.com/nis/stse/getPendingTransactions.do");
        matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        Calendar cal = Calendar.getInstance();
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP            EXAMPLE DATA
             * 1: Trans. date      10-18
             * 2: Book. date      10-19
             * 3: Specification      ICA Kvantum
             * 4: Location         Stockholm
             * 5: Currency         always empty?
             * 6: Amount         always empty?
             * 7: Amount in sek      5791,18
             * 
             */
            transactions.add(new Transaction("" + cal.get(Calendar.YEAR) + "-" + matcher.group(1).trim(),
                    Html.fromHtml(matcher.group(3)).toString().trim() + (matcher.group(4).trim().length() > 0
                            ? " (" + Html.fromHtml(matcher.group(4)).toString().trim() + ")"
                            : ""),
                    Helpers.parseBalance(matcher.group(7)).negate()));
        }
        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.phonty.improved.Contacts.java

public boolean add(String phone, String name) {
    StringBuilder builder = new StringBuilder();
    try {/*from  ww  w.ja v  a  2  s. c om*/
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("phone", phone));
        nvps.add(new BasicNameValuePair("name", name));

        httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse response = client.execute(httppost);

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
                VALUE = Parse(line);
            }
        } else {
            this.VALUE = "0.0";
        }
    } catch (ClientProtocolException e) {
        this.VALUE = "Protocol exception";
        e.printStackTrace();
    } catch (IOException e) {
        this.VALUE = "I.O. Exception";
        e.printStackTrace();
    }

    try {
        if (Integer.parseInt(VALUE) > 0)
            return true;
    } catch (NumberFormatException e) {
        return false;
    }
    return false;
}

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

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);
    if (account.getId().startsWith("a:") || !mIdMappings.containsKey(account.getId()))
        return; // No transactions for "saldo"-accounts
    String accountId = mIdMappings.get(account.getId());
    String response = null;// ww  w  .j  av  a 2s . c o m
    Matcher matcher;
    try {
        response = urlopen
                .open("https://online.akeliusinvest.com/AccountStatement.mws?selectedaccount=" + accountId);
        matcher = reTransactions.matcher(response);
        /*             ICA-banken   Akelius Invest
         * Beskrivning   1         2
         * Datum      2         1
         * Belopp      3         3
         */

        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);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);
    if (account.getId().startsWith("a:") || !mIdMappings.containsKey(account.getId()))
        return; // No transactions for "saldo"-accounts
    String accountId = mIdMappings.get(account.getId());
    String response = null;//from   w  ww  . j  a v a 2s  .  com
    Matcher matcher;
    try {
        response = urlopen
                .open("https://www.online.akeliusspar.se/AccountStatement.mws?selectedaccount=" + accountId);
        matcher = reTransactions.matcher(response);
        /*             ICA-banken   Akelius Invest
         * Beskrivning   1         2
         * Datum      2         1
         * Belopp      3         3
         */

        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);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:es.uma.lcc.tasks.SendUpdateTask.java

@Override
public Void doInBackground(Void... args) {
    DefaultHttpClient httpclient = new DefaultHttpClient();

    final HttpParams params = new BasicHttpParams();
    HttpClientParams.setRedirecting(params, false);
    httpclient.setParams(params);//from ww  w .  j a va  2  s.c  o m
    String target = SERVERURL + "?" + QUERYSTRING_ACTION + "=" + ACTION_UPDATE + "&" + QUERYSTRING_PICTUREID
            + "=" + mPicId;
    HttpPost httppost = new HttpPost(target);
    while (mCookie == null)
        mCookie = mMainActivity.getCurrentCookie();

    httppost.setHeader("Cookie", mCookie.getName() + "=" + mCookie.getValue());

    String jsonOperations = buildUpdateOperations(mOperations, mPicId);
    try {
        StringEntity permissionsEntity = new StringEntity(jsonOperations);
        permissionsEntity.setContentType(new BasicHeader("Content-Type", "application/json"));
        httppost.setEntity(permissionsEntity);
        HttpResponse response = httpclient.execute(httppost);

        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() != 200) {
            throw new IOException("Invalid response from server: " + status.toString());
        }

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = entity.getContent();
            ByteArrayOutputStream content = new ByteArrayOutputStream();

            // Read response into a buffered stream
            int readBytes = 0;
            byte[] sBuffer = new byte[256];
            while ((readBytes = inputStream.read(sBuffer)) != -1) {
                content.write(sBuffer, 0, readBytes);
            }
            String result = new String(content.toByteArray());

            try {
                JSONArray jsonArray = new JSONArray(result);
                if (jsonArray.length() == 0) {
                    // should never happen
                    Log.e(APP_TAG, LOG_ERROR + ": Malformed response from server");
                } else {
                    // Elements in a JSONArray keep their order
                    JSONObject successState = jsonArray.getJSONObject(0);
                    if (successState.get(JSON_RESULT).equals(JSON_RESULT_ERROR)) {
                        if (successState.getBoolean(JSON_ISAUTHERROR) && mIsFirstRun) {
                            mIsAuthError = true;
                        } else {
                            Log.e(APP_TAG,
                                    LOG_ERROR + ": Server found an error: " + successState.get(JSON_REASON));
                        }
                    } else {// result is ok, if there were modifications we notify the user
                        if (mOperations != null && mOperations.size() > 0)
                            mIsSuccessfulUpdate = true;
                    }
                }
            } catch (JSONException jsonEx) {
                Log.e(APP_TAG, LOG_ERROR + ": Malformed JSON response from server");
            }
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:no.ntnu.idi.socialhitchhiking.myAccount.MyAccountMeActivity.java

/**
 * Getting the user information from the database.
 * @param params//from   w  w w.  j  av  a  2s  .c  o m
 * @return
 */
protected UserResponse doInBackground(Void... params) {
    UserResponse res = null;
    try {
        Request req = new UserRequest(RequestType.GET_USER, activity.getApp().getUser());
        res = (UserResponse) RequestTask.sendRequest(req, activity.getApp());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return res;
}

From source file:org.megam.deccanplato.provider.salesforce.chatter.handler.FeedImpl.java

/**
 * Comment post not working/*from  w ww  .ja  v a2  s  . co  m*/
 * @param outMap
 * @return
 */
private Map<String, String> postcomment() {

    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_CHATTER_URL = args.get(INSTANCE_URL) + "/services/data/v25.0/chatter/feed-items/"
            + args.get(ID) + "/comments?";
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));
    Gson gson = new Gson();
    Map<String, Object> accountAttrMap = new HashMap<String, Object>();

    accountAttrMap.put(S_TEXT, gson.toJson(new Post(args.get(TYPE), args.get(TEXT))));

    TransportTools tst = new TransportTools(SALESFORCE_CHATTER_URL, null, header);
    Gson obj = new GsonBuilder().setPrettyPrinting().create();
    tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(accountAttrMap));
    try {
        String response = TransportMachinery.post(tst).entityToString();
        outMap.put(OUTPUT, response);

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outMap;
}

From source file:zjut.soft.finalwork.fragment.LeftFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.left, null);

    iv1 = (ImageView) view.findViewById(R.id.left_iv1);
    iv2 = (ImageView) view.findViewById(R.id.left_iv2);
    iv3 = (ImageView) view.findViewById(R.id.left_iv3);
    iv4 = (ImageView) view.findViewById(R.id.left_iv4);
    iv5 = (ImageView) view.findViewById(R.id.left_iv5);
    headTV = (ImageView) view.findViewById(R.id.sliding_activity_head_view);
    headTV.setOnClickListener(new View.OnClickListener() {

        @Override/*from   w  w w .ja  va2 s .  c o  m*/
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), BasicInfoUI.class);
            i.putExtra("myportrait", portraitBitmap);
            getActivity().startActivity(i);
            getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }
    });
    TextView tv = (TextView) view.findViewById(R.id.sliding_activity_name_tv);
    YCApplication app = (YCApplication) this.getActivity().getApplication();
    tv.setText(app.get("name").toString()); // 
    //      portrait = (ImageView) view.findViewById(R.id.sliding_activity_head_view);

    final String url = ((YCApplication) getActivity().getApplication()).get("selectedIp")
            + Constant.portraitContext;

    new Thread(new Runnable() {

        @Override
        public void run() {
            HttpGet get = new HttpGet(url);

            try {
                DefaultHttpClient client = ((YCApplication) getActivity().getApplicationContext()).getClient();
                synchronized (client) {
                    HttpResponse response = client.execute(get);
                    HttpEntity entity = response.getEntity();
                    InputStream is = entity.getContent();

                    portraitBitmap = BitmapFactory.decodeStream(is); // 
                    is.close();
                    Message msg = mHandler.obtainMessage();
                    msg.obj = portraitBitmap;
                    mHandler.sendMessage(msg);
                }

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

        }
    }).start();

    TextView username = (TextView) view.findViewById(R.id.sliding_activity_username_textview);
    username.setText(app.get("username").toString()); // 
    userConfTV = (TextView) view.findViewById(R.id.sliding_activity_user_manage); // 
    payQueryTV = (TextView) view.findViewById(R.id.sliding_activity_pay_query); // 
    querySystemTV = (TextView) view.findViewById(R.id.sliding_activity_query_system); // 
    aboutUsTV = (TextView) view.findViewById(R.id.sliding_activity_about_us); // 
    unRegisterTV = (TextView) view.findViewById(R.id.sliding_activity_unregister_user); // 
    classNameTV = (TextView) view.findViewById(R.id.sliding_activity_class_tv); // 

    registTV = (TextView) view.findViewById(R.id.sliding_activity_regist_system); // 
    pickCourseTV = (TextView) view.findViewById(R.id.sliding_activity_pick_course_system); // 
    RatingTV = (TextView) view.findViewById(R.id.sliding_activity_student_rating); // 
    return view;
}

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

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);
    if (!urlopen.acceptsInvalidCertificates()) { //Should never happen, but we'll check it anyway.
        urlopen = login();//from  w w w . j a v a 2  s  .c  om
    }
    if (account.getType() != Account.CCARD)
        return;
    String response = null;
    Matcher matcher;
    try {
        response = urlopen.open(String
                .format("https://application.sebkort.com/nis/%s/getPendingTransactions.do", provider_part));
        matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP            EXAMPLE DATA
             * 1: Trans. date      10-18
             * 2: Book. date      10-19
             * 3: Specification      ICA Kvantum
             * 4: Location         Stockholm
             * 5: Currency         currency code (e.g. EUR) for transactions in non-SEK
             * 6: Amount         local currency amount (in $currency) for transactions in non-SEK
             * 7: Amount in sek      5791,18
             * 
             */
            String[] monthday = matcher.group(1).trim().split("-");
            transactions.add(new Transaction(Helpers.getTransactionDate(monthday[0], monthday[1]),
                    Html.fromHtml(matcher.group(3)).toString().trim() + (matcher.group(4).trim().length() > 0
                            ? " (" + Html.fromHtml(matcher.group(4)).toString().trim() + ")"
                            : ""),
                    Helpers.parseBalance(matcher.group(7)).negate()));
            Collections.sort(transactions, Collections.reverseOrder());
        }
        account.setTransactions(transactions);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}