0

I'm adding a zip-file to a SoapMessage in an AttachmenPart and after the message has been send I'm trying to move the folder containing the xml-message and the zip-file to a history-Folder containing all the previously sent messages. However, this isn't possible because when executing I'm getting the following error message:

Unable to delete file: H:\directory\containing\sent\attachment.zip

Here's the method to add the attachment:

private static void addAttachement(SOAPMessage message, SOAPEnvelope envelope, String path) throws SOAPException {
    URL url = null;
    File attachementFile = null;
    try {
        System.out.println(path);
        attachementFile = new File(path);
        url = attachementFile.toURI().toURL();
        DataHandler dataHandler = new DataHandler(url);
        AttachmentPart attachment = message.createAttachmentPart(dataHandler);
        attachment.setContentId(attachementFile.getName());
        message.addAttachmentPart(attachment);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

This function call sends the message:

SOAPMessage response = connection.call(message, new URL(SERVICE_LOCATION));

And here's the code that should move the folder:

File srcDir = new File(inFilePath + "/" + children[0]);
File destDir = new File(inFilePath + "/" + "Hist" + "/" + children[0]);            
FileUtils.moveDirectory(srcDir, destDir);

I'm using apache.commons.io.FileUtils

What prevents the zip-file from being deleted?

Daniel Wild
  • 167
  • 3
  • 7
  • 1
    Probably the file is still in use. You said `after the message has been send`, but that is not obvious from your code snippet. I don't know the soap package enough, but I would try to `close` the file after sending and then moving... wait ... isn't that `FileUtils.moveFile()` ? – PeterMmm May 03 '16 at 08:01
  • I'm actually moving the entire folder containing the sent xml message and the attachment. How can I close the file? – Daniel Wild May 03 '16 at 08:08

0 Answers0