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:org.megam.deccanplato.provider.salesforce.crm.handler.UserImpl.java

/**
 * This method updates a user in salesforce.com and returns a success message with updated user id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /*from   ww w .  j av a 2 s .c o m*/
 * @param outMap 
 */
public Map<String, String> update() {

    final String SALESFORCE_UPDATE_USER_URL = args.get(INSTANCE_URL) + SALESFORCE_USER_URL + args.get(ID);
    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));

    Map<String, Object> userAttrMap = new HashMap<String, Object>();
    userAttrMap.put(S_USERNAME, args.get(USERNAME));
    userAttrMap.put(S_FIRSTNAME, args.get(FIRSTNAME));
    userAttrMap.put(S_EMAIL, args.get(EMAIL));
    userAttrMap.put(S_ALIAS, args.get(ALIAS));
    userAttrMap.put(S_PROFILEID, args.get(PROFILEID));
    userAttrMap.put(S_LASTNAME, args.get(LASTNAME));
    userAttrMap.put(S_TIMEZONESIDKEY, args.get(TIMEZONESIDKEY));
    userAttrMap.put(S_LOCALESIDKEY, args.get(LOCALESIDKEY));
    userAttrMap.put(S_EMAILENCODINGKEY, args.get(EMAILENCODINGKEY));
    userAttrMap.put(S_LANGUAGELOCALEYKEY, args.get(LANGUAGELOCALEKEY));

    TransportTools tst = new TransportTools(SALESFORCE_UPDATE_USER_URL, null, header);
    Gson obj = new GsonBuilder().setPrettyPrinting().create();
    tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(userAttrMap));
    try {
        TransportMachinery.patch(tst);
        outMap.put(OUTPUT, UPDATE_STRING + args.get(ID));

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

}

From source file:com.deployd.DeploydObject.java

public void deleteInBackground() {
    AsyncTask<JSONObject, JSONObject, JSONObject> del = new AsyncTask<JSONObject, JSONObject, JSONObject>() {

        @Override/*from   w  w w  . j  a v a2  s. c o  m*/
        protected JSONObject doInBackground(JSONObject... params) {
            // TODO Auto-generated method stub
            try {
                JSONObject result = Deployd.delete("/" + resource + "/" + DeploydObject.this.getObjectId());
                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

            super.onPostExecute(result);
        }
    };
    //   del.execute(null);
}

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

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);
    // Only update transactions for the main account
    if (!account.getId().startsWith("b_"))
        return;//w w w.  j  a  v  a  2 s .c  om

    try {
        response = urlopen.open("https://secure.resurs.se/internetbank/kontoutdrag.jsp");
        Matcher matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                    EXAMPLE DATA
             * 1: Date                  2010-04-17
             * 2: Transaction           ONOFF L+NNA
             * 3: Currency              always null?
             * 4: Amount                -95,00 kr 
             * 
             */
            transactions.add(new Transaction(matcher.group(1),
                    Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(4))));
        }
        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:cn.com.zzwfang.http.HttpClient.java

