Package org.restlet.data

Examples of org.restlet.data.Cookie


* @author Arjohn Kampman
*/
class SessionUtil {

  static String getSessionID(Request request) {
    Cookie sessionCookie = request.getCookies().getFirst(SESSION_COOKIE);
    if (sessionCookie != null) {
      return sessionCookie.getValue();
    }
    return null;
  }
View Full Code Here


    }

    // Cache result
    @Override
    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);
                        createResponse(id, request, response);
                        clearCookies(response);
                    }
                } catch (JSONException ignore) {
                }
View Full Code Here

        }
    }

    @Override
    protected int doHandle(Request request, Response response) {
        Cookie c = request.getCookies().getFirst(UserCookieID);
        if (c == null) {
            String key = generate(40);
            CookieSetting cs = new CookieSetting(UserCookieID, key);
            response.getCookieSettings().add(cs);
            userCache.put(key, "");
View Full Code Here

        random.nextBytes(token);
        return toHex(token);
    }

    public boolean handleCached(Request request, Response response) {
        Cookie c = request.getCookies().getFirst(UserCookieID);
        if (c != null) { // might be in cache
            String key = c.getValue();
            if (key != null && key.length() > 0 && userCache.containsKey(key)) {
                createResponse(userCache.get(key), request, response);
                clearCookies(response);
                return true;
            }
View Full Code Here

        final String entity = response.getEntity().getText();
        assertEquals("c1, c2", entity.substring(1, entity.length() - 1));
    }

    public void testWithDefault() throws IOException {
        Response response = get("withDefault", new Cookie("c", "value"));
        sysOutEntityIfError(response);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("value", response.getEntity().getText());

        response = get("withDefault", new Cookie("c", "sdfgdfg"));
        sysOutEntityIfError(response);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("sdfgdfg", response.getEntity().getText());

        response = get("withDefault");
View Full Code Here

        return appConfig;
    }

    public void testCookieParams() throws IOException {
        final List<Cookie> cookies = new ArrayList<Cookie>();
        cookies.add(new Cookie("c", "c1"));
        cookies.add(new Cookie("c", "c2"));
        cookies.add(new Cookie("c", "c3"));
        cookies.add(new Cookie("cc", "cc1"));
        cookies.add(new Cookie("cc", "cc2"));
        cookies.add(new Cookie("cc", "cc3"));
        final Response response = getWithCookies("cookie", cookies);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("c=c1\ncc=[cc1, cc2, cc3]", response.getEntity().getText());
    }
View Full Code Here

            }
        };
    }

    public void test1() throws IOException {
        Response response = get(new Cookie("c", "value"));
        sysOutEntityIfError(response);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("value", response.getEntity().getText());

        response = get(new Cookie("c", "sdfgdfg"));
        sysOutEntityIfError(response);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("sdfgdfg", response.getEntity().getText());
    }
View Full Code Here

        assertEquals(null, text);
    }

    public void testCookieArray() throws Exception {
        final Request request = createGetRequest("array");
        request.getCookies().add(new Cookie("c", "c1"));
        request.getCookies().add(new Cookie("c", "c2"));
        request.getCookies().add(new Cookie("d", "c3"));
        final Response response = accessServer(request);
        sysOutEntityIfError(response);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        final String entity = response.getEntity().getText();
        final String entityWithoutBrackets = entity.substring(1, entity
View Full Code Here

        assertEquals("c1, c2", entityWithoutBrackets);
    }

    public void testCookieSet() throws Exception {
        final Request request = createGetRequest("Set");
        request.getCookies().add(new Cookie("c", "c1"));
        request.getCookies().add(new Cookie("c", "c2"));
        request.getCookies().add(new Cookie("d", "c3"));
        final Response response = accessServer(request);
        sysOutEntityIfError(response);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        final String entity = response.getEntity().getText();
        final String entityWithoutBrackets = entity.substring(1, entity
View Full Code Here

        }
    }

    public void testCookieSortedSet() throws Exception {
        final Request request = createGetRequest("SortedSet");
        request.getCookies().add(new Cookie("c", "c1"));
        request.getCookies().add(new Cookie("c", "c2"));
        request.getCookies().add(new Cookie("d", "c3"));
        final Response response = accessServer(request);
        sysOutEntityIfError(response);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        final String entity = response.getEntity().getText();
        assertEquals("c1, c2", entity.substring(1, entity.length() - 1));
View Full Code Here

TOP

Related Classes of org.restlet.data.Cookie

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.