Description
Matt Magoffin opened SWS-246 and commented
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.
Affects: 1.0.2
Attachments:
- AxiomSoapMessageFactory.java (10.47 kB)
Referenced from: commits 3f837ab