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

Better support for large Axiom attachments

    Details

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

      Description

      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.

        Activity

        Hide
        msqr Matt Magoffin added a comment -

        Here is a sample implementation of these changes, starting from the 1.0.2 release version of the class.

        Show
        msqr Matt Magoffin added a comment - Here is a sample implementation of these changes, starting from the 1.0.2 release version of the class.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        This is now in SVN, thanks for the improvement!

        I've changed the default value of the attachmentCaching property to false, for backwards compatibility reasons.

        Show
        arjen.poutsma Arjen Poutsma added a comment - This is now in SVN, thanks for the improvement! I've changed the default value of the attachmentCaching property to false, for backwards compatibility reasons.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Closing 1.5 M2 issues.

        Show
        arjen.poutsma Arjen Poutsma added a comment - Closing 1.5 M2 issues.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: