Package org.brickred.socialauth.util

Examples of org.brickred.socialauth.util.Response


  }

  private Profile getProfile() throws Exception {
    LOG.debug("Obtaining user profile");
    Profile profile = new Profile();
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(PROFILE_URL);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + PROFILE_URL,
          e);
    }
    if (serviceResponse.getStatus() != 200) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + PROFILE_URL
              + ". Staus :" + serviceResponse.getStatus());
    }

    Element root;
    try {
      root = XMLParseUtil.loadXmlResource(serviceResponse
          .getInputStream());
    } catch (Exception e) {
      throw new ServerDataException(
          "Failed to parse the profile from response." + PROFILE_URL,
          e);
View Full Code Here


  private Profile getProfile() throws Exception {
    String presp;

    try {
      Response response = authenticationStrategy.executeFeed(PROFILE_URL);
      presp = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting profile from "
          + PROFILE_URL, e);
    }
    try {
View Full Code Here

  public Response api(final String url, final String methodType,
      final Map<String, String> params,
      final Map<String, String> headerParams, final String body)
      throws Exception {
    LOG.info("Calling api function for url  :  " + url);
    Response response = null;
    try {
      response = authenticationStrategy.executeFeed(url, methodType,
          params, headerParams, body);
    } catch (Exception e) {
      throw new SocialAuthException(
View Full Code Here

      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    LOG.info("Fetching contacts from " + CONTACTS_URL);

    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(CONTACTS_URL);
    } catch (Exception ie) {
      throw new SocialAuthException(
          "Failed to retrieve the contacts from " + CONTACTS_URL, ie);
    }
    String result;
    try {
      result = serviceResponse
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("Contacts JSON :" + result);
    } catch (Exception exc) {
      throw new SocialAuthException("Failed to read contacts from  "
          + CONTACTS_URL, exc);
View Full Code Here

    if (msg == null || msg.trim().length() == 0) {
      throw new ServerDataException("Status cannot be blank");
    }
    LOG.info("Updating status " + msg + " on " + UPDATE_STATUS_URL);
    String msgBody = "{\"status\":\"" + msg + "\"}";
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(
          UPDATE_STATUS_URL, MethodType.PUT.toString(), null, null,
          msgBody);
    } catch (Exception ie) {
      throw new SocialAuthException("Failed to update status on "
          + UPDATE_STATUS_URL, ie);
    }
    LOG.info("Update Status Response :" + serviceResponse.getStatus());
    return serviceResponse;
  }
View Full Code Here

  private Profile getProfile() throws Exception {
    LOG.debug("Obtaining user profile");
    Profile profile = new Profile();

    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(PROFILE_URL);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + PROFILE_URL,
          e);
    }
    if (serviceResponse.getStatus() != 200) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + PROFILE_URL
              + ". Staus :" + serviceResponse.getStatus());
    }

    String result;
    try {
      result = serviceResponse
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("User Profile :" + result);
    } catch (Exception exc) {
      throw new SocialAuthException("Failed to read response from  "
          + PROFILE_URL, exc);
View Full Code Here

  @Override
  protected Profile authLogin() throws Exception {
    String presp;
    System.out.println(accessGrant.getAttributes());
    try {
      Response response = authenticationStrategy.executeFeed(PROFILE_URL);
      presp = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting profile from "
          + PROFILE_URL, e);
    }
    try {
View Full Code Here

  @SuppressWarnings("unchecked")
  protected Profile authLogin() throws Exception {
    String presp;

    try {
      Response response = authenticationStrategy.executeFeed(PROFILE_URL);
      presp = response.getResponseBodyAsString(Constants.ENCODING);
      //System.out.println(response.getStatus());
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting profile from "
          + PROFILE_URL, e);
    }
View Full Code Here

  @SuppressWarnings("unchecked")
  protected Profile authLogin() throws Exception {
    String presp;

    try {
      Response response = authenticationStrategy.executeFeed(PROFILE_URL);
      presp = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting profile from "
          + PROFILE_URL, e);
    }
    try {
View Full Code Here

    LOG.info("Fetching contacts from " + CONTACTS_URL);
    return getContacts(CONTACTS_URL);
  }

  private List<Contact> getContacts(final String url) throws Exception {
    Response serviceResponse;
    try {
      serviceResponse = authenticationStrategy.executeFeed(url);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting contacts from "
          + url, e);
    }
    if (serviceResponse.getStatus() != 200) {
      throw new SocialAuthException("Error while getting contacts from "
          + url + "Status : " + serviceResponse.getStatus());
    }
    String result;
    try {
      result = serviceResponse
          .getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
      throw new ServerDataException("Failed to get response from " + url,
          e);
    }
    LOG.debug("User Contacts list in JSON " + result);
    JSONObject resp = new JSONObject(result);
    List<Contact> plist = new ArrayList<Contact>();
    if (resp.has("data")) {
      JSONArray addArr = resp.getJSONArray("data");
      LOG.debug("Contacts Found : " + addArr.length());
      for (int i = 0; i < addArr.length(); i++) {
        JSONObject obj = addArr.getJSONObject(i);
        Contact p = new Contact();
        if (obj.has("email_hashes")) {
          JSONArray emailArr = obj.getJSONArray("email_hashes");
          if (emailArr.length() > 0) {
            p.setEmailHash(emailArr.getString(0));
          }
        }
        if (obj.has("name")) {
          p.setDisplayName(obj.getString("name"));
        }
        if (obj.has("first_name")) {
          p.setFirstName(obj.getString("first_name"));
        }
        if (obj.has("last_name")) {
          p.setLastName(obj.getString("last_name"));
        }
        if (obj.has("id")) {
          p.setId(obj.getString("id"));
        }
        plist.add(p);
      }
    }
    serviceResponse.close();
    return plist;
  }
View Full Code Here

TOP

Related Classes of org.brickred.socialauth.util.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.