Package play.libs.WS

Examples of play.libs.WS.HttpResponse


    OAuthSession sess = (OAuthSession) Cache
        .get(session.getId() + "-oauth");
    boolean sandboxLogout = (Boolean) Cache.get(session.getId() + "-sandbox");
    Map<String, Object> params = new HashMap();
    params.put("token", sess.access_token);
    HttpResponse revokeResponse = WS.url(sandboxLogout ? REVOKE_URL_sBox : REVOKE_URL).params(params).post();
    if (!revokeResponse.success()) {
      Logger.info("revoke response failed: " + revokeResponse.toString());
    }
    if (sess != null) {
      Cache.safeDelete(session.getId() + "-oauth");
//      Logger.info("cache removed in logout:");
//      OAuthSession u = OAuthSession.get(sess.uid);
View Full Code Here


      params.put("client_id", clientid);
      params.put("client_secret", secret);
      params.put("redirect_uri",
          play.mvc.Router.getFullUrl("ForceDotComOAuth2.callback"));
      params.put("code", accessCode);
      HttpResponse response = WS.url(sandboxLogin ? TOKEN_URL_sBox : TOKEN_URL).params(params).post();
      JsonObject r = response.getJson().getAsJsonObject();

      // ensure all expected elements are present in response object
      if (attributesPresent(r, Lists.newArrayList(ACCESS_TOKEN,
          REFRESH_TOKEN, ID_ATTR, INSTANCE_URL, SIGNATURE))) {
       
        OAuthSession s = new OAuthSession();
        s.access_token = r.getAsJsonPrimitive(ACCESS_TOKEN).getAsString();
        s.refresh_token = r.getAsJsonPrimitive(REFRESH_TOKEN).getAsString();
        s.idURL = r.getAsJsonPrimitive(ID_ATTR).getAsString();
        s.instance_url = r.getAsJsonPrimitive(INSTANCE_URL).getAsString();
        s.signature = r.getAsJsonPrimitive(SIGNATURE).getAsString();

        String id = s.idURL.substring(s.idURL.lastIndexOf('/') + 1);
        s.uid = id;
       
        Cache.set(session.getId() + "-oauth", s);
        Cache.set(session.getId() + "-sandbox", sandboxLogin);
       
        if (isPersistentSession()) {
          Response.current().setCookie("uid",
              id + "-" + Crypto.sign(id), "30d");
          s.save();
        }
        listener.onSuccess(s);
      } else {
        Logger.error("Callback failed. HttpResponse was not valid after Post for token." +
            (sandboxLogin ? "Sandbox login attempt." : "Prod login attempt."));
        Logger.error("Response body from post: %s", response.getString());

        JsonPrimitive error = r.getAsJsonPrimitive("error");
        JsonPrimitive errorDescription = r.getAsJsonPrimitive("error_description");
        if (error != null && errorDescription != null) {
          listener.onFailure(error.getAsString(), errorDescription.getAsString());
View Full Code Here

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("grant_type", "refresh_token");
    params.put("refresh_token", currentSession.refresh_token);
    params.put("client_id", clientId);
    params.put("client_secret", sec);
    HttpResponse response = WS.url(tokenURL).params(params).post();
    JsonObject r = response.getJson().getAsJsonObject();

    // ensure all expected elements are present in response object
    if (attributesPresent(r, Lists.newArrayList(ACCESS_TOKEN,
        ID_ATTR, INSTANCE_URL, SIGNATURE))) {
View Full Code Here

      Application.index();
    }
    WSRequest req = WS.url(oauth.instance_url
        + "/services/data/v28.0/query/?q=%s", query);
    req.headers.put("Authorization", "OAuth " + oauth.access_token);
    HttpResponse response = req.get();

    int res = response.getStatus();
    if (res == 200) {
      return response.getJson().getAsJsonObject().getAsJsonObject();
    } else if (res == 400) {
      Logger.info("Response: 400 - Malformed query. Query: %s", query);
    } else if (res == 401) {
      Logger.info("Response: 401 - Calling refresh for query");
      retry = true;
View Full Code Here

    } else {
      // cache miss
      WSRequest req = WS.url(oauth.instance_url
          + "/services/data/v28.0/sobjects/%s/describe/", "PermissionSet");
      req.headers.put("Authorization", "OAuth " + oauth.access_token);
      HttpResponse response = req.get();
 
      int res = response.getStatus();
      if (res == 200) {
        JsonElement jsonResult = response.getJson();
        Cache.set(cacheKey, jsonResult.toString(), "6mn");
        return jsonResult.getAsJsonObject();
       
      } else if (res == 401) {
        Logger.info("Response: 400 - calling refresh in getUserPerms");
View Full Code Here

TOP

Related Classes of play.libs.WS.HttpResponse

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.