Announcement Announcement Module
No announcement yet.
Out of memory error when marshalling large attachments Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Out of memory error when marshalling large attachments

    I'm using spring ws on the server side with a AxiomSoapmessageFactory:

    <bean id="messageFactory" class="">
           <property name="payloadCaching" value="true"/>
            <!-- Need to figure out the appropriate directory -->
           <property name="attachmentCacheDir" value="..."/>
    This works fine when the services are ingesting a message. However, when the services attempt to serve up a large message I get Java out of memory exception. Here is the stack trace:

    The problem seems to be that the services are attempting to read the whole attachment into memory prior to writing it out. Is there a way to stream the attachment?

    java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(
    at org.apache.axiom.mime.impl.axiom.MultipartWriterIm pl$PartOutputStream.write( :42)
    at javax.activation.DataHandler.writeTo(DataHandler.j ava:294)
    at org.apache.axiom.mime.impl.axiom.MultipartWriterIm pl.writePart(
    at rt(
    at WithAttachmentsMessage(
    at .writeSwAMessage(
    at .writeTo(
    at tMessageContent(
    at ceive(
    at eMessageReceiverObjectSupport.handleConnection(Web
    at ssageReceiverHandlerAdapter.handle(WebServiceMessa
    at bServiceMessageReceiverHandlerAdapter.handle(Error 42)
    at tcherServlet2.doService(MessageDispatcherServlet2. java:148)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(
    at org.springframework.web.servlet.FrameworkServlet.d oPost(
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at ternalDoFilter(
    at Filter(
    at org.apache.catalina.core.StandardWrapperValve.invo ke(
    at org.apache.catalina.core.StandardContextValve.invo ke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke (
    at org.apache.catalina.core.StandardEngineValve.invok e(
    at org.apache.catalina.connector.CoyoteAdapter.servic e(
    at org.apache.coyote.http11.Http11Processor.process(H
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(

    I'm running this in a Tomcat instance on OSX 10.6.7 java --version =

    java version "1.6.0_24"
    Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
    Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)

  • #2
    Found it

    So the problem was in the MessageDispatcher (ws 1.5.9.) When you have message tracing set to trace the MessageDispatcher attempts to retrieve the message as a String so it copies the message to ByteArrayOutputStream which causes the attachment to be loaded into memory. Here is the offending code from MessageDispatcher:

       private String getMessageContent(WebServiceMessage message) throws IOException {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            return bos.toString("UTF-8");