Skip to main content

MTOM best practices

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2005-02-06

I use Weblogic 10.3.2 ( so jaxws metro based )

The web app I have is uploading and downloading large files (PDF's) via a WS (i know is not the optimum way for doing this but this is how it is now)

NOW the files that are uploaded and downloaded are inside the payload (base64).

10 simultaneously users can cause easily OOME , with some large payloads.

So for download operation I would like to stream the the pdf from the database to the user

For this I changed the WS in order to use MTOM :

@Mtom+ changed the wsdl

minOccurs="0" xmime:expectedContentTypes="*/*"

xmlns:xmime="" />

The ws returned this time DataHandler and I instantiated

return new DataHandler(new InputStreamDataSource(null, "*/*", inputStreamFromOracleBlob));

Code for InputStreamDataSource

After I generate the client I use

DataHandler dh =;

StreamingDataHandler sdh = (StreamingDataHandler)dh;

InputStream in = sdh.readOnce();

FileOutputStream fos = new FileOutputStream(new File("c://test.pdf"));

org.apache.xmlbeans.impl.common.IOUtil.copyCompletely(in, fos);

So things look ok

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-02-06

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 !