Weblogic 10.3.6 JAX-WS Web服务未从FileSystem中删除MTOM附件的临时副本

时间:2017-11-30 22:19:28

标签: web-services jax-ws weblogic11g mtom

我开发了一个JAX-WS Web服务来处理大文件(上传/下载)。在Web服务和客户端上都启用了MTOM附件+流媒体功能。部署在Weblogic 10.3.6 JDK 1.7

// Enable attachment streaming feature
// dir - attachment above memoryThreshold are stored in this directory
// parseEagerly - Streaming attachments are to be parsed eagerly (read or write the complete attachment)
// memoryThreshold - Memory threshold set to 4MB. Attachments under 4MB are stored in memory.
@StreamingAttachment(dir="C:/Users/rakesh/Desktop/temp/server", parseEagerly=true, memoryThreshold=40000L)
//Enable MTOM (Message Transmission Optimization Mechanism) feature for xs:binary64 data over 10KB (10240 bytes)
@MTOM(enabled=true, threshold=10240)
@WebService
public class ImagingStreamingWebService {
...
}

MTOM流媒体在上传和下载方面都运行良好。如果客户端发送大于4MB的大附件,则会出现问题。基于@StreamingAttachment注释附件保存到dir="C:/Users/rakesh/Desktop/temp/server"处理完成并将响应发送回客户端后,临时附件文件不会从上面的dir中删除。

即使在JVM回收(服务器关闭)之后,也不会删除临时附件文件。请参阅下面临时目录中的文件图片

Temp attachment files on FileSystem

我找不到任何删除这些文件的方法。手动删除或批处理/脚本以清理目录是不可能的,因为它们被JVM锁定。理想的是在webmethod处理完成后立即删除这些文件。

1 个答案:

答案 0 :(得分:0)

在webservice方法中访问InputStream并完成处理后,请在从webservice方法返回之前关闭DataHandler和底层InputStream。

关闭datahandler和inputstream的示例代码

public static void close(final DataHandler dataHandler) throws IOException {
    if (dataHandler instanceof StreamingDataHandler) {
        ((StreamingDataHandler) dataHandler).close();
    }
    else {
        dataHandler.getInputStream().close();
    }
    LOGGER.debug("DataHandler closed");
}

如果关闭,属性临时文件将自动删除。 我希望它对某人有所帮助。