我正在使用下面的代码从网络服务器检索附件。在这种情况下,客户端是 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();
}
}