package votorola.g.web.wic; // Copyright 2009, 2012, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import javax.servlet.http.*; import org.apache.wicket.request.http.*; import votorola.g.lang.*; /** Web response utilities. * *

Note: WebResponse#{@linkplain WebResponse#enableCaching enableCaching} is * documented to enable caching in 1.5.4, but it does not. You must also override * WebPage.{@linkplain org.apache.wicket.markup.html.WebPage#setHeaders setHeaders} or it * clobbers the headers by calling disableCaching(). See bug 4357.

*/ public @ThreadSafe final class WebResponseX { private WebResponseX() {} /** Adds a cookie to the response, working around a known bug in WebResponse subclass * BufferedWebResponse. * * @see org.apache.wicket.protocol.http.BufferedWebResponse#addCookie(Cookie) */ public static void addCookie( final WebResponse response, final Cookie cookie ) { // response.addCookie( cookie ); // uncomment here and comment below to TEST /// If that's a BufferedWebResponse, then it fails under certain conditions: (1) when /// called on the last of three 302 redirects during OpenID login; and (2) on single /// redirect immediately after container startup, though it later recovers. See: /// https://issues.apache.org/jira/browse/WICKET-4358 /// So bypass the buffered response: ((HttpServletResponse)response.getContainerResponse()).addCookie( cookie ); } /** Clears a cookie in the response, working around a known bug in WebResponse * subclass BufferedWebResponse. A cookie instance obtained from the HTTP request * will have values for domain, path and so forth that are initially null. Ensure * they are corrected to match the values under which the cookie was originally * stored before calling this method, or it will probably fail. * * @param cookie the cookie to clear, or null to clear nothing. * * @see org.apache.wicket.protocol.http.BufferedWebResponse#clearCookie(Cookie) */ public static void clearCookie( final WebResponse response, final Cookie cookie ) { if( cookie == null ) return; cookie.setMaxAge( 0/*delete*/ ); cookie.setValue( null ); addCookie( response, cookie ); } }