@Override
public HttpResponse request(HttpUriRequest httpUriRequest) {
    if (httpUriRequest == null || httpClient == null) {
        return null;
    }//  ww  w .  j  ava2s .  c  om
    HttpResponse httpResponse = null;
    try {
        httpResponse = httpClient.execute(httpUriRequest);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return httpResponse;
}

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

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

    Matcher matcher;// ww w  . j av a2  s  . c o m
    try {
        response = urlopen.open(String.format("https://mobil-banken.se/%s/accountmovement.html?account_no=%s",
                targetId, account.getId()));
        matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        while (matcher.find()) {
            /*
             * Capture groups:
             * GROUP                    EXAMPLE DATA
             * 1: Transaction           Kortkp QPARKSTOCKHOLM,  STOCKHOLM
             * 2: Amount                -40,00
             * 3: Date                  2010.12.23 
             * 
             */
            transactions.add(new Transaction(matcher.group(3).trim().replace(".", "-"),
                    Html.fromHtml(matcher.group(1)).toString().trim(), Helpers.parseBalance(matcher.group(2))));
        }
        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:eu.eexcess.partnerdata.reference.enrichment.DbpediaSpotlight.java

public boolean isEntityDbpediaSpotlight(String word, PartnerdataLogger logger) {
    long startTime = logger.getActLogEntry().getTimeNow();
    try {//from   w w  w.  j ava  2s . co  m
        String URL = DBPEDIA_URL;
        URL += word.replaceAll(" ", "%20");

        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout)
                .setSocketTimeout(timeout).build();
        HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();

        //      HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(URL);
        request.setHeader("Accept", "text/xml");
        HttpResponse response;

        try {
            response = client.execute(request);
            if (response.getStatusLine().getStatusCode() == 200) {
                InputStream is = response.getEntity().getContent();
                //               Set<DbpediaSpotlightResult> entities=XmlParser.getEntitiesDbpediaSpotlightCandidatesXML(this.partnerConfig,is);
                Set<DbpediaSpotlightResult> entities = XmlParser
                        .getEntitiesDbpediaSpotlightAnnotateXML(this.partnerConfig, is, logger);
                is.close();
                logger.getActLogEntry().addEnrichmentDbpediaSpotlightResults(entities.size());
                logger.getActLogEntry().addEnrichmentDbpediaSpotlightServiceCalls(1);
                logger.getActLogEntry().addEnrichmentDbpediaSpotlightServiceCallDuration(startTime);

                return entities.size() > 0;
            }

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

    }

    return false;

}

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

@Override
public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException {
    super.updateTransactions(account, urlopen);
    String response = null;//from  www  .  ja va 2  s  .com
    Matcher matcher;
    try {
        response = urlopen.open("https://mobil2.icabanken.se/account/account.aspx?id=" + account.getId());
        matcher = reTransactions.matcher(response);
        ArrayList<Transaction> transactions = new ArrayList<Transaction>();
        while (matcher.find()) {
            transactions.add(new Transaction(matcher.group(2).trim().substring(8),
                    Html.fromHtml(matcher.group(1)).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();
    } finally {
        super.updateComplete();
    }
}

From source file:cic.myapps.signin.v1.HttpClient.java

/**
 * Get json object from remote db//from w  w w  . ja v a 2  s .  c  o m
 * 
 */
@Override
protected JSONObject doInBackground(String... urls) {

    try {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httpPostRequest = new HttpPost(urls[0]);

        // Start from here
        // Set HTTP parameters
        httpPostRequest.setHeader("Accept", "application/json");
        httpPostRequest.setHeader("Content-type", "application/json");

        long t = System.currentTimeMillis();
        HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest);
        Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis() - t) + "ms]");

        // Get hold of the response entity (-> the data):
        HttpEntity entity = response.getEntity();

        if (entity != null) {
            // Read the content stream
            InputStream instream = entity.getContent();

            // convert content stream to a String
            String resultString = convertStreamToString(instream);

            instream.close();
            //resultString = resultString.substring(1,resultString.length()-1); // remove wrapping "[" and "]"            

            // Transform the String into a JSONObject
            JSONObject jsonObjRecv = new JSONObject(resultString);

            // Raw DEBUG output of our received JSON object:
            Log.i(TAG, "<JSONObject>\n" + jsonObjRecv.toString() + "\n</JSONObject>");

            return jsonObjRecv;
        }

    } 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();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.megam.deccanplato.provider.sugarcrm.handler.BusinessActivityImpl.java

/**
 * This method deals with create business activity for users,accounts and leads,
 * and it takes outMap MAP(contains json data) value as input and returns a MAP 
 * this method uses MutableSugar class to populate sugarCRM json input.
 * @param outMap./*from   w  w  w.jav  a2  s . co  m*/
 * 
 */
private Map<String, String> create(Map<String, String> outMap) {

    MutableSugar scu = new MutableSugar(name(), args);
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(scu);

    List<NameValuePair> userAttr = new ArrayList<NameValuePair>();
    userAttr.add(new BasicNameValuePair(METHOD, SET_METHOD));
    userAttr.add(new BasicNameValuePair(INPUT_TYPE, TYPE));
    userAttr.add(new BasicNameValuePair(RESPONSE_TYPE, TYPE));
    userAttr.add(new BasicNameValuePair(DATA, json));

    TransportTools tst = new TransportTools(SUGAR_URL, userAttr);
    String responseBody = null;

    TransportResponse response = null;
    try {
        response = TransportMachinery.post(tst);
        responseBody = response.entityToString();

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    outMap.put(OUTPUT, responseBody);
    return outMap;
}

From source file:org.service.TaskGetEdifice.java

private Boolean getRestFul() {

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(HTTP_RESTFUL);

    Boolean strResultado = true;/*w  w  w .  j  av  a 2s  . com*/
    try {
        //ejecuta
        HttpResponse response = httpclient.execute(httpGet);
        HttpEntity entity = response.getEntity();
        BufferedHttpEntity buffer = new BufferedHttpEntity(entity);
        InputStream iStream = buffer.getContent();

        String aux = "";

        BufferedReader r = new BufferedReader(new InputStreamReader(iStream));
        StringBuilder total = new StringBuilder();
        String line;
        while ((line = r.readLine()) != null) {
            aux += line;
        }
        JSONObject jsonObject = new JSONObject(aux);
        JSONArray array = jsonObject.getJSONArray("edifice");
        edifices = new Edifice[array.length()];
        // Recorremos el array con los elementos cities
        for (int i = 0; i < array.length(); i++) {
            JSONObject row = array.getJSONObject(i);
            String idEdifice = row.getString("idEdifice");
            String NameEdifice;
            NameEdifice = row.getString("NameEdifice");
            edifices[i] = new Edifice(idEdifice, NameEdifice);
        }
        return strResultado;

    } catch (ClientProtocolException e) {
        strResultado = false;
        e.printStackTrace();
    } catch (IOException e) {
        strResultado = false;
        e.printStackTrace();
    } catch (JSONException e) {
        strResultado = false;
        e.printStackTrace();
    }
    return strResultado;
}