Search code examples
javaperformanceweb-servicesweblogicmtom

WS Download operation with MTOM


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

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.

So how can I stream from DB via WS and MTOM to a WS client ?

Any idea ?

Thanks

Cris


Solution

  • I tried experimenting and finally i had some positive results.

    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";
        }
    }
    

    What I was affraid is that once I closed the input stream myself... the ws client did not received the binary content...

    Than i check and actually the DataHandler creates a new thread and closes the input stream

    I was able to stream 500MB from DB to client fast and with low memory footprint !