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

/**
 * This method updates a task in salesforce.com and returns a success message with task id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /* w w  w . ja v  a  2 s .  co m*/
 */
private Map<String, String> update() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_UPDATE_PRODUCT_URL = args.get(INSTANCE_URL) + SALESFORCE_TASK_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_SUBJECT, args.get(SUBJECT));

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

/**
 * this method creates an opportunity in salesforce.com and returns that opportunity id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /*from ww w .ja  v  a 2s  .co m*/
 */
private Map<String, String> create() {
    final String SALESFORCE_CREATE_OPPORTUNITY_URL = args.get(INSTANCE_URL) + SALESFORCE_OPPORTUNITY_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_NAME, args.get(NAME));
    userAttrMap.put(S_STAGENAME, args.get(STAGE_NAME));
    userAttrMap.put(S_CLOSEDATE, DateTime.parse(args.get(CLOSE_DATE)));

    GsonBuilder gson = new GsonBuilder();
    gson.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter());
    Gson obj = gson.setPrettyPrinting().create();
    TransportTools tst = new TransportTools(SALESFORCE_CREATE_OPPORTUNITY_URL, null, header);
    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.SolutionImpl.java

/**
 * this method creates an solution in salesforce.com and returns that solution id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap //  w  w w .  j a v a 2  s  .com
 */
private Map<String, String> create() {

    final String SALESFORCE_CREATE_SOLUTION_URL = args.get(INSTANCE_URL) + SALESFORCE_SOLUTION_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_SOLUTIONNAME, args.get(SOLUTION_NAME));
    userAttrMap.put(S_STATUS, args.get(STATUS));

    TransportTools tst = new TransportTools(SALESFORCE_CREATE_SOLUTION_URL, null, header);
    Gson obj = new GsonBuilder().setPrettyPrinting().create();
    tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(userAttrMap));
    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:de.unikassel.android.sdcframework.transmission.SimpleHttpProtocol.java

/**
 * Method for an HTTP upload of file stream
 * /* www.j a  v a 2 s  .  c  o m*/
 * @param file
 *          the input file
 * 
 * @return true if successful, false otherwise
 */
