I was looking at the latest 2.1.x code which I know has had a bunch of changes 
around the attachment support to make sure streams are closed and such.  It's 
quite possible that 2.1.0 is different.

That said, the OTHER thing you can try is to override the getInputStream() 
call on the FileDataSource to return a FilterOutputStream that overrides 
the "close" method to call super.close() and then delete the file.  For the 
most part, I THINK we either have to call DataHandler.writeTo(..) or call 
DataHandler.getInputStream() and copy the bytes out of there and into the 
target stream.

Dan


On Wednesday 03 December 2008 2:08:14 pm Daniel Lipofsky wrote:
> Unfortunately that doesn't seem to work.  I see no evidence
> that my code is actually being called, i.e. there is no log
> output and the file is not deleted, but everything works
> without errors like it did before I added this code.
> Does CXF really call this method?  It seems possible
> that it could be getting the streams directly from the
> DataHandler.  I'm using CXF 2.1.0, JBoss 4.2.3, JDK 1.5.
>
> This is what I am implemented:
>
> public DataHandler getObjectsAsAttachment(...) throws WSException {
>     try {
>         final File tempFile = ...;
>         ...
>         return new DataHandler(new FileDataSource(tempFile)) {
>             @Override
>             public void writeTo(OutputStream out) throws IOException {
>                 super.writeTo(out);
>                 log.info("########### " + tempFile + " ###########");
>                 tempFile.delete();
>             }
>         };
>     } catch (Exception e) {
>         log.error("Exception thrown in getObjectsAsAttachment", e);
>         throw new WSException(e);
>     }
> }
>
> > -----Original Message-----
> > From: Daniel Kulp
> > Sent: Tuesday, December 02, 2008 2:38 PM
> >
> > In general, in this type of case, I recommend doing something like:
> > (pseudo
> > code)
> >
> >  return new DataHandler(new FileDataSource(tempFile)) {
> >     public void writeTo(OutputStream out)  {
> >         super.writeTo(out);
> >         tempFile.delete();
> >     }
> > };
> >
> > or similar.   Basically, when the datahandler is done being written
> > out,
> > delete the file.
> >
> > Dan
> >
> > On Tuesday 02 December 2008 1:14:40 pm Daniel Lipofsky wrote:
> > > I have a web-service that is returning a stream like this:
> > >
> > >   <xsd:element name="objects" type="xsd:base64Binary"
> > >      xmime:expectedContentTypes="application/octet-stream"/>
> > >
> > > My implementation method works by creating a
> > > temporary file and the returning like
> > >
> > >   return new DataHandler(new FileDataSource(tempFile));
> > >
> > > My understanding is that this is asynchronous.
> > > So how can I trigger a deletion of this file
> > > when the streaming is done?
> > >
> > > I am already calling tempFile.deleteOnExit() but it
> > > could be months or years before the JVM actually exits,
> > > and I want to delete it sooner.
> > >
> > > Thanks,
> > > Dan



-- 
Daniel Kulp
[EMAIL PROTECTED]
http://dankulp.com/blog

Reply via email to