0 Replies Latest reply: Jan 26, 2013 2:48 AM by csergiu77 RSS

    MTOM best practices

    csergiu77
      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="http://www.w3.org/2005/05/xmlmime" />

      The ws returned this time DataHandler and I instantiated

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

      Code for InputStreamDataSource http://tny.cz/7122db2b

      After I generate the client I use

      DataHandler dh = port.download(id);

      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….

      What I fear is that I am mot applying the best practices and I am stuck a little bit with upload.

      On upload I do not know how can I stream the content to the server and then into DB. (maybe I should create OutputStreamDataSource ?)

      Any idea for upload ?

      Should I use better the already done ByteArrayDataSource ? not the custom InputStreamDataSource ?

      Do I have to use @StreamingAttachment(parseEagerly=true, memoryThreshold=4000000L)?

      What if I don’t use @StreamingAttachment on WS , it will not use streaming ?
      Thanks a lot.
      Cris

      PS.
      I took a look on InputStreamDataSource and javax.mail.util.ByteArrayDataSourceand 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 ?