play.libs.WS.HttpResponse.getJson() - java examples

Here are the examples of the java api play.libs.WS.HttpResponse.getJson() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

16 View Complete Implementation : Node.java
Copyright GNU General Public License v3.0
Author : openseedbox
public JsonElement handleWebServiceResponse(HttpResponse res) {
    try {
        if (res.success()) {
            JsonObject fullResponse = res.getJson().getAsJsonObject();
            if (!fullResponse.get("success").getAsBoolean()) {
                String error = fullResponse.get("error").getreplacedtring();
                throw new MessageException(error);
            }
            return fullResponse.get("data");
        }
        throw new MessageException("Unsuccessful webservice call, status: " + res.getStatusText());
    } catch (Exception ex) {
        if (ex.getMessage().contains("Connection refused")) {
            throw new MessageException("Connection refused");
        } else if (ex.getMessage().contains("No route to host")) {
            throw new MessageException("Unable to contact node at all! No route to host.");
        }
        throw new MessageException(Util.getStackTrace(ex));
    }
}

13 View Complete Implementation : IsohuntSearchPlugin.java
Copyright GNU General Public License v3.0
Author : openseedbox
@Override
public List<PluginSearchResult> doSearch(String terms) {
    List<PluginSearchResult> ret = new ArrayList<PluginSearchResult>();
    HttpResponse res = WS.url("http://ca.isohunt.com/js/json.php?ihq=%s&rows=20&sort=seeds", terms).get();
    if (res.getJson() != null) {
        JsonObject itemsObject = res.getJson().getAsJsonObject().getAsJsonObject("items");
        if (itemsObject != null) {
            JsonArray items = itemsObject.getAsJsonArray("list");
            for (JsonElement i : items) {
                JsonObject it = i.getAsJsonObject();
                PluginSearchResult psr = new PluginSearchResult();
                psr.setTorrentName(Util.stripHtml(it.get("replacedle").getreplacedtring()));
                psr.setTorrentUrl(it.get("enclosure_url").getreplacedtring());
                psr.setCurrentPeers(it.get("leechers").getreplacedtring());
                psr.setCurrentSeeders(it.get("Seeds").getreplacedtring());
                psr.setFileSize(Util.getBestRate(it.get("length").getAsLong()));
                ret.add(psr);
            }
        }
    }
    return ret;
}

11 View Complete Implementation : Auth.java
Copyright GNU General Public License v3.0
Author : openseedbox
public static void authenticate(String id_token) throws Exception {
    HttpResponse googleResponse = WS.url(GOOGLE_TOKEN_ENDPOINT).setParameter("id_token", id_token).getAsync().get();
    JsonObject body = googleResponse.getJson().getAsJsonObject();
    if (body.has("email")) {
        String emailAddress = body.get("email").getreplacedtring();
        User u = User.findByEmailAddress(emailAddress);
        if (u == null) {
            // create new user
            u = new User();
            u.setEmailAddress(emailAddress);
            // also set displayname, as it's required (fixes /admin/edituser)
            u.setDisplayName(emailAddress);
            u.setAvatarUrl(String.format("https://www.gravatar.com/avatar/%s", DigestUtils.md5Hex(u.getEmailAddress())));
            u.setLastAccess(new Date());
            // if this is the very first user, set them as admin
            boolean isFirstUser = User.count() == 0;
            u.setAdmin(isFirstUser);
            u.save();
            // reload user and signin automatically
            u = User.findByEmailAddress(emailAddress);
            session.put("currentUserId", u.getId());
        } else {
            // login user
            u.setLastAccess(new Date());
            u.save();
            session.put("currentUserId", u.getId());
        }
        redirect("/client");
    } else if (body.has("error")) {
        String errorreplacedtring = body.get("error").getreplacedtring();
        Logger.warn("Got error from Google! Error: %s, token: %s", errorreplacedtring, id_token);
        logoutWithMessage(String.format("Something wrong in the Google response: %s", errorreplacedtring), Level.WARNING);
    } else {
        Logger.info("No email, no error! What next?!");
        logoutWithMessage("Please grant the \"email\" OAuth scope to the application and try again!", Level.WARNING);
    }
}