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

/**
 * this method creates an case in salesforce.com and returns that case id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap //from   w  ww.  ja v  a 2  s .co m
 */
private Map<String, String> create() {
    final String SALESFORCE_CREATE_CASE_URL = args.get(INSTANCE_URL) + SALESFORCE_CASE_URL;
    Map<String, String> outMap = new HashMap<>();
    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_SUBJECT, args.get(SUBJECT));
    userAttrMap.put(S_CONTACTID, args.get(CONTACT_ID));
    userAttrMap.put(S_ACCOUNTID, args.get(ACCOUNT_ID));

    TransportTools tst = new TransportTools(SALESFORCE_CREATE_CASE_URL, null, header);
    Gson obj = new GsonBuilder().setPrettyPrinting().create();
    tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(userAttrMap));

    try {
        String responseBody = TransportMachinery.post(tst).entityToString();
        outMap.put(OUTPUT, responseBody);

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

From source file:org.megam.deccanplato.provider.salesforce.crm.handler.ContractImpl.java

/**
 * this method lists all contract in salesforce.com and returns a list of all contract details.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /*w  ww .java2  s. c  o m*/
 */
private Map<String, String> list() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_LIST_CONTACT_URL = args.get(INSTANCE_URL)
            + "/services/data/v25.0/query/?q=SELECT+Id,Description,BillingCity+FROM+Contract";
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

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

From source file:com.nlworks.wowapi.util.ConnectionManager.java

public String sendRequest(String url, long lastModified, String publicKey, String privateKey) {

    String ret = null;/*from w  w  w .j a  va  2s .c  om*/
    System.out.println("URL to send: " + url);

    if (publicKey != null && publicKey.length() > 0 && privateKey != null && privateKey.length() > 0) {
        // generateSignature(St)
        // TODO private key signing of requests

        //         String stringToSign = urlConnection.getRequestMethod() + "\n" + dateStr + "\n" + UrlPath + "\n";
        //         String sig = generateHmacSHA1Signature(stringToSign, privateKey);
        //         try {
        //            urlConnection.setRequestProperty("Authorization", "BNET" + " " + publicKey + ":" + sig);
        //            urlConnection.setRequestProperty("Date", dateStr);
        //            if (lastModified != 0)
        //               urlConnection.setIfModifiedSince(lastModified);
        //         } catch (IllegalStateException e) {
        //            e.printStackTrace();
        //         }
    }

    HttpGet httpGet = new HttpGet(url);
    if (lastModified > 0) {
        httpGet.addHeader(new BasicHeader("If-Modified-Since", Long.toString(lastModified)));
    }

    try {
        HttpResponse response = httpClient.execute(httpGet);
        System.out.println("Resp Status: " + response.getStatusLine());
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer sb = new StringBuffer(1024);
        while (reader.ready()) {
            sb.append(reader.readLine()).append('\n');
        }
        ret = sb.toString();
        System.out.println("Resp Data: " + ret);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return ret;
}

From source file:com.webnetmobile.tools.GoogleMapRouteHelper.java

public List<LatLng> getDirections() {
    if ((mPickup != null) || (mDropoff != null)) {

        HttpClient httpclient = new DefaultHttpClient();

        StringBuilder urlBuilder = new StringBuilder();

        urlBuilder.append("http://maps.googleapis.com/maps/api/directions/json");

        urlBuilder.append("?origin=");
        urlBuilder.append(Double.toString((double) mPickup.latitude));
        urlBuilder.append(",");
        urlBuilder.append(Double.toString((double) mPickup.longitude));

        urlBuilder.append("&destination=");
        urlBuilder.append(Double.toString((double) mDropoff.latitude));
        urlBuilder.append(",");
        urlBuilder.append(Double.toString((double) mDropoff.longitude));
        urlBuilder.append("&sensor=false&units=metric&mode=driving");

        HttpPost httppost = new HttpPost(urlBuilder.toString());
        HttpResponse response;//ww w  . j  ava2s. co  m
        try {
            response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            InputStream is = null;

            is = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            sb.append(reader.readLine() + "\n");
            String line = "0";
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            reader.close();

            String result = sb.toString();

            JSONObject jsonObject = new JSONObject(result);

            JSONArray routeArray = jsonObject.getJSONArray("routes");
            if ((routeArray != null) && (routeArray.length() > 0)) {
                JSONObject routes = routeArray.getJSONObject(0);
                JSONObject overviewPolylines = routes.getJSONObject("overview_polyline");
                String encodedString = overviewPolylines.getString("points");
                mRoutePoints = decodePoly(encodedString);
            } else {
                mRoutePoints = null;
            }

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

        return mRoutePoints;
    } else {
        throw new NullPointerException("Pickup or Dropoff cannot be null.");
    }
}

From source file:org.megam.deccanplato.provider.salesforce.crm.handler.CampaignImpl.java

/**
 * this method deletes an campaign in salesforce.com and returns a success message with deleted campaign id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap // w  w w  .ja  va2  s . c o  m
 */
private Map<String, String> delete() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_DELETE_CAMPAIGN_URL = args.get(INSTANCE_URL) + SALESFORCE_CAMPAIGN_URL
            + 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(SALESFORCE_DELETE_CAMPAIGN_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:org.megam.deccanplato.provider.salesforce.crm.handler.OpportunitiesImpl.java

/**
 * This method updates a opportunity in salesforce.com and returns a success message with event opportunity id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /*w  ww  . ja va2 s  .  c  om*/
 */
private Map<String, String> update() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_UPDATE_OPPORTUNITY_URL = args.get(INSTANCE_URL) + SALESFORCE_OPPORTUNITY_URL
            + args.get(ID);
    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_STAGENAME, args.get(STAGE_NAME));

    TransportTools tst = new TransportTools(SALESFORCE_UPDATE_OPPORTUNITY_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:org.megam.deccanplato.provider.salesforce.crm.handler.ProductImpl.java

/**
 * this method lists all product in salesforce.com and returns a list of all product details.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap // w  ww  .  j a v  a  2s. co  m
 */
private Map<String, String> list() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_LIST_PRODUCT_URL = args.get(INSTANCE_URL)
            + "/services/data/v25.0/query/?q=SELECT+Id,Name+FROM+Product2";
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(SALESFORCE_LIST_PRODUCT_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.crm.handler.ProductImpl.java

/**
 * This method updates a product in salesforce.com and returns a success message with product id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /*from   www  .j  a  v  a 2 s  .  c om*/
 */
private Map<String, String> update() {
    final String SALESFORCE_UPDATE_PRODUCT_URL = args.get(INSTANCE_URL) + SALESFORCE_PRODUCT_URL + args.get(ID);
    Map<String, String> outMap = new HashMap<>();
    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_NAME, args.get(NAME));

    TransportTools tst = new TransportTools(SALESFORCE_UPDATE_PRODUCT_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:org.megam.deccanplato.provider.salesforce.crm.handler.EventImpl.java

/**
 * this method deletes an event in salesforce.com and returns a success message with deleted event id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap // w  w  w  .  j a  va 2 s  .  c  o  m
 */
private Map<String, String> delete() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_DELETE_EVENT_URL = args.get(INSTANCE_URL) + SALESFORCE_EVENT_URL + 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(SALESFORCE_DELETE_EVENT_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:org.megam.deccanplato.provider.salesforce.crm.handler.SolutionImpl.java

/**
 * This method updates a solution in salesforce.com and returns a success message with solution id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap //from w  w  w  .j a  va 2 s. co  m
 */
private Map<String, String> update() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_UPDATE_SOLUTION_URL = args.get(INSTANCE_URL) + SALESFORCE_SOLUTION_URL
            + args.get(ID);

    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_SOLUTIONNAME, args.get(SOLUTION_NAME));

    TransportTools tst = new TransportTools(SALESFORCE_UPDATE_SOLUTION_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;
}