Package org.brickred.socialauth.util

Examples of org.brickred.socialauth.util.Response


  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


  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

    LOG.info("Fetching contacts from " + CONTACTS_FEED_URL);
    if (Permission.AUTHENTICATE_ONLY.equals(this.scope)) {
      throw new SocialAuthException(
          "You have not set Permission to get contacts.");
    }
    Response serviceResponse = null;
    try {
      Map<String, String> map = new HashMap<String, String>();
      map.put("Authorization", "Bearer " + getAccessGrant().getKey());
      serviceResponse = authenticationStrategy.executeFeed(
          CONTACTS_FEED_URL, null, null, map, null);
    } catch (Exception ie) {
      throw new SocialAuthException(
          "Failed to retrieve the contacts from " + CONTACTS_FEED_URL,
          ie);
    }
    List<Contact> plist = new ArrayList<Contact>();
    Element root;

    try {
      root = XMLParseUtil.loadXmlResource(serviceResponse
          .getInputStream());
    } catch (Exception e) {
      throw new ServerDataException(
          "Failed to parse the contacts from response."
              + CONTACTS_FEED_URL, e);
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

    if (guid.indexOf("<") != -1) {
      guid = guid.substring(0, guid.indexOf("<")).trim();
      accessToken.setAttribute("xoauth_yahoo_guid", guid);
    }
    String url = String.format(PROFILE_URL, guid);
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(url);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + url, e);
    }
    if (serviceResponse.getStatus() != 200) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + 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  "
          + url, exc);
View Full Code Here

  public List<Contact> getContactList() throws Exception {
    String url = String.format(CONTACTS_URL,
        accessToken.getAttribute("xoauth_yahoo_guid"));
    LOG.info("Fetching contacts from " + url);

    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(url);
    } catch (Exception ie) {
      throw new SocialAuthException(
          "Failed to retrieve the contacts from " + url, ie);
    }

    List<Contact> plist = new ArrayList<Contact>();
    Element root;
    try {
      root = XMLParseUtil.loadXmlResource(serviceResponse
          .getInputStream());
    } catch (Exception e) {
      throw new ServerDataException(
          "Failed to parse the contacts from response." + url, e);
    }
View Full Code Here

    }
    String url = String.format(UPDATE_STATUS_URL,
        accessToken.getAttribute("xoauth_yahoo_guid"));
    LOG.info("Updating status " + msg + " on " + url);
    String msgBody = "{\"status\":{\"message\":\"" + msg + "\"}}";
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(url,
          MethodType.PUT.toString(), null, null, msgBody);
    } catch (Exception ie) {
      throw new SocialAuthException("Failed to update status on " + url,
          ie);
    }

    if (serviceResponse.getStatus() != 204) {
      throw new SocialAuthException(
          "Failed to update status. Return status code :"
              + serviceResponse.getStatus());
    }
    LOG.debug("Status Updated and return status code is : "
        + serviceResponse.getStatus());
    // return 204
    return serviceResponse;
  }
View Full Code Here

    Profile p = new Profile();
    Map<String, String> headerParam = new HashMap<String, String>();
    headerParam.put("Authorization", "OAuth " + accessGrant.getKey());
    headerParam.put("Content-Type", "application/json");
    headerParam.put("Accept", "application/json");
    Response serviceResponse;
    try {
      serviceResponse = authenticationStrategy.executeFeed(profileURL,
          MethodType.GET.toString(), null, headerParam, null);
      // HttpUtil.doHttpRequest(profileURL, "GET", null, headerParam);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + profileURL,
          e);
    }

    String result;
    try {
      result = serviceResponse
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("User Profile :" + result);
    } catch (Exception e) {
      throw new SocialAuthException("Failed to read response from  "
          + profileURL, e);
    }
    try {
      JSONObject resp = new JSONObject(result);
      if (resp.has("user_id")) {
        p.setValidatedId(resp.getString("user_id"));
      }
      if (resp.has("first_name")) {
        p.setFirstName(resp.getString("first_name"));
      }
      if (resp.has("last_name")) {
        p.setLastName(resp.getString("last_name"));
      }
      p.setDisplayName(resp.getString("display_name"));

      p.setEmail(resp.getString("email"));
      String locale = resp.getString("locale");
      if (locale != null) {
        String a[] = locale.split("_");
        p.setLanguage(a[0]);
        p.setCountry(a[1]);
      }
      if (resp.has("photos")) {
        JSONObject photosResp = resp.getJSONObject("photos");

        if (p.getProfileImageURL() == null
            || p.getProfileImageURL().length() <= 0) {
          p.setProfileImageURL(photosResp.getString("thumbnail"));
        }
      }
      serviceResponse.close();
      p.setProviderId(getProviderId());
      userProfile = p;
      return p;
    } catch (Exception e) {
      throw new SocialAuthException(
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

  }

  @Override
  public List<Contact> getContactList() throws Exception {
    LOG.info("Fetching contacts from " + CONTACTS_URL);
    Response serviceResponse;
    try {
      serviceResponse = authenticationStrategy.executeFeed(CONTACTS_URL);
    } catch (Exception e) {
      throw new SocialAuthException("Error : " + e.getMessage()
          + " - while getting contacts from " + CONTACTS_URL, e);
    }

    if (serviceResponse.getStatus() != 200) {
      throw new SocialAuthException("Error while getting contacts from "
          + CONTACTS_URL + "Status : " + serviceResponse.getStatus());
    }

    String respStr = serviceResponse
        .getResponseBodyAsString(Constants.ENCODING);
    LOG.debug("Contacts JSON string :: " + respStr);
    List<Contact> plist = new ArrayList<Contact>();

    JSONObject resp = new JSONObject(respStr);
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.