Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 232773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:02:44+00:00 2026-05-11T20:02:44+00:00

I have a temporary file with data that’s returned as part of a SOAP

  • 0

I have a temporary file with data that’s returned as part of a SOAP response via a MTOM binary attachment. I would like to trash it as soon as the method call “ends” (i.e., finishes transferring). What’s the best way for me to do this? The best way I can figure out how to do this is to delete them when the session is destroyed, but I’m not sure if there’s a more ‘immediate’ way to do this.

FYI, I’m NOT using Axis, I’m using jax-ws, if that matters.

UPDATE: I’m not sure the answerers are really understanding the issue. I know how to delete a file in java. My problem is this:

@javax.jws.WebService 
public class MyWebService {
...

 @javax.jws.WebMethod 
 public MyFileResult getSomeObject() {
   File mytempfile = new File("tempfile.txt");
   MyFileResult result = new MyFileResult();
   result.setFile(mytempfile);  // sets mytempfile as MTOM attachment

   // mytempfile.delete() iS WRONG
   // can't delete mytempfile because it hasn't been returned to the web service  client
   // yet.  So how do I remove it?

   return result;
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:02:44+00:00Added an answer on May 11, 2026 at 8:02 pm

    I ran into this same problem. The issue is that the JAX-WS stack manages the file. It is not possible to determine in your code when JAX-WS is done with the file so you do not know when to delete it.

    In my case, I am using a DataHandler on my object model rather than a file. MyFileResult would have the following field instead of a file field:

    private DataHandler handler;
    

    My solution was to create a customized version of FileDataSource. Instead of returning a FileInputStream to read the contents of the file, I return the following extension of FileInputStream:

    private class TemporaryFileInputStream extends FileInputStream {
        public TemporaryFileInputStream(File file) throws FileNotFoundException {
            super(file);
        }
    
        @Override
        public void close() throws IOException {
            super.close();
            file.delete();
        }
    }
    

    Essentially the datasource allows reading only once. After the stream is closed, the file is deleted. Since the JAX-WS stack only reads the file once, it works.

    The solution is a bit of a hack but seems to be the best option in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a temporary table that contains a part category and the associated part
I have a folder that will contain a temporary file that will be created
I have a string containing XML data that is returned from an http request.
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I have a sample file like the following: CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11 (
I have a temporary table that I'm using and I have a unique column,
In my app, I have a temporary div that is shown each time the
I have seen that Windows system use temporary files to increase the performance of
I have php script that creates a temporary watermark image for users that are
I am trying to create a temporary file in /data/local/tmp directory. The path is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.