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.michael.feng.utils.YahooWeather4a.YahooWeatherUtils.java

private String getWeatherString(Context context, String woeidNumber) {
    String qResult = "";
    String queryString = "http://weather.yahooapis.com/forecastrss?w=" + woeidNumber;

    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(queryString);

    try {//from w w  w .  j av  a  2s.  co m
        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 stringReadLine = null;

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

            qResult = stringBuilder.toString();
        }

    } catch (ClientProtocolException 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();
    }

    return qResult;
}

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

/**
 * This method takes input as group id and returns all grooup members 
 * from that group. /*from   w w  w. j ava 2 s. com*/
 * @param outMap(group id)
 * @return list of members from that group
 */
private Map<String, String> member() {
    Map<String, String> outMap = new HashMap<String, String>();
    final String SALESFORCECRM_CHATTER_URL = "/services/data/v25.0/chatter/groups/" + args.get(ID) + "/members";
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCECRM_CHATTER_URL, null, header);

    try {
        String response = TransportMachinery.get(tst).entityToString();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return outMap;
}

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

/**
 * this method returns membership id from a group
 * it takes group id as argument/*from  w  ww . j  a  v  a 2  s  . c om*/
 * @param outMap
 * @return returns membership details
 */
private Map<String, String> membership() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCECRM_CHATTER_URL = "/services/data/v25.0/chatter/group-memberships/" + args.get(ID);
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCECRM_CHATTER_URL, null, header);
    try {
        String response = TransportMachinery.get(tst).entityToString();
        outMap.put(OUTPUT, response);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return outMap;
}

From source file:org.digitalcampus.oppia.task.DownloadMediaTask.java

@Override
protected Payload doInBackground(Payload... params) {
    Payload payload = params[0];//from   ww w . j  ava 2 s.c o m
    for (Object o : payload.getData()) {
        Media m = (Media) o;
        File file = new File(MobileLearning.MEDIA_PATH, m.getFilename());
        try {

            URL u = new URL(m.getDownloadUrl());
            HttpURLConnection c = (HttpURLConnection) u.openConnection();
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();
            c.setConnectTimeout(
                    Integer.parseInt(prefs.getString(ctx.getString(R.string.prefs_server_timeout_connection),
                            ctx.getString(R.string.prefServerTimeoutConnection))));
            c.setReadTimeout(
                    Integer.parseInt(prefs.getString(ctx.getString(R.string.prefs_server_timeout_response),
                            ctx.getString(R.string.prefServerTimeoutResponse))));

            int fileLength = c.getContentLength();

            DownloadProgress dp = new DownloadProgress();
            dp.setMessage(m.getFilename());
            dp.setProgress(0);
            publishProgress(dp);

            FileOutputStream f = new FileOutputStream(file);
            InputStream in = c.getInputStream();

            MessageDigest md = MessageDigest.getInstance("MD5");
            in = new DigestInputStream(in, md);

            byte[] buffer = new byte[8192];
            int len1 = 0;
            long total = 0;
            int progress = 0;
            while ((len1 = in.read(buffer)) > 0) {
                total += len1;
                progress = (int) (total * 100) / fileLength;
                if (progress > 0) {
                    dp.setProgress(progress);
                    publishProgress(dp);
                }
                f.write(buffer, 0, len1);
            }
            f.close();

            dp.setProgress(100);
            publishProgress(dp);

            // check the file digest matches, otherwise delete the file 
            // (it's either been a corrupted download or it's the wrong file)
            byte[] digest = md.digest();
            String resultMD5 = "";

            for (int i = 0; i < digest.length; i++) {
                resultMD5 += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1);
            }

            Log.d(TAG, "supplied   digest: " + m.getDigest());
            Log.d(TAG, "calculated digest: " + resultMD5);

            if (!resultMD5.contains(m.getDigest())) {
                this.deleteFile(file);
                payload.setResult(false);
                payload.setResultResponse(ctx.getString(R.string.error_media_download));
            } else {
                payload.setResult(true);
                payload.setResultResponse(ctx.getString(R.string.success_media_download, m.getFilename()));
            }
        } catch (ClientProtocolException e1) {
            e1.printStackTrace();
            payload.setResult(false);
            payload.setResultResponse(ctx.getString(R.string.error_media_download));
        } catch (IOException e1) {
            e1.printStackTrace();
            this.deleteFile(file);
            payload.setResult(false);
            payload.setResultResponse(ctx.getString(R.string.error_media_download));
        } catch (NoSuchAlgorithmException e) {
            if (!MobileLearning.DEVELOPER_MODE) {
                BugSenseHandler.sendException(e);
            } else {
                e.printStackTrace();
            }
            payload.setResult(false);
            payload.setResultResponse(ctx.getString(R.string.error_media_download));
        }
    }
    return payload;
}

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

