Package org.brickred.socialauth.util

Examples of org.brickred.socialauth.util.Response


    Map<String, String> headerParam = new HashMap<String, String>();
    headerParam.put("Authorization", "Bearer " + accessToken);
    LOG.info("Fetching contacts from " + contactURL);
    String respStr;
    try {
      Response response = HttpUtil.doHttpRequest(contactURL,
          MethodType.GET.toString(), null, headerParam);
      respStr = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting contacts from "
          + contactURL, e);
    }
    try {
View Full Code Here


    Map<String, String> headerParam = new HashMap<String, String>();
    headerParam.put("Authorization", "Bearer " + accessToken);
    headerParam.put("Content-Type", "application/json");
    headerParam.put("Accept", "application/json");
    String msgBody = "{\"body\" : \"" + msg + "\"}";
    Response serviceResponse;
    try {
      serviceResponse = HttpUtil.doHttpRequest(UPDATE_STATUS_URL,
          MethodType.POST.toString(), msgBody, headerParam);

      if (serviceResponse.getStatus() != 201) {
        throw new SocialAuthException(
            "Status not updated. Return Status code :"
                + serviceResponse.getStatus());
      }
    } catch (Exception e) {
      throw new SocialAuthException(e);
    }
    return serviceResponse;
View Full Code Here

    if (!isVerify || accessToken == null) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token and then update status");
    }
    Profile p = new Profile();
    Response serviceResponse;
    if (profileId == null) {
      profileId = (String) accessGrant.getAttribute("profileId");
    }
    String profileURL = String.format(PROFILE_URL, profileId, accessToken);
    Map<String, String> headerParam = new HashMap<String, String>();
    headerParam.put("Authorization", "Bearer " + accessToken);
    try {

      serviceResponse = 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);
View Full Code Here

    headerParam.put("Accept", "application/json");
    if (headerParams != null) {
      headerParam.putAll(headerParams);
    }
    headerParam.put("Authorization", "Bearer " + accessToken);
    Response serviceResponse;
    LOG.debug("Calling URL : " + url);
    LOG.debug("Header Params : " + headerParam.toString());
    try {
      serviceResponse = HttpUtil.doHttpRequest(url, methodType, body,
          headerParam);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Error while making request to URL : " + url, e);
    }
    if (serviceResponse.getStatus() != 200
        && serviceResponse.getStatus() != 201) {
      LOG.debug("Return statuc for URL " + url + " is "
          + serviceResponse.getStatus());
      throw new SocialAuthException("Error while making request to URL :"
          + url + "Status : " + serviceResponse.getStatus());
    }
    return serviceResponse;
  }
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

    Map<String, String> headerParam = new HashMap<String, String>();
    headerParam.put("Authorization", "Bearer " + accessGrant.getKey());
    headerParam.put("Content-Type", "application/json");
    String body = "{message:\"" + msg + "\"}";
    Response serviceResponse;
    serviceResponse = authenticationStrategy.executeFeed(UPDATE_STATUS_URL,
        MethodType.POST.toString(), null, headerParam, body);

    int code = serviceResponse.getStatus();
    LOG.debug("Status updated and return status code is :" + code);
    // return 201
    return serviceResponse;
  }
View Full Code Here

    authenticationStrategy.logout();
  }

  private Profile getProfile() throws Exception {
    Profile p = new Profile();
    Response serviceResponse;
    try {
      serviceResponse = authenticationStrategy.executeFeed(PROFILE_URL);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from  " + PROFILE_URL,
          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  "
          + PROFILE_URL, e);
    }
    try {
      JSONObject resp = new JSONObject(result);
      if (resp.has("id")) {
        p.setValidatedId(resp.getString("id"));
      }
      if (resp.has("name")) {
        p.setFullName(resp.getString("name"));
      }
      if (resp.has("first_name")) {
        p.setFirstName(resp.getString("first_name"));
      }
      if (resp.has("last_name")) {
        p.setLastName(resp.getString("last_name"));
      }
      if (resp.has("Location")) {
        p.setLocation(resp.getString("Location"));
      }
      if (resp.has("gender")) {
        p.setGender(resp.getString("gender"));
      }
      if (resp.has("ThumbnailImageLink")) {
        p.setProfileImageURL(resp.getString("ThumbnailImageLink"));
      }

      if (resp.has("birth_day") && !resp.isNull("birth_day")) {
        BirthDate bd = new BirthDate();
        bd.setDay(resp.getInt("birth_day"));
        if (resp.has("birth_month") && !resp.isNull("birth_month")) {
          bd.setMonth(resp.getInt("birth_month"));
        }
        if (resp.has("birth_year") && !resp.isNull("birth_year")) {
          bd.setYear(resp.getInt("birth_year"));
        }
        p.setDob(bd);
      }

      if (resp.has("emails")) {
        JSONObject eobj = resp.getJSONObject("emails");
        String email = null;
        if (eobj.has("preferred")) {
          email = eobj.getString("preferred");
        }
        if ((email == null || email.isEmpty()) && eobj.has("account")) {
          email = eobj.getString("account");
        }
        if ((email == null || email.isEmpty()) && eobj.has("personal")) {
          email = eobj.getString("personal");
        }
        p.setEmail(email);

      }
      if (resp.has("locale")) {
        p.setLanguage(resp.getString("locale"));
      }
      serviceResponse.close();
      p.setProviderId(getProviderId());
      String picUrl = String.format(PROFILE_PICTURE_URL,
          accessGrant.getKey());
      p.setProfileImageURL(picUrl);
      userProfile = p;
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.debug("Calling URL : " + url);
    Response serviceResponse;
    try {
      serviceResponse = authenticationStrategy.executeFeed(url,
          methodType, params, headerParams, body);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Error while making request to URL : " + url, e);
    }
    if (serviceResponse.getStatus() != 200) {
      LOG.debug("Return statuc for URL " + url + " is "
          + serviceResponse.getStatus());
      throw new SocialAuthException("Error while making request to URL :"
          + url + "Status : " + serviceResponse.getStatus());
    }
    return serviceResponse;
  }
View Full Code Here

   */

  @Override
  public List<Contact> getContactList() throws Exception {
    LOG.info("Fetching contacts from " + CONNECTION_URL);
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy
          .executeFeed(CONNECTION_URL);
    } catch (Exception ie) {
      throw new SocialAuthException(
          "Failed to retrieve the contacts from " + CONNECTION_URL,
          ie);
    }
    Element root;
    try {
      root = XMLParseUtil.loadXmlResource(serviceResponse
          .getInputStream());
    } catch (Exception e) {
      throw new ServerDataException(
          "Failed to parse the contacts from response."
              + CONNECTION_URL, e);
View Full Code Here

    message = message.replace("&", "&amp;");
    LOG.info("Updating status " + message + " on " + UPDATE_STATUS_URL);
    Map<String, String> headerParams = new HashMap<String, String>();
    headerParams.put("Content-Type", "text/xml;charset=UTF-8");
    String msgBody = String.format(STATUS_BODY, message);
    Response serviceResponse = null;
    try {
      serviceResponse = authenticationStrategy.executeFeed(
          UPDATE_STATUS_URL, MethodType.POST.toString(), null,
          headerParams, msgBody);
    } catch (Exception ie) {
      throw new SocialAuthException("Failed to update status on "
          + UPDATE_STATUS_URL, ie);
    }
    LOG.debug("Status Updated and return status code is : "
        + serviceResponse.getStatus());
    // return 201
    return serviceResponse;
  }
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.