2010-09-29 60 views
0

我正在使用下面的代碼從Web服務器檢索附件。在這種情況下,客戶端是一個Web瀏覽器。因此,目前,用戶向附件的web服務器發出請求。網絡服務器向另一臺服務器發送MTOM請求以獲取附件。然後,該Web服務器在開始將附件寫入響應之前,等待附件下載。用戶等待兩次以獲取文件。如何訪問Axis2代碼以訪問臨時文件,以便在創建時將其傳輸給用戶?我知道這聽起來不像是這樣做的最佳方式,但這是要求。我正在處理高達2GB的大文件,因此等待兩倍的時間才能收到文件。如何將Axis 2 MTOM臨時文件傳輸到HttpServletRequest

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

回答

0
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(); 
相關問題