Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-246

Better support for large Axiom attachments


    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0.2
    • Fix Version/s: 1.5 M2
    • Component/s: Core
    • Labels:
    • Environment:


      The AxiomSoapMessageFactory does not allow configuring how Axiom parses SOAP attachments (or at least, I could not find a way!). Because of this, all attachments are loaded into memory. Submitting a large attachment will cause out-of-memory exceptions. The problem seems to be because this class calls

      new Attachments(inputStream, contentType)

      in the createMultiPartAxiomSoapMessage() method which, looking at Axiom code (1.2.5) defaults it's "fileCacheEnable" property to "false". This causes the full contents of each attachment to get loaded into memory, even when doing this in server code:

      Attachment media = mimeRequest.getAttachment("my-id");
      FileCopyUtils.copy(media.getInputStream(), new FileOutputStream(mediaFile));

      I found a simple way to fix this, by using the full Attachments(InputStream, String, boolean, String, String) constructor, and providing configurable properties for the additional constructor elements, like this:

      Attachments attachments = new Attachments(inputStream, contentType, attachmentFileCaching,
      attachmentCacheDir, attachmentCacheSizeThreashold.toString());

      which refer to class properties:

      private boolean attachmentFileCaching = true;
      private String attachmentCacheDir = System.getProperty("java.io.tmpdir");
      private Integer attachmentCacheSizeThreashold = Integer.valueOf(4096);

      Then, adding setter method for these properties allows them to be configured. These defaults here mean for any attachment over 4k in size, it will be copied to a temp file in the Java temporary directory, and then subsequently reading that attachment InputStream will not cause an out-of-memory error to occur.




            • Assignee:
              arjen.poutsma Arjen Poutsma
              msqr Matt Magoffin
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: