tags:

views:

7

answers:

0

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