users@jersey.java.net

[Jersey] How to filter a response after marshalling

From: zzantozz <rds6235_at_gmail.com>
Date: Thu, 30 Dec 2010 11:35:36 -0800 (PST)

I'm puzzled by the lack of any mechanism in Jersey for applying a response
filter after the marshalling of the response. In
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(),
all ContainerResponseFilters are applied before the call to
ContainerResponse.write(). I can see the usefulness of this, but I really
need an "around" filter or specific "before" and "after" filters here
instead of just a "before". My specific case is a need for the
open-session-in-view pattern in a Jersey app, but I'd think this would have
more general uses, too.

My problem in more detail: I can open a Session (Hibernate) in a
ContainerRequestFilter for use by the application, but if I close it in a
ContainerResponseFilter, then it's closed before the "view" is rendered
(object is marshalled), and so there was no point in even opening it to
begin with. The only other thing I've come up with is that I could perhaps
use a ContainerResponseFilter to wrap the ContainerResponse's responseWriter
with a ContainerResponseWriter whose finish() method would close the
Session, but I haven't yet checked whether finish() is guaranteed to always
be called.

Any advice? Comments on my potential solution?
-- 
View this message in context: http://jersey.576304.n2.nabble.com/How-to-filter-a-response-after-marshalling-tp5877285p5877285.html
Sent from the Jersey mailing list archive at Nabble.com.