如何将 Axis 2 MTOM 临时文件流式传输到 HttpServletRequest

发布于 2024-09-25 17:34:47 字数 1534 浏览 2 评论 0原文

我使用下面的代码从网络服务器检索附件。本例中的客户端是 Web 浏览器。目前,用户向网络服务器请求附件。 Web 服务器向另一台服务器发出 MTOM 请求以获取附件。然后,该网络服务器等待附件下载,然后开始将该附件写入响应。用户等待两倍的时间才能获取文件。如何利用 Axis2 代码来访问临时文件,以便在创建临时文件时将其流式传输给用户?我知道这听起来不是最好的方法,但这是要求。我正在处理高达 2GB 的大文件,因此等待两倍的时间才能收到文件是行不通的。

Options options = new Options();
options.setTo(new EndpointReference(this.endpointUrl));
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
options.setProperty(Constants.Configuration.CACHE_ATTACHMENTS, Constants.VALUE_TRUE);
options.setProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR, this.tempDirectory);
options.setProperty(Constants.Configuration.FILE_SIZE_THRESHOLD, String.valueOf(this.tempFileSizeThreshold));
options.setTimeOutInMilliSeconds(this.serviceRequestTimeOut);

sender = new ServiceClient();
sender.setOptions(options);

OMElement result = sender.sendReceive(this.getAttachmentPayload(productId, attachmentId));

OMElement attachmentElement = result.getFirstElement();

Iterator<OMElement> elementIterator = attachmentElement.getChildElements();

String fileName = "";
DataHandler dataHandler = null;

while (elementIterator.hasNext()) {
    OMElement element = elementIterator.next();

    if (element.getQName().getLocalPart().equals("name")) {
        fileName = element.getText();
    } else if (element.getQName().getLocalPart().equals("attachment")) {
        dataHandler = (DataHandler) ((OMText) element.getFirstOMChild()).getDataHandler();
    }
}

I'm using the code below to retrieve an attachment from a webserver. The client in this case is a web browser. So currently, the user makes a request to a webserver for the attachment. The webserver makes an MTOM request to another server for the attachment. That webserver then waits for the attachment to download before it begins writing that attachment out to the response. The user is waiting twice as long to get the file. How can I tap into the Axis2 code to get access to the temp file so that I can stream it to the user as it is being created? I know this doesn't sound like the best way to do this, but this is the requirement. I'm working with large files up to 2GB, so waiting twice as long to recieve the file isn't working out.

Options options = new Options();
options.setTo(new EndpointReference(this.endpointUrl));
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
options.setProperty(Constants.Configuration.CACHE_ATTACHMENTS, Constants.VALUE_TRUE);
options.setProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR, this.tempDirectory);
options.setProperty(Constants.Configuration.FILE_SIZE_THRESHOLD, String.valueOf(this.tempFileSizeThreshold));
options.setTimeOutInMilliSeconds(this.serviceRequestTimeOut);

sender = new ServiceClient();
sender.setOptions(options);

OMElement result = sender.sendReceive(this.getAttachmentPayload(productId, attachmentId));

OMElement attachmentElement = result.getFirstElement();

Iterator<OMElement> elementIterator = attachmentElement.getChildElements();

String fileName = "";
DataHandler dataHandler = null;

while (elementIterator.hasNext()) {
    OMElement element = elementIterator.next();

    if (element.getQName().getLocalPart().equals("name")) {
        fileName = element.getText();
    } else if (element.getQName().getLocalPart().equals("attachment")) {
        dataHandler = (DataHandler) ((OMText) element.getFirstOMChild()).getDataHandler();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妳是的陽光 2024-10-02 17:34:47
org.w3.www._2005._05.xmlmime.Base64Binary b64data = ---YOUR_SOURCE_ATTACHMENT---;

org.apache.axiom.attachments.CachedFileDataSource ds = (CachedFileDataSource) b64data.getBase64Binary().getDataSource();

String absPath = ds.getFile().getAbsolutePath();
org.w3.www._2005._05.xmlmime.Base64Binary b64data = ---YOUR_SOURCE_ATTACHMENT---;

org.apache.axiom.attachments.CachedFileDataSource ds = (CachedFileDataSource) b64data.getBase64Binary().getDataSource();

String absPath = ds.getFile().getAbsolutePath();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文