You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by no...@free.fr on 2006/03/30 12:24:36 UTC

Removing Temporary Files after response is sent

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
  ...
  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 temporary folder created once the
 the 'return ret' has been done.

I tried many things:
. Deleting the temporary folder before calling 'return' -> I got a
FileNotFoundException (can't send the file if the file no longer exists ;-) )
. 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();
--------------------

Re: Removing Temporary Files after response is sent

Posted by no...@free.fr.
Found a solution :

I use a destructor in my web services class : this constructor call the
cleanUpFolders() method described previously.

I imagine that once service execution was done, TOMCAT or AXIS (or whatever)
will destroy the webservice instance : and it seems to work.

After 5 web services call, the olders folders have been automatically destroyed
(garbage collector stuff I suppose)

Thanks again to whom who tried to solve my problem.

Selon nocoz@free.fr:

> 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
>   ...
>   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 temporary folder created once
> the
>  the 'return ret' has been done.
>
> I tried many things:
> . Deleting the temporary folder before calling 'return' -> I got a
> FileNotFoundException (can't send the file if the file no longer exists ;-) )
> . 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();
> --------------------
>