cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <>
Subject Re: Empty stream when reading twice the content of an attachment greater than 100KB
Date Thu, 12 Jun 2014 10:25:16 GMT

On 11/06/14 23:10, sfont wrote:
> Hi!
> We have published a soap endpoint using cxf 2.7.10 on tomcat 6 and jdk 6.
> The web service request may contain one or more attachments (mtom support is
> enabled).
> The server side classes that we have we implemented to manage the request
> need to read the stream of every attachment more than one time.
> In most of our tests we have used files whose size was < 100KB and we had
> not found problems. Than, using a file with greater size, we have discovered
> that the subsequents calls to get the attachments stream receive an empty
> stream if the previous stream consumer has (correctly) closed it.
> This behaviour is described here (an old post):
> at point 1 and in particular in the statement: "closing stream of attachment
> “cached with temporary file”  will delete temporary file, and replace it’s
> content with a empty byte array."
> In that blog they suggest to use the cxf api to hold the attachment. Is it
> the best way to manage my requirement to read the stream of an attachment
> more times? Could a custom interceptor that manages the unhold task help me
> to let the code clean from this logic?

May be you can try

IOUtils.transferTo(attachmentInputStream, destinationFile);


This was added recently

> IMHO the different behavior between the case where the file is bigger or
> smaller than 100 kb is a little bit confusing and dangerous if unknown. In
> fact if we had not noticed this behavior we would have risked to lose the
> content of the file without a check on file size greater than zero. Why not
> to launch an Exception if the stream is unexpectedly unavailable when it is
> requested again?
Probably makes sense if CXF handler knows that the underlying temp file 
has already gone as part of the earlier close.

Cheers, Sergey

> Thank you very much for the great work with cxf!
> Stefano
> --
> View this message in context:
> Sent from the cxf-user mailing list archive at

View raw message