users@jersey.java.net

Re: [Jersey] Cleanup

From: Craig McClanahan <craigmcc_at_gmail.com>
Date: Wed, 4 Nov 2009 13:01:37 -0800

On Wed, Nov 4, 2009 at 12:47 PM, Moises Lejter <moilejter_at_gmail.com> wrote:
> Would a CleanupFilter work?  They get call "around" each HTTP request,
> right?

More precisely, you'll want to take a look at ContainerResponseFilter
(for cleanup after the resource method returns) and perhaps
ContainerRequestFilter (to initialize things on the way in). It's
also possible to have a single Filter instance that implements both
interfaces if you need "around" type functionality. Note that, in
addition to cleanup, you can actually modify the response entity or
headers in a ContainerResponseFilter.

There are some gotchas to be aware of if your resource method might
throw exceptions ... Google these class names for more info.

Craig

>
> Moises
>
> On Wed, Nov 4, 2009 at 1:02 PM, dloy <david.loy_at_ucop.edu> wrote:
>>
>> I would like to do cleanup after a Jersey request completes (e.g. delete
>> temporary files, ...). Does Jersey provide any mechanism for running a
>> process at the completion of an http request?
>