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.expensify.testframework.RestClient.java

private void executeRequest(HttpUriRequest request, String url) {
    HttpClient client = new DefaultHttpClient();

    HttpResponse httpResponse;//from  www  .  j  a  v  a  2  s  .c  o m

    try {
        httpResponse = client.execute(request);
        responseCode = httpResponse.getStatusLine().getStatusCode();
        message = httpResponse.getStatusLine().getReasonPhrase();

        HttpEntity entity = httpResponse.getEntity();

        if (entity != null) {

            InputStream instream = entity.getContent();
            response = convertStreamToString(instream);

            // Closing the input stream will trigger connection release
            instream.close();
        }

    } catch (ClientProtocolException cpExc) {
        client.getConnectionManager().shutdown();
        cpExc.printStackTrace();
    } catch (IOException ioExc) {
        client.getConnectionManager().shutdown();
        ioExc.printStackTrace();
    }
}

From source file:com.deployd.DeploydObject.java

public void saveInBackground(final ObjectCreateEventHandler onCreated) {
    AsyncTask<JSONObject, JSONObject, JSONObject> save = new AsyncTask<JSONObject, JSONObject, JSONObject>() {

        @Override//from  w w w.j av a  2  s .c  o m
        protected JSONObject doInBackground(JSONObject... params) {
            // TODO Auto-generated method stub
            try {
                JSONObject result = null;
                if (DeploydObject.this.has("id")) {
                    result = Deployd.put(params[0], "/" + resource + "/" + DeploydObject.this.getString("id"));

                    // TODO: add code for handling junctions

                } else {
                    result = Deployd.post(params[0], "/" + resource);
                }
                return result;
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(JSONObject result) {
            // TODO Auto-generated method stub
            if (result != null) {
                if (onCreated != null) {
                    try {
                        DeploydObject.this.put("id", result.getString("id"));

                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    onCreated.objectCreated(DeploydObject.this);
                }
            }
            super.onPostExecute(result);
        }
    };
    save.execute(this);
}

From source file:net.eve.finger.server.JSONAuth.java

@Override
public Boolean authUser(Connection conn, String username, String password) {
    // Build the URL
    StringBuilder url = new StringBuilder();
    url.append("https://auth.example.com/api/login?user=");
    url.append(username);// ww  w.  j  a  v  a  2s  . co  m
    url.append("&pass=");
    url.append(password);

    // Create the request      
    HttpGet authReq = new HttpGet(url.toString());

    // DB var
    PreparedStatement stmt = null;

    try {
        // Make the request to the JSON API
        String response = EntityUtils.toString(httpClient.execute(authReq).getEntity());
        JSONObject authInfo = new JSONObject(response);

        // Was the auth successful?
        if (authInfo.getString("auth").compareToIgnoreCase("ok") == 0) {
            // Yes, get their groups
            JSONArray rawGroups = authInfo.getJSONArray("groups");

            // In a format that is useful to us
            Map<String, Boolean> groups = new HashMap<String, Boolean>();

            // Convert the groups
            JSONObject temp;
            int groupCount = rawGroups.length();
            for (int i = 0; i < groupCount; i++) {
                temp = rawGroups.getJSONObject(i);
                groups.put(temp.getString("name"), temp.getBoolean("admin"));
            }

            // The group that will eventually be assigned to the user
            String groupToAssign;

            // Figure out what group to give them
            if (groups.containsKey("Alliance Director")) {
                groupToAssign = "Director";
            } else if (groups.containsKey("FC") || groups.containsKey("Cap. FC")
                    || groups.containsKey("Wing Cmdrs.")) {
                groupToAssign = "Fleet Cmdrs.";
            } else if (groups.containsKey("Scouts") || groups.containsKey("Junior FCs")) {
                groupToAssign = "Scouts";
            } else {
                groupToAssign = "No Access";
            }

            // Insert/update the user            
            stmt = conn.prepareStatement("INSERT INTO tblUsers (username, accessGroup) "
                    + "VALUES (?, (SELECT id FROM tblAccessGroups WHERE name = ?)) "
                    + "ON DUPLICATE KEY UPDATE accessGroup = VALUES(accessGroup);");
            stmt.setString(1, username);
            stmt.setString(2, groupToAssign);
            stmt.execute();

            // Success, clean up
            Utils.closeStatement(stmt);
            return true;
        } else {
            // No, go away
        }
    } catch (ClientProtocolException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    } catch (IOException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    } catch (JSONException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    } catch (SQLException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    }

    // Failure, clean up
    Utils.closeStatement(stmt);
    return false;
}

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

public CloseableHttpResponse setModelConfigs(JSONArray modelConfigConf, long analysisId) {

    Map<String, String> configurations = new HashMap<String, String>();
    configurations.put(MLConstants.ALGORITHM_NAME,
            ((JSONObject) modelConfigConf.get(0)).get(MLConstants.VALUE).toString());
    configurations.put(MLConstants.ALGORITHM_TYPE,
            ((JSONObject) modelConfigConf.get(1)).get(MLConstants.VALUE).toString());
    configurations.put(MLConstants.RESPONSE_VARIABLE,
            ((JSONObject) modelConfigConf.get(2)).get(MLConstants.VALUE).toString());
    configurations.put(MLConstants.TRAIN_DATA_FRACTION,
            ((JSONObject) modelConfigConf.get(0)).get(MLConstants.VALUE).toString());

    String payload = "[";
    for (Map.Entry<String, String> property : configurations.entrySet()) {
        payload = payload + "{\"key\":\"" + property.getKey() + "\",\"value\":\"" + property.getValue()
                + "\"},";
    }//from w  ww . jav  a2s .  c om
    payload = payload.substring(0, payload.length() - 1) + "]";

    CloseableHttpClient httpClient = HttpClients.createDefault();

    try {
        HttpPost httpPost = new HttpPost(mlHost + "/api/analyses/" + analysisId + "/configurations");
        httpPost.setHeader(MLConstants.AUTHORIZATION_HEADER, getBasicAuthKey());
        httpPost.setHeader(MLConstants.CONTENT_TYPE, MLConstants.CONTENT_TYPE_APPLICATION_JSON);
        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:org.apache.activemq.artemis.tests.integration.rest.util.RestMessageContext.java

@Override
public void close() {
    String consumerUri = contextMap.get(KEY_MSG_CONSUMER);
    if (consumerUri != null) {
        try {// w w  w .  j ava2 s . c om
            connection.delete(consumerUri);
            contextMap.remove(KEY_MSG_CONSUMER);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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

public void postDataFromText(String url, String text) throws ConnectTimeoutException {
    initConnection(url);//from  w  w w. j  a  v  a2s .  c o m
    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:edu.cwru.apo.RestClient.java

private void executeRequest(HttpUriRequest request, String url) {
    HttpResponse httpResponse;/* w ww . ja v a  2 s  .co m*/

    try {
        httpResponse = httpClient.execute(request);
        responseCode = httpResponse.getStatusLine().getStatusCode();
        message = httpResponse.getStatusLine().getReasonPhrase();

        HttpEntity entity = httpResponse.getEntity();

        if (entity != null) {

            InputStream instream = entity.getContent();
            response = convertStreamToString(instream);

            // Closing the input stream will trigger connection release
            instream.close();
        }

    } catch (ClientProtocolException e) {
        httpClient.getConnectionManager().shutdown();
        e.printStackTrace();
    } catch (IOException e) {
        httpClient.getConnectionManager().shutdown();
        e.printStackTrace();
    }
}

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

/**
 * this method delete a member from a group membership
 * it takes input as membership id.//from  w  w  w.ja va 2  s .co m
 * @param outMap membership id.
 * @return
 */
private Map<String, String> delete() {
    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 {
        TransportMachinery.delete(tst);
        outMap.put(OUTPUT, DELETE_STRING + args.get(ID));
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outMap;
}

From source file:com.liato.bankdroid.banking.banks.Eurocard.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 ww .  j a  v a 2s  . c  o m
    urlopen = login();
    Matcher matcher = reAccounts.matcher(response);
    Integer accountId = 0;
    while (matcher.find()) {
        /*
         * Capture groups:
         * GROUP                     EXAMPLE DATA           NOTES
         * 1: account number         **** **** **** 1234
         * 2: id                     a1c2d3d4e5f6s7b8c9d0   Changes when session expires
         * 3: ofakturerat amount     &nbsp;2 988,96
         * 
         */

        // Create a separate account for "Ofakturerat".
        // Set the balance for the main account to 0 and update it later
        accounts.add(new Account(Html.fromHtml(matcher.group(1)).toString().trim(), new BigDecimal(0),
                accountId.toString()));
        accounts.add(new Account(" " + "Ofakturerat", Helpers.parseBalance(matcher.group(3)),
                "o:ofak:" + accountId.toString(), Account.OTHER));
        accountIds.add(matcher.group(2).trim());
        accountId += 1;
    }

    try {
        response = urlopen.open("https://e-saldo.eurocard.se/nis/ecse/getBillingUnits.do");
        matcher = reSaldo.matcher(response);
        int i = 0;
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                     EXAMPLE DATA
             * 1: balance                &nbsp;40 988,96
             * 
             */

            // Update the main account balance
            if (accounts.size() >= i * 2 + 1) {
                accounts.get(i * 2).setBalance(Helpers.parseBalance(matcher.group(1)));
            }
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (accounts.isEmpty()) {
        throw new BankException(res.getText(R.string.no_accounts_found).toString());
    }
    super.updateComplete();
}

From source file:com.limewoodmedia.nsdroid.NationInfo.java

/**
 * Returns the bitmap for your nation's flag
 * Don't call from main thread//from w ww. ja  va2 s.  c om
 * @param activity Context
 * @return flag bitmap
 * @throws ExecutionException 
 * @throws InterruptedException 
 */
public Bitmap getFlagBitmap(final Activity activity) throws InterruptedException, ExecutionException {
    Log.d(TAG, "Flag bitmap: " + flagBitmap);
    if (flagBitmap == null) {
        String uri = getFlag();
        if (uri == null) {
            NationData data = null;
            try {
                data = API.getInstance(activity).getNationInfo(name.replace(' ', '_'), FLAG);

                flag = data.flagURL;
                try {
                    flagBitmap = LoadingHelper.loadFlag(flag, activity);
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (RateLimitReachedException e) {
                e.printStackTrace();
            } catch (UnknownNationException e) {
                e.printStackTrace();
            } catch (RuntimeException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            try {
                flagBitmap = LoadingHelper.loadFlag(uri, activity);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return flagBitmap;
}