I created this little filter to automatically return a 304 if the
"If-None-Match" filter matches the ETag.
It's not clear to me however, how i can now prevent the entity to be
written to the output stream, wile preserving the response headers.
public class NotModifiedFilter implements Filter {
private static final Logger log =
Logger.getLogger(NotModifiedFilter.class);
public void doFilter(final ServletRequest request, final
ServletResponse response, FilterChain chain) throws IOException,
ServletException {
chain.doFilter(request, new
HttpServletResponseWrapper((HttpServletResponse) response) {
boolean set_304 = false; // TODO use this flag to
intercept the
output stream, preventing the writing of the entity?
@Override
public void addHeader(String name, String value) {
if (name.equals("ETag")){
if (request instanceof
HttpServletRequest) {
String etagin =
((HttpServletRequest)request).getHeader("If-None-Match");
if (value.equals(etagin)) {
set_304 = true;
setStatus(HttpServletResponse.SC_NOT_MODIFIED);
log.debug("Changing
response status 200 into 304 because the
ETag matches the If-None-Match header");
}
}
}
super.addHeader(name, value);
}
});
}
}
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Resteasy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/resteasy-users