Here is what I use to keep the cookies (headers): public class NonResettingRestartException extends ReplaceHandlerException {
public NonResettingRestartException(final Class<? extends Page<?>> pageClass, final PageParameters params, final RequestCycle cycle) { super(createRequestHandler(pageClass, params), true); Response response = cycle.getResponse(); if (response instanceof IMetaDataBufferingWebResponse) { IMetaDataBufferingWebResponse bufferingWebResponse = (IMetaDataBufferingWebResponse) response; bufferingWebResponse.writeMetaData((WebResponse) cycle.getOriginalResponse()); } } private static IRequestHandler createRequestHandler(Class<? extends Page<?>> pageClass, PageParameters params) { return new RenderPageRequestHandler(new PageProvider(pageClass, params)); } } On Thu, Sep 29, 2011 at 12:01 AM, <b...@actrix.gen.nz> wrote: > Hi, > > How do I add a cookie to a URL redirect response? I started with the > following class: > > public class RedirectToUrlWithHandlerException extends > ReplaceHandlerException { > ... > > public RedirectToUrlWithHandlerException(final String redirectUrl, > final int statusCode, final IRequestHandler handler) { > super(new RedirectRequestHandler(redirectUrl, statusCode){ > @Override > public void detach(IRequestCycle requestCycle) { > super.detach(requestCycle); > handler.detach(requestCycle); > } > @Override > public void respond(IRequestCycle requestCycle) { > super.respond(requestCycle); > handler.respond(requestCycle); > } > }, true); > } > } > > > and in the page: > > throw new RedirectToUrlWithHandlerException(targetUrl, new > IRequestHandler(){ > @Override > public void respond(IRequestCycle requestCycle) { > // Set cookie > cookieUtils.save(name, value); > } > > @Override > public void detach(IRequestCycle requestCycle) { } > }); > > with cookieUtils: > > instance.cookieUtils = new CookieUtils(cookieDefaults){ > @Override > protected void initializeCookie(Cookie cookie) { > super.initializeCookie(cookie); > cookie.setPath("/"); > } > }; > > > Still no cookie in the response. > > I know this is a tricky issue where older browsers don't always > cooperate, but the page being redirected to can't set the cookie > because the cookie is used to transfer information to it. > > Many thanks, > > Bernard > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org