I dont understand, i try to send a cookie to my client browser (firefox, IE6
) but it doesn't seems to work.

so it is pretty simple i have a filter and a router


(*filter*1) ------- <router> ----- [handler1]
                           |
                           |---------- [handler2]




So here my filter


MyFilter extends Filter {

    //=> IN DEBUGMODE I SAW ANY COOKIES in the request object, but in my
firefox browser or IE
    // i have many cookies which came from my personal usage
    public void beforeHandle(Request request, Response response) {
        Cookie cookie = null;

        if ((cookie = hasCookie(request)) != null) {
            String hash = cookie.getValue();
             .....
        }
    }

    public void doHandle(Request request, Response response) {
        super.doHandle(request, response);
    }


    //=> I put in the response object the cookie, so by defautl it shoud
send the cookie to my browser
    public void afterHandle(Request request, Response response) {

        if (hasCookie(request) == null) {
            CookieSetting cookie = new CookieSetting(COOKIE_VERSION,
                    COOKIE_HASH, session.getHash(), COOKIE_PATH,
                    request.getHostRef().getIdentifier());

            cookie.setMaxAge(0);
            cookie.setSecure(false);
            response.getCookieSettings().add(cookie);
        }
    }


    private Cookie hasCookie(Request request) {

        List<Cookie> cookies = request.getCookies(); //always NULL

        for (Cookie cookie : cookies) {

            if (cookie.getPath().equals(COOKIE_PATH)
                    && cookie.getVersion() == COOKIE_VERSION.intValue()
                    && cookie.getDomain().equals(request.getHostRef
().getIdentifier())
                    && cookie.getName().equals(COOKIE_HASH)
                    && cookie.getValue().length() > 1) {
                return cookie;
            }

        }

        return null;

    }

}


Could you tell me what's wrong with my code ?
My goal it is to send a cookie to my client if it doesn't exist...

About my environment all of this it is run in a tomcat container, and i use
the restlet version 1.0.4.

thanks for your reply.




-- 
Regis LERAY

Reply via email to