You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by divad91 <di...@hotmail.com> on 2013/04/04 14:43:33 UTC
Browser Cookie detection
Hi
I just migrated to wicket 6.6.0 and I need display a page to the customer
when his browser cookies are disabled.
Is there a better approach to do this ? Is it better to
- add a cookie to the response and redirect to the same page and then check
the presence of the cookie in the request
Or
- use session().getClientInfo().getProperties().isCookiesEnabled() provided
method.
Thanks.
David
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Browser Cookie detection
Posted by divad91 <di...@hotmail.com>.
thanks it's working !
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657826.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Browser Cookie detection
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
You can use something like:
String url = urlFor(page, page.getPageParameters());
throw new RedirectToUrlException(url, 302);
On Mon, Apr 8, 2013 at 4:33 PM, divad91 <di...@hotmail.com> wrote:
> In wicket 1.4.21, I was using the RedirectException class. Cookies were
> transfered.
>
> public HomePage(final PageParameters parameters) {
> super(parameters);
>
> if (MySession.session().isSessionSetup()) {
> Cookie requestCookie = ((WebRequest)
> getRequest()).getCookie("appCoookie");
> if (requestCookie == null) {
> // Cookies are not enabled.
> }
> // Working with wicket 1.4.21
> }
>
> Cookie appCookie = new Cookie("appCoookie", "1");
> appCookie.setMaxAge(3600 * 5);
> appCookie.setPath("/");
> appCookie.setSecure(false);
> ((WebResponse) getResponse()).addCookie(appCookie);
>
> if (!MySession.session().isSessionSetup()) {
> MySession.session().setIsSessionSetup(true);
> throw new RedirectException(HomePage.class);
> }
> }
>
> Is there a similar exception that I could use in wicket 6.6.0 to do the
> same
> work (add the cookie to the response and then check it in the request) ?
>
> Thanks
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657822.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>
Re: Browser Cookie detection
Posted by divad91 <di...@hotmail.com>.
In wicket 1.4.21, I was using the RedirectException class. Cookies were
transfered.
public HomePage(final PageParameters parameters) {
super(parameters);
if (MySession.session().isSessionSetup()) {
Cookie requestCookie = ((WebRequest)
getRequest()).getCookie("appCoookie");
if (requestCookie == null) {
// Cookies are not enabled.
}
// Working with wicket 1.4.21
}
Cookie appCookie = new Cookie("appCoookie", "1");
appCookie.setMaxAge(3600 * 5);
appCookie.setPath("/");
appCookie.setSecure(false);
((WebResponse) getResponse()).addCookie(appCookie);
if (!MySession.session().isSessionSetup()) {
MySession.session().setIsSessionSetup(true);
throw new RedirectException(HomePage.class);
}
}
Is there a similar exception that I could use in wicket 6.6.0 to do the same
work (add the cookie to the response and then check it in the request) ?
Thanks
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657822.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Browser Cookie detection
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
org.apache.wicket.NonResettingRestartException does lead to HTTP redirect.
It just restarts the processing of the current request at the server side.
That is after throwing this exception you should not expect that the cookie
has been delivered to the browser. There is no interaction with the browser
at all.
In contrast to RestartResponseException it preserves any cookies (and some
other headers) in the buffering web response.
On Fri, Apr 5, 2013 at 9:49 PM, divad91 <di...@hotmail.com> wrote:
> I just created a new wicket 6.6.0 quickstart project
> (http://wicket.apache.org/start/quickstart.html)
> and I have the same problem.
>
> If I add the following code in the HomePage class,
>
> Cookie requestCookie = ((WebRequest) getRequest()).getCookie("appCoookie");
> System.out.println("----------------------->" + (requestCookie != null));
>
> Cookie appCookie = new Cookie("appCoookie", "1");
> appCookie.setMaxAge(3600 * 5);
> appCookie.setPath("/");
> appCookie.setSecure(false);
>
> ((WebResponse) getResponse()).addCookie(appCookie);
> if (getSession().getAttribute("init") == null) {
> getSession().setAttribute("init", "true");
> System.out.println("here...");
> throw new NonResettingRestartException(HomePage.class);
> }
>
> the second time I enter the HomePage constructor, the cookie is not present
> in the request.
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657789.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>
Re: Browser Cookie detection
Posted by divad91 <di...@hotmail.com>.
I just created a new wicket 6.6.0 quickstart project
(http://wicket.apache.org/start/quickstart.html)
and I have the same problem.
If I add the following code in the HomePage class,
Cookie requestCookie = ((WebRequest) getRequest()).getCookie("appCoookie");
System.out.println("----------------------->" + (requestCookie != null));
Cookie appCookie = new Cookie("appCoookie", "1");
appCookie.setMaxAge(3600 * 5);
appCookie.setPath("/");
appCookie.setSecure(false);
((WebResponse) getResponse()).addCookie(appCookie);
if (getSession().getAttribute("init") == null) {
getSession().setAttribute("init", "true");
System.out.println("here...");
throw new NonResettingRestartException(HomePage.class);
}
the second time I enter the HomePage constructor, the cookie is not present
in the request.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657789.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Browser Cookie detection
Posted by divad91 <di...@hotmail.com>.
Sorry this was just a test cookie.
Even with the age,
Cookie appCookie = new Cookie("appCoookie", "1");
appCookie.setMaxAge(3600 * 5);
appCookie.setPath("/");
appCookie.setSecure(false);
the cookie is not transfer. When i debug, in the transferResponseMetaData of
the NonResettingRestartException class, the originalResponse and the
response are the same so the meta data are not written.
WebResponse originalResponse = (WebResponse) cycle.getOriginalResponse();
if (originalResponse != response) {
IMetaDataBufferingWebResponse bufferingWebResponse =
(IMetaDataBufferingWebResponse) response;
bufferingWebResponse.writeMetaData(originalResponse);
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657780.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Browser Cookie detection
Posted by Martin Grigorov <mg...@apache.org>.
Set some age for this cookie.
On Fri, Apr 5, 2013 at 4:31 PM, divad91 <di...@hotmail.com> wrote:
> Does NonResettingRestartException suppose to keep the cookies in the
> response
> ?
>
> I am using wicket 6.6.0 on jboss 6 and when I throw a
> NonResettingRestartException, the cookies are not present in the request
> after.
>
> Cookie appCookie = new Cookie("appCoookie", "1");
> ((WebResponse) getResponse()).addCookie(appCookie);
> // Redirection needed for client cookies detection.
> throw new
>
> NonResettingRestartException(AppWebSession.session().getNavigationManager().getEntryPoint()
> .getNodeClass(),
> this.pageParameters);
>
> .....
>
> In the same page constructor the first thing i check is the presence of the
> cookie:
> Cookie requestCookie = ((WebRequest) getRequest()).getCookie("appCoookie");
> System.out.println("----------------------->" + (requestCookie != null));
> // Always false.
>
> Thanks
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657772.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>
Re: Browser Cookie detection
Posted by divad91 <di...@hotmail.com>.
Does NonResettingRestartException suppose to keep the cookies in the response
?
I am using wicket 6.6.0 on jboss 6 and when I throw a
NonResettingRestartException, the cookies are not present in the request
after.
Cookie appCookie = new Cookie("appCoookie", "1");
((WebResponse) getResponse()).addCookie(appCookie);
// Redirection needed for client cookies detection.
throw new
NonResettingRestartException(AppWebSession.session().getNavigationManager().getEntryPoint()
.getNodeClass(), this.pageParameters);
.....
In the same page constructor the first thing i check is the presence of the
cookie:
Cookie requestCookie = ((WebRequest) getRequest()).getCookie("appCoookie");
System.out.println("----------------------->" + (requestCookie != null));
// Always false.
Thanks
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657772.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Browser Cookie detection
Posted by divad91 <di...@hotmail.com>.
Thanks for your help I will consider this option !
David
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657753.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Browser Cookie detection
Posted by Martin Grigorov <mg...@apache.org>.
You can either show "Cookies are required" feedback message in the current
page or use "document.location= 'the/other/page'" to move to another page.
On Thu, Apr 4, 2013 at 4:33 PM, divad91 <di...@hotmail.com> wrote:
> Thanks for your answer !
>
> If I check the presence of the cookies in Javascript, how would you
> redirect
> the client to the "cookie disabled page" ?
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657749.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>
Re: Browser Cookie detection
Posted by divad91 <di...@hotmail.com>.
Thanks for your answer !
If I check the presence of the cookies in Javascript, how would you redirect
the client to the "cookie disabled page" ?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744p4657749.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Browser Cookie detection
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
I think the first approach is better. I'd just use JavaScript to check that
the cookie is stored (and probably remove it) instead of doing http
redirect.
The second approach requires usage
of org.apache.wicket.settings.IRequestCycleSettings#setGatherExtendedBrowserInfo(true)
On Thu, Apr 4, 2013 at 3:43 PM, divad91 <di...@hotmail.com> wrote:
> Hi
>
> I just migrated to wicket 6.6.0 and I need display a page to the customer
> when his browser cookies are disabled.
>
> Is there a better approach to do this ? Is it better to
>
> - add a cookie to the response and redirect to the same page and then check
> the presence of the cookie in the request
>
> Or
>
> - use session().getClientInfo().getProperties().isCookiesEnabled() provided
> method.
>
> Thanks.
> David
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Browser-Cookie-detection-tp4657744.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>