3

I am trying to upload the attachment of size 350 MB through SOAP UI(with MTOM enabled) and sending the attachment to axis2 web services.

Axis2 web services is configured to be having MTOM enabled at server end. And caching is also enabled at server side. Following configuration is there in axis2.xml:

<parameter name="enableMTOM">true</parameter>

and

<parameter name="cacheAttachments">true</parameter>
<parameter name="attachmentDIR">C:\Temp\TempWS</parameter>
<parameter name="sizeThreshold">8000</parameter>

Tomcat Setting

Maximum heap size in tomcat is set to be 3000 MB(see screen shot above), but still web services is throwing me below exception:

Java heap space
java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOfRange(Arrays.java:2694)
    at java.lang.String.<init>(String.java:203)
    at java.lang.StringBuffer.toString(StringBuffer.java:561)
    at org.apache.axiom.util.base64.Base64Utils.encode(Base64Utils.java:81)
    at org.apache.axiom.om.impl.llom.OMTextImpl.getText(OMTextImpl.java:264)
    at org.apache.axiom.om.impl.llom.OMElementImpl.getText(OMElementImpl.java:786)
    at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:334)
    at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:407)
    at org.apache.axis2.databinding.utils.BeanUtil.processObject(BeanUtil.java:682)
    at org.apache.axis2.databinding.utils.BeanUtil.ProcessElement(BeanUtil.java:630)
    at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:562)
    at org.apache.axis2.rpc.receivers.RPCUtil.processRequest(RPCUtil.java:153)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:188)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:173)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:144)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at com.csdcsystems.amanda.servlet.AmandaAxisServlet.service(AmandaAxisServlet.java:103)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)

My Questions:

  1. Can someone help me understand what I am missing? Is there an additional setting that needs to be there in tomcat configuration?
  2. How can I support large attachments to get uploaded/downloaded through axis2 web services?

Note: Service is configured to be having byte[] as services's input/output parameter.

Puneet Gupta
  • 41
  • 1
  • 5
  • Where and how do you set the max heap size? – cowls Dec 01 '14 at 11:43
  • Hold on; why is there some `StringBuffer` in your trace here? Do you mean you generate a base64 string of _the whole file_ before sending it along? Why do you do that at all? Can you show your upload code? – fge Dec 01 '14 at 11:52
  • "Service is configured to be having byte[] as services's input/output parameter." <-- which means you wait to swallow it all before sending? Not very smart; why not just grabbing the connection's output stream and sending the bytes as you decode them (using Guava's BaseEncoding for instance)? – fge Dec 01 '14 at 11:57
  • @cowls- I have edited the post showing how I am setting the max heap space. Actually I have tomcat installed at my end, and its been shown in the image. – Puneet Gupta Dec 01 '14 at 12:11
  • http://stackoverflow.com/questions/12553350/best-way-to-increase-heap-size-in-catalina-bat-file – Himanshu Dec 01 '14 at 12:12
  • @fge: `StringBuffer` is internally used by Base64Util.class. If you can suggest me how I can grab connection's output stream with an example, then it would be great! – Puneet Gupta Dec 01 '14 at 12:13
  • I can only provide an example use of Guava's BaseEncoding; without the original code I can not adapt your code... – fge Dec 01 '14 at 12:23
  • @fge: I am just receiving the byte[] array in my service and using it in to save it in my database. Smaller attachments are working fine, but problem is occurring for big attachments. I have increased the heap size to approx 2-3 gb, but getting same exception for file of size 350 MB. I believe I am missing a trick to upload/download large attachment through axis2 ws. Any help is highly appreciated. – Puneet Gupta Dec 02 '14 at 04:59
  • Well then how do you write to your database? How do you read from it? Can you use streams to do either? – fge Dec 02 '14 at 09:54

1 Answers1

0

Try increasing the heap space with

C:\tomcat-7.0.57\bin>set JAVA_OPTS=-Xmx1g
C:\tomcat-7.0.57\bin>startup.bat

this will run jvm with 1GB of heap space, if still throws exception try 2g.

If you are running tomcat via eclipse, go to "Run Configurations", select your project, open "Arguments" tab and add -Xmx1g to the "VM arguments"

outdev
  • 5,249
  • 3
  • 21
  • 38
  • He did say "Maximum heap size in tomcat is set to be 3000 MB". However, he didnt say how he was setting it, so maybe he hasnt set it correctly. – cowls Dec 01 '14 at 11:43