Package org.brickred.socialauth.util

Examples of org.brickred.socialauth.util.Response


    return userProfile;
  }

  private Profile getProfile() throws Exception {
    LOG.debug("Obtaining user profile");
    Response response;
    try {
      response = authenticationStrategy.executeFeed(PROFILE_URL);
    } catch (Exception e) {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from " + PROFILE_URL,
          e);
    }

    if (response.getStatus() == 200) {
      String respStr = response
          .getResponseBodyAsString(Constants.ENCODING);
      LOG.debug("Profile JSON string :: " + respStr);
      JSONObject obj = new JSONObject(respStr);
      JSONObject data = obj.getJSONObject("data");
      Profile p = new Profile();
      p.setValidatedId(data.optString("id"));
      String full_name = data.optString("full_name");
      p.setDisplayName(full_name);
      if (full_name != null) {
        String[] names = full_name.split(" ");
        if (names.length > 1) {
          p.setFirstName(names[0]);
          p.setLastName(names[1]);
        } else {
          p.setFirstName(full_name);
        }
      }
      p.setProfileImageURL(data.optString("profile_picture"));
      p.setProviderId(getProviderId());
      return p;
    } else {
      throw new SocialAuthException(
          "Failed to retrieve the user profile from " + PROFILE_URL
              + ". Server response " + response.getStatus());
    }
  }
View Full Code Here


  private Profile getProfile() throws Exception {
    Profile profile = new Profile();
    String url = PROFILE_URL;
    LOG.debug("Obtaining user profile. Profile URL : " + url);
    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

      throws Exception {
    if (!isVerify) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    Response response = null;
    LOG.debug("Calling URL : " + url);
    response = authenticationStrategy.executeFeed(url, methodType, params,
        headerParams, body);
    return response;
  }
View Full Code Here

      throws Exception {
    if (!isVerify) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    Response response = null;
    LOG.debug("Calling URL : " + url);
    response = authenticationStrategy.executeFeed(url, methodType, params,
        headerParams, body);
    return response;
  }
View Full Code Here

  @Override
  public String getLoginRedirectURL(final String successUrl) throws Exception {
    String associationURL = OpenIdConsumer.getAssociationURL(endpoints
        .get(Constants.OAUTH_REQUEST_TOKEN_URL));
    Response r = HttpUtil.doHttpRequest(associationURL,
        MethodType.GET.toString(), null, null);
    StringBuffer sb = new StringBuffer();
    String assocHandle = "";
    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(
          r.getInputStream(), "UTF-8"));
      String line = null;
      while ((line = reader.readLine()) != null) {
        sb.append(line).append("\n");
        if ("assoc_handle:".equals(line.substring(0, 13))) {
          assocHandle = line.substring(13);
View Full Code Here

  @Override
  public Response executeFeed(final String url, final String methodType,
      final Map<String, String> params,
      final Map<String, String> headerParams, final String body)
      throws Exception {
    Response response = null;
    if (accessToken == null) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    if (MethodType.GET.toString().equals(methodType)) {
View Full Code Here

  @Override
  public Response executeFeed(final String urlStr, final String methodType,
      final Map<String, String> params,
      final Map<String, String> headerParams, final String body)
      throws Exception {
    Response response = null;
    if (accessToken == null) {
      throw new SocialAuthException(
          "Please call verifyResponse function first to get Access Token");
    }
    if (MethodType.GET.toString().equals(methodType)) {
View Full Code Here

    sb.append("&client_secret=").append(
        oauth.getConfig().get_consumerSecret());
    sb.append("&code=").append(acode);
    sb.append("&grant_type=authorization_code");

    Response response;
    String authURL = null;
    try {
      if (MethodType.GET.toString().equals(methodType)) {
        authURL = sb.toString();
        LOG.debug("URL for Access Token request : " + authURL);
        response = HttpUtil.doHttpRequest(authURL, methodType, null,
            null);
      } else {
        authURL = endpoints.get(Constants.OAUTH_ACCESS_TOKEN_URL);
        LOG.debug("URL for Access Token request : " + authURL);
        response = HttpUtil.doHttpRequest(authURL, methodType,
            sb.toString(), null);
      }
    } catch (Exception e) {
      throw new SocialAuthException("Error in url : " + authURL, e);
    }
    String result;
    try {
      result = response.getResponseBodyAsString(Constants.ENCODING);
    } catch (IOException io) {
      throw new SocialAuthException(io);
    }
    Map<String, Object> attributes = new HashMap<String, Object>();
    Integer expires = null;
View Full Code Here

    this.providerSupport = providerSupport;
  }

  @Override
  public List<Album> getAlbums() throws Exception {
    Response response = providerSupport.api(ALBUMS_URL,
        MethodType.GET.toString(), null, null, null);

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

    return albums;
  }

  private List<Photo> getAlbumPhotos(final String id) throws Exception {

    Response response = providerSupport.api(PHOTOS_URL + id,
        MethodType.GET.toString(), null, null, null);
    LOG.info("Getting Photos of Album :: " + id);

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