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?