Package org.brickred.socialauth.util

Examples of org.brickred.socialauth.util.Response


    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
    serviceResponse.close();
  }
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"));
      }
      //Fix issue 145
      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

    map.put("sig", signature);
    map.remove("access_token");

    String presp;
    try {
      Response response = authenticationStrategy.executeFeed(url, "POST", map, null, null);
      presp = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting profile from "
          + PROFILE_URL, e);
    }
    Map<String, Object> data = (Map<String, Object>) Json.fromJson(presp);
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

  @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

  @SuppressWarnings("unchecked")
  protected Profile authLogin() throws Exception {
    String presp;
    try {
      Response response = authenticationStrategy.executeFeed(PROFILE_URL);
      presp = response.getResponseBodyAsString(Constants.ENCODING); // callback( {"client_id":"YOUR_APPID","openid":"YOUR_OPENID"} );
      if (presp != null) {
        presp = presp.trim().intern();
        if (presp.startsWith("callback(") && presp.endsWith(");")) {
          presp = presp.substring(presp.indexOf("{"), presp.indexOf("}") + 1);
          Map<String, String> map = (Map<String, String>) Json.fromJson(presp);
          if (map.get("openid") != null) {
            Profile p = new Profile();
            p.setValidatedId(map.get("openid")); // QQ定义的
            p.setProviderId(getProviderId());
            userProfile = p;
           
            try {
              Map<String, String> params = new HashMap<String, String>();
              params.put("format", "json");
              params.put("openid", map.get("openid"));
              params.put("oauth_consumer_key", config.get_consumerKey());
              response = authenticationStrategy.executeFeed("https://graph.qq.com/user/get_user_info", "GET", params, null, null);
              presp = response.getResponseBodyAsString(Constants.ENCODING);
              Map<String, Object> user_info = (Map<String, Object>) Json.fromJson(presp);
              if ((Integer)user_info.get("ret") == 0 ) { //获取成功
                if (user_info.get("nickname") != null)
                  p.setDisplayName(user_info.get("nickname").toString());
                if (user_info.get("figureurl") != null)
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);
    }
    try {
View Full Code Here

  protected Profile authLogin() throws Exception {
    String presp;

    try {
        String uid = this.accessGrant.getAttribute("uid").toString();
      Response response = authenticationStrategy.executeFeed(PROFILE_URL.replace("${uid}", uid));
      presp = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
      throw new SocialAuthException("Error while getting profile from "
          + PROFILE_URL, e);
    }
    try {
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.