users@jersey.java.net

Re: [Jersey] Cleanup

From: dloy <david.loy_at_ucop.edu>
Date: Wed, 04 Nov 2009 14:45:45 -0800

Sorry to be slow on this.

I haven't found a working code example on the web.
<http://n2.nabble.com/Filters-td2285491.html> is about as close as I
could find.
<http://n2.nabble.com/ContainerResponseFilter-is-not-suitable-for-cleanup-job-td2312274.html>
is far from encouraging.

The javadoc for ContainerResponseFilter has:
A filter for filtering a response after the response is returned from a
resource class and before the response is written to the container.

The comment "before the response is written" implies (to me) that the
ContainerResponseFilter is called before the response is sent and/or
that the implementation must write out the response. Knowing some of
these details for how to do a cleanup following the transmission of a
response would be very useful. Also, are there other changes (web.xml?)

Does the @PreDestroy annotated method work?

Any help on this would be much appreciated.

Thanks
David



Craig McClanahan wrote:
> 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?
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>