private final boolean httpUpload(File file) {
    DefaultHttpClient client = new DefaultHttpClient();

    try {
        String fileName = FileUtils.fileNameFromPath(file.getName());
        String contentType = getContentType(fileName);

        URL url = getURL();
        configureForAuthentication(client, url);

        HttpPost httpPost = new HttpPost(url.toURI());

        FileEntity fileEntity = new FileEntity(file, contentType);
        fileEntity.setContentType(contentType);
        fileEntity.setChunked(true);

        httpPost.setEntity(fileEntity);
        httpPost.addHeader("filename", fileName);
        httpPost.addHeader("uuid", getUuid().toString());

        HttpResponse response = client.execute(httpPost);

        int statusCode = response.getStatusLine().getStatusCode();
        boolean success = statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT;
        Logger.getInstance().debug(this, "Server returned: " + statusCode);

        // clean up if necessary
        HttpEntity resEntity = response.getEntity();
        if (resEntity != null) {
            resEntity.consumeContent();
        }

        if (!success) {
            doHandleError("Unexpected server response: " + response.getStatusLine());
            success = false;
        }

        return success;
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        doHandleError(PROTOCOL_EXCEPTION + ": " + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        doHandleError(IO_EXCEPTION + ": " + e.getMessage());
    } catch (URISyntaxException e) {
        setURL(null);
        doHandleError(INVALID_URL);
    } finally {
        client.getConnectionManager().shutdown();
    }
    return false;
}

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

/**
 * This method updates a contract in salesforce.com and returns a success message with updated contract id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /*from w  w  w .j a  v a 2  s  .c o m*/
 */
private Map<String, String> update() {
    final String SALESFORCE_UPDATE_CONTACT_URL = args.get(INSTANCE_URL) + SALESFORCE_CONTRACT_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_BILLINGCITY, args.get(BILLING_CITY));

    TransportTools tst = new TransportTools(SALESFORCE_UPDATE_CONTACT_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 lists all event in salesforce.com and returns a list of all event details.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap //from  ww  w.  j a va 2  s.  com
 */
private Map<String, String> list() {
    Map<String, String> outMap = new HashMap<>();
    final String SALESFORCE_LIST_EVENT_URL = args.get(INSTANCE_URL)
            + "/services/data/v25.0/query/?q=SELECT+Id,Subject+FROM+Event";
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));

    TransportTools tst = new TransportTools(SALESFORCE_LIST_EVENT_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.mycompany.FacebookManager.java

@Override
public String getLongAccessToken(String accessToken) {
    String GET_PATH = defaultFacebookPath + "&client_id=" + APP_ID + "&client_secret=" + APP_SECRET
            + "&fb_exchange_token=" + accessToken;

    HttpClient client = HttpClientBuilder.create().build();
    HttpGet get = new HttpGet(GET_PATH);

    get.setHeader("Accept", "application/json");

    HttpEntity entity;//from w  w  w  .  j a v  a2 s. c o  m
    try {
        HttpResponse response = client.execute(get);

        if (response.getStatusLine().getStatusCode() != 200) {
            System.out.println("GET> Unexpected status code: " + response.getStatusLine().getStatusCode());
        }

        entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        String[] at = data.split("=");
        String newTok = at[1];
        at = newTok.split("&");

        return at[0]; //at[1] == Long accessToken get by facebook 

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

}

From source file:com.sonetel.plugins.sonetelcallthru.CallThru.java

void SendMsgToNetWork(String callthrunum, Context context, PendingIntent callthruIntent) {
    try {//ww  w.ja va2  s.  co  m
        SipAccount = AccessNumbers.sendPostReq(SipAccount, callthrunum, null, context, callthruIntent);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReader.java

/**
 * Returns the Profile of the logged user
 * //from w  ww . j  a  v  a  2s  .  c  o  m
 * @param sid
 * @return Profile
 */
public static Profile getOwnProfile(String sid) {
    listToParse.clear();
    listToParse.add(new ParamObject("sid", sid, false));

    JsonObject object = null;

    try {
        object = JSonRequestProvider.doRequest(listToParse, "own_profile.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    boolean suc = false;
    int id = 0;
    String username = null;
    String email = null;
    String firstname = null;
    String lastname = null;
    String tel = null;
    String description = null;
    boolean email_public = false;
    boolean firstname_public = false;
    boolean lastname_public = false;
    boolean tel_public = false;

    double rating_avg = 0;
    int rating_num = 0;
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
        id = object.get("id").getAsInt();
        username = object.get("username").getAsString();
        Log.d(TAG, "USERNAME:" + username);
        email = object.get("email").getAsString();
        firstname = object.get("firstname").getAsString();
        lastname = object.get("lastname").getAsString();
        tel = object.get("tel").getAsString();
        description = object.get("description").getAsString();
        object.get("regdate").getAsString();
        rating_avg = object.get("rating_avg").getAsFloat();
        rating_num = object.get("rating_num").getAsInt();
        email_public = object.get("email_public").getAsBoolean();
        firstname_public = object.get("firstname_public").getAsBoolean();
        lastname_public = object.get("lastname_public").getAsBoolean();
        tel_public = object.get("tel_public").getAsBoolean();
    }

    // String userid = object.get("id").getAsString();
    // TODO
    // String regdate = object.get("regdate").getAsString();
    Profile profile;

    Date date = new Date();
    if (suc) {
        profile = new Profile(id, username, email, firstname, lastname, tel, description, date, email_public,
                firstname_public, lastname_public, tel_public, rating_avg, rating_num);
        return profile;
    }
    return null;
}

From source file:org.megam.deccanplato.provider.zoho.crm.handler.UserImpl.java

/**
 * This method lists all users in zoho.com and returns a list of users details.
 * This method takes input as a MAP(contains json dada) and returns a MAP.
 * @param outMap // w  w w.  j a v a  2 s . c  o m
 */
private Map<String, String> list(Map<String, String> outMap) {

    List<NameValuePair> userAttrList = new ArrayList<NameValuePair>();
    userAttrList.add(new BasicNameValuePair(OAUTH_TOKEN, args.get(AUTHTOKEN)));
    userAttrList.add(new BasicNameValuePair(ZOHO_SCOPE, SCOPE));
    userAttrList.add(new BasicNameValuePair(ZOHO_TYPE, TYPE));

    TransportTools tst = new TransportTools(ZOHO_CRM_USER_JSON_URL + GET_RECORDS, userAttrList, null, true,
            "UTF-8");
    String responseBody = null;

    TransportResponse response = null;

    try {
        response = TransportMachinery.get(tst);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    responseBody = response.entityToString();

    outMap.put(OUTPUT, responseBody);
    return outMap;

}