Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7909

Sending large payloads with RestTemplate results in an OutOfMemoryError

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1 M1
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      When sending a large file with the RestTemplate (with a POST or PUT), the RestTemplate will throw an OutOfMemoryError:

      com.cat.tcm.jmx.ManagementException: An unexpected error occurred performing the operation. 
      at com.cat.tcm.jmx.JMXTaskTemplate.run(JMXTaskTemplate.java:144) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
      at java.lang.Thread.run(Thread.java:619) 
      Caused by: java.lang.OutOfMemoryError: Java heap space 
      at java.util.Arrays.copyOf(Arrays.java:2786) 
      at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94) 
      at org.springframework.util.FileCopyUtils.copy(FileCopyUtils.java:113) 
      at org.springframework.http.converter.ResourceHttpMessageConverter.write(ResourceHttpMessageConverter.java:85) 
      at org.springframework.http.converter.ResourceHttpMessageConverter.write(ResourceHttpMessageConverter.java:1) 
      at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:288) 
      at org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:252) 
      at org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:242) 
      at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:194) 
      at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:1) 
      at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:588) 
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:436) 
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401) 
      at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:279) 
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
      at java.lang.reflect.Method.invoke(Method.java:597) 
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
      at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50) 
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
      at $Proxy17.postForObject(Unknown Source)

        Issue Links

          Activity

          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open In Progress In Progress
          28s 1 Arjen Poutsma 25/Jan/11 7:25 AM
          In Progress In Progress Resolved Resolved
          43m 15s 1 Arjen Poutsma 25/Jan/11 8:08 AM
          Resolved Resolved Closed Closed
          510d 19h 31m 1 Chris Beams 19/Jun/12 3:39 AM

            People

            • Assignee:
              arjen.poutsma Arjen Poutsma
              Reporter:
              arjen.poutsma Arjen Poutsma
              Last updater:
              Serge P. Nekoval
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 2 days ago

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 2d
                2d