使用 MTOM 进行 WS 下载操作 [英] WS Download operation with MTOM
问题描述
我想通过带有 MTOM 的 WS 直接从 Oracle 数据库 blob 文件流式传输到 WS 客户端.
I want to stream directly from an Oracle database blobs files via WS with MTOM directly to the WS client.
我以为我找到了这里描述的方法:
I thought I found a way which is described here:
http://www.java.net/forum/topic/glassfish/metro-and-jaxb/mtom-best-practices
但是在我查看了 InputStreamDataSource 和 javax.mail.util.ByteArrayDataSource 之后,我意识到它们在内存中实际包含了文档"的一个字节 [],这意味着流媒体的想法是徒劳的,导致我试图避免是在内存中同时拥有多个文档.
but after i took a look on InputStreamDataSource and javax.mail.util.ByteArrayDataSource i realized that they acutal hava a byte[] of the 'document' in memory meaning the streaming ideea is in vain, cause what i try to avoid is to have multiple docs in the same time fully in memory.
那么我如何通过 WS 和 MTOM 从 DB 流式传输到 WS 客户端?
So how can I stream from DB via WS and MTOM to a WS client ?
有什么想法吗?
谢谢
克里斯
推荐答案
我尝试过尝试,最后我得到了一些积极的结果.
I tried experimenting and finally i had some positive results.
为了从数据库直接流式传输到客户端浏览器,上述事情是有效的,但 InputStreamDataSource 应该是这样的:
In order to stream from DB directly to clients browser the above things are valid but the InputStreamDataSource should be like this:
public class InputStreamDataSource implements DataSource {
private InputStream inputStream;
public InputStreamDataSource(InputStream inputStream) {
this.inputStream = inputStream;
}
public InputStream getInputStream() throws IOException {
return inputStream;
}
public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException("Not implemented");
}
public String getContentType() {
return "*/*";
}
public String getName() {
return "InputStreamDataSource";
}
}
我害怕的是,一旦我自己关闭了输入流......ws 客户端没有收到二进制内容...
What I was affraid is that once I closed the input stream myself... the ws client did not received the binary content...
我检查了一下,实际上DataHandler创建了一个新线程并关闭了输入流
Than i check and actually the DataHandler creates a new thread and closes the input stream
我能够快速地将 500MB 从数据库传输到客户端,并且内存占用低!
I was able to stream 500MB from DB to client fast and with low memory footprint !
这篇关于使用 MTOM 进行 WS 下载操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!