I am experimenting some possibilities at this moment :-)

You said you have temporary binary files to send. How are these files generated? If the files are generated on the fly by your own code, you could create a DataSource implementation wrapping your generation code. Supposing your generation code writes to an OutputStream, you could use a PipedOutputStream, and make your DataSource return a connected PipedInputStream. Just ensure your generator runs in a separated thread, and you will have no temporary files to delete :-P

If you obtain the files from third-party code, or from external applications, I guess your only option will be to ensure file deletion from the FileDataSource. You could create a FileDataSource subclass like:

public class TempFileDataSource extends FileDataSource {
 public TempFileDataSource(String name) {
   this(new File(name));
 }

 public TempFileDataSource(File f) {
   super(f);
   f.deleteOnExit();
 }

 public void finalize() {
   f.delete();
   super.finalize();
 }
}

It is not a safe option, and I have not tested it yet. I guess it will fail if the DataSource instance is gc'ed before the InputStream used to obtain its contents. I do not know if this can happen, as it depends on the Axis source code, but I think it could work. You could also overwrite the getInputStream() method, and wrap the returned InputStream by a custom class that performs the deletion on the InputStream finalization, but this would prevent the file from being used twice.

Depending on your requirements / possibilities, another option is to redesign your service interface and add a method to delete the temporary files in a separated call, after finishing with them, and maintaining a background thread that deletes those temporary files that reach a certain timeout. Just store a pair (file, timestamp) in a list and make your background thread delete those items that are older than a certain amount of time. This thread would be only a safety measure, as only aborted (or buggy) clients would let undeleted files on your server.

Hope this helps you,
Rodrigo Ruiz

Heinz Schwarz wrote:

I have some Axis-Webservices which deliver binary files via attachments.
After sending the attachment, I have to delete this (temporary) attachment.


What is the best way to do this ?
How can I be sure that my client has received the attachment ?

Thanks Heinz








Reply via email to