/**
 * this method takes input as group id and returns list of 
 * files from that group. group id is taken from group membership subscription
 * @param outMap(user group id)/*  ww w.j  av  a2 s.com*/
 * @return list of files from that group
 */
private Map<String, String> file() {
    Map<String, String> outMap = new HashMap<String, String>();
    final String SALESFORCECRM_CHATTER_URL = "/services/data/v25.0/chatter/groups/" + args.get(ID) + "/files";
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCECRM_CHATTER_URL, null, header);

    try {
        String response = TransportMachinery.get(tst).entityToString();
        outMap.put(OUTPUT, response);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return outMap;
}

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

/**
 * this method returns a particular group details
 * it takes group id from group membership method implementation
 * @param outMap(Group id)/*from w w w.  j  a v  a2s. co  m*/
 * @return details about a group
 */
private Map<String, String> view() {
    Map<String, String> outMap = new HashMap<String, String>();
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(
            args.get(INSTANCE_URL) + SALESFORCECRM_CHATTER_MESSAGE_URL + args.get(ID), null, header);

    try {
        String response = TransportMachinery.get(tst).entityToString();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return outMap;

}

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

/**
 * This method lists all groups in an organization
 * @param outMap/*from w w  w  .  j  a  v a 2 s.co  m*/
 * @return returns group id and group details.
 */
private Map<String, String> list() {
    Map<String, String> outMap = new HashMap<>();
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCECRM_CHATTER_MESSAGE_URL, null,
            header);

    try {
        String response = TransportMachinery.get(tst).entityToString();
        outMap.put(OUTPUT, response);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return outMap;
}

From source file:uk.ac.ebi.phenotype.web.util.BioMartBot.java

public void postData(String url, String filename) {
    initConnection(url);/*from w  w w.  j  a  v a2 s  . c  o m*/

    String text = getQueryFromFile(filename);

    try {

        responseEntity = executeRequest(text);

        if (responseEntity != null) {

            this.processResponse();

        }

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

From source file:net.liuxuan.Tools.signup.SignupV2ex.java

/**
 * ?? post??????/*from  w  w  w. j a v a 2  s .  c om*/
 */
public String post(String url, String reqEncoding, String respEncoding, List<NameValuePair> param) {
    String resStr = "";
    // httppost
    HttpPost httppost = new HttpPost(url);
    // ?
    List<NameValuePair> formparams = param;
    UrlEncodedFormEntity uefEntity;
    try {
        uefEntity = new UrlEncodedFormEntity(formparams, reqEncoding);
        httppost.setEntity(uefEntity);
        HttpResponse response;
        response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            resStr = EntityUtils.toString(entity, respEncoding);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        // ,?
        // httpclient.getConnectionManager().shutdown();
    }
    return resStr;
}

From source file:com.liato.bankdroid.banking.banks.Vasttrafik.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());
    }/* w w w.ja v a 2 s.c om*/
    urlopen = login();
    try {
        response = urlopen.open("https://www.vasttrafik.se/mina-sidor-inloggad/mina-kort/");
        Matcher matcher;
        Matcher matcher_b;

        matcher = reAccounts.matcher(response);
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                EXAMPLE DATA
             * 1: Card number       1111111111
             * 2: Name              Nytt
             * 3: Balance information
             */

            if ("".equals(matcher.group(1))) {
                continue;
            }

            matcher_b = reBalance.matcher(matcher.group(3));
            if (matcher_b.find()) {
                /*
                 * Capture groups:
                 * GROUP                EXAMPLE DATA
                 * 1: Type              Kontoladdning
                 * 2: Amount            592,80 kr
                 */

                String balanceString = matcher_b.group(2).replaceAll("\\<a[^>]*>", "")
                        .replaceAll("\\<[^>]*>", "").trim();

                accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                        Helpers.parseBalance(balanceString), matcher.group(1)));
                balance = balance.add(Helpers.parseBalance(balanceString));
            }
        }

        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();
    }
}