Package org.restlet.ext.json

Examples of org.restlet.ext.json.JsonRepresentation


        } catch (JSONException e) {
            //throw new ResourceException(Status.SERVER_ERROR_INTERNAL);
        }

        JsonRepresentation jr = new JsonRepresentation(json);

        jr.setCharacterSet(CharacterSet.UTF_8);

        //
        // store result
        item.getProperties().put(RestletConsumer.RESTLET_RESOURCE_OUT_REPRESENTATION,jr);
View Full Code Here


      } catch (JSONException e) {
        //throw new ResourceException(Status.SERVER_ERROR_INTERNAL);
      }

      JsonRepresentation jr = new JsonRepresentation(json);

      jr.setCharacterSet(CharacterSet.UTF_8);

        //
        // store result
        item.getProperties().put(RestletConsumer.RESTLET_RESOURCE_OUT_REPRESENTATION,jr);
View Full Code Here

                    }
                } catch (JSONException e) {
                    log.log(Level.WARNING, "Failed to get the ID!", e);
                }

                getResponse().setEntity(new JsonRepresentation(obj));
            }
            // cleanup of cookie
            getResponse().getCookieSettings().remove(DESCRIPTOR_COOKIE);
            CookieSetting disc = new CookieSetting(DESCRIPTOR_COOKIE, "");
            disc.setMaxAge(0);
View Full Code Here

    protected void afterHandle(Request request, Response response) {
        Cookie c = request.getCookies().getFirst(UserCookieID);
        if (c != null) {
            Representation r = response.getEntity();
            if (r != null && (r instanceof JsonRepresentation)) {
                JsonRepresentation jr = (JsonRepresentation) r;
                try {
                    JSONObject o = jr.getJsonObject();
                    if (o != null && o.has("id")) {
                        String id = o.getString("id");
                        getLogger().info("Caching JSON id = " + id);

                        userCache.put(c.getValue(), id);
View Full Code Here

                jcallback = request.getCookies().getFirstValue(
                        EXTERNAL_SERVER_COOKIE);
            if (jcallback != null) {
                Redirector dispatcher = new Redirector(getContext(), jcallback,
                        Redirector.MODE_SERVER_OUTBOUND);
                request.setEntity(new JsonRepresentation(obj));
                request.setMethod(Method.POST);
                dispatcher.handle(request, response);
                response.getCookieSettings().remove(EXTERNAL_SERVER_COOKIE);
            } else {
                response.setEntity(new JsonRepresentation(obj));
            }
        }
    }
View Full Code Here

            meRef.addQueryParameter(OAuthServerResource.ACCESS_TOKEN,
                    accessToken);

            ClientResource graphResource = new ClientResource(FB_GRAPH);
            ClientResource meResource = graphResource.getChild(meRef);
            JsonRepresentation meRepr = meResource
                    .get(JsonRepresentation.class);
            if (meResource.getResponse().getStatus().isSuccess()) {
                JSONObject me;
                try {
                    me = meRepr.getJsonObject();
                    String id = me.get("id").toString();
                    log.info("Your ID = " + id);
                    accessTokens.put(id, accessToken);
                    // TODO Set Cookie
                    return true;
                } catch (JSONException e) {
                    log.log(Level.WARNING, "Failed in parsing the me object.",
                            e);
                }
            }
            meRepr.release();
            meResource.release();
            graphResource.release();
        }

        return false;
View Full Code Here

            }
        }

        try {
            String error = null;
            JsonRepresentation rest = new JsonRepresentation(input);
            JSONObject call = rest.getJsonObject();
            String token = call.get("access_token").toString();
            String uri = call.get("uri").toString();
            JSONArray scopes = null;

            if (call.has("scope"))
View Full Code Here

                getLogger().info("After posting to validator...");
                repr.release();
                getLogger().info(
                        "Got Respose from auth resource OK "
                                + r.getClass().getCanonicalName());
                JsonRepresentation returned = new JsonRepresentation(r);

                // GET OBJECT
                JSONObject response = returned.getJsonObject();
                boolean authenticated = response.getBoolean("authenticated");

                if (response.has("tokenOwner"))
                    this.setUser(req, response, accessToken);

                String error = null;
                if (response.has("error"))
                    error = response.getString("error");

                getLogger().info("In Auth Filer -> " + authenticated);

                // Clean-up
                returned.release();
                r.release();
                authResource.release();

                if (authenticated)
                    return true;
View Full Code Here

        } else {
            // Fetch a resource: a JSON document full of search results
            String term = Reference.encode(args[0]);
            String uri = BASE_URI + "?appid=restbook&output=json&query=" + term;
            Representation entity = new ClientResource(uri).get();
            JSONObject json = new JsonRepresentation(entity).getJsonObject();

            // Navigate within the JSON document to display the titles
            JSONObject resultSet = json.getJSONObject("ResultSet");
            JSONArray results = resultSet.getJSONArray("Result");
            for (int i = 0; i < results.length(); i++) {
View Full Code Here

                rep.put("endpoint", ei.toJson());
            }
        } catch (JSONException e) {
            log.warning("Failed to produce JSON OAuth info");
        }
        JsonRepresentation repr = new JsonRepresentation(rep);
        repr.setMediaType(MEDIA_TYPE);
        response.setEntity(repr);

    }
View Full Code Here

TOP

Related Classes of org.restlet.ext.json.JsonRepresentation

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.