Hello,
I have recently created some web services using TOMCAT 5.5 and AXIS 1.3. The aim
of those web services is to compute some data and to generate ZIP files. Those
ZIP files are returned to client each time he calls the web service.
The thing is that those ZIP files have to be removed from the server after each
call.
Here is how my web services look like
public DataHandler generateFile(String myParam){
MyConfig myConf = new MyConfig(); //generate a temporary folder on the server
in which data will be stored and ZIP file created
/*
* generation of temporary files in the created temporary folder
* and compression in a single ZIP archive
*/
DataHandler ret = new DataHandlern(new FileDataSource(myConf.myZipFile));
return ret; // return the zip file to client
}
The thing is that I can't manage to remove the created temporary folder once the 'return ret' has been done.
I tried many things:
. Deleting the temporary folder before calling 'return'
DataHandler ret = new DataHandlern(new FileDataSource(myConf.myZipFile));
myConf.cleanUpFolders();
return ret; // return the zip file to client
}
But I got a
FileNotFoundException (can't send the file if the file does no longer exists ;-) ) => this error seems logic to me
. Deleting the temporary folder using a '
try ... finally' block as follows:
try{
return ret;
}finally{
myConf.cleanUpFolders(); // method that remove temporary folder
}
but I also got a
FileNotFoundException (the 'return ret' can't find the ZIP file
I need to send, is it a kind of synchronizing problem?) -> file is deleted
before client get the ZIP file
. Third solution, creating a destructor in MyConfig class:
public void finalize(){
cleanUpFolders();
}
The problem here is that the destructor is called only when I restart the server (and a server purpose is not to be restarted each hours)
Is there any solution to remove those temporary files (that are stored on
various places on the server hard drive) after each web service call ?
Thanks for your help
Nicolas Cottais
PS: this is how my client retrieves the file from the web service:
ret = (DataHandler) call.invoke(new Object[] { monparam});
FileOutputStream archive = new FileOutputStream(savePath);// savepath is c:\\test.zip
ret.writeTo(archive);
archive.close();