SAAJ - 发送消息后从磁盘中删除附件不起作用

时间:2016-05-03 07:24:47

标签: java web-services attachment fileutils saaj

我将一个zip文件添加到AttachmenPart中的SoapMessage中,并且在发送消息之后我试图将包含xml-message和zip文件的文件夹移动到历史记录中 - 包含所有先前发送的消息的文件夹。但是,这是不可能的,因为在执行时我收到以下错误消息:

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

以下是添加附件的方法:

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();
    }
}

此函数调用发送消息:

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

以下是应该移动文件夹的代码:

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

我正在使用apache.commons.io.FileUtils

是什么阻止了zip文件被删除?

0 个答案:

没有答案