users@jersey.java.net

Re: [Jersey] Cleanup of jersey-multipart BodyPartEntity data

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 18 Feb 2009 10:39:47 +0100

On Feb 17, 2009, at 10:23 PM, Craig McClanahan wrote:

> Andrew Feller wrote:
>>
>> SCENARIO: Issuing multipart POST request to Jersey REST web service
>> with multiple file attachments; file attachments being stored to
>> disk in java.io.temp directory and not being cleaned up
>> ENVIRONMENT: Windows 2000, Java 6, Tomcat 6.0, jersey-bundle-1.0.1
>> SNAPSHOT, jersey-multipart-1.0.1 SNAPSHOT
>>
>> I am looking to upgrade to the latest versions of the Jersey bumdle
>> and multipart, but I wanted to bring this up. I know from an
>> earlier post ( http://n2.nabble.com/Problem-saving-binary-data-using-Jersey-multipart-td2242402.html
>> ) that jersey-multipart will store data exceeding the buffer size
>> to file, however I would like these files cleaned up at the end of
>> a request.
>>
> Are you calling multiPart.cleanup() after you have processed the
> contents? That will cause the temporary files to be cleaned up.
>
> And yes, it is unfortunate that the application developer has to
> remember to do this, but a better solution is not known at this time.

Working in it. Alex has proposed a CleanupSevice that can be injected
and one can add Closeable instances. The multipart support can use
this service. When the request goes out of scope the close method on
any registered Closeable instances will be invoked (and guaranteed to
be invoked).

Paul.