2

I have a bunch of web services that return some content, sometimes > 100kb. Unfortunately for the bigger results, I get the partial response with Transfer-encoding: Chunked.

Is there any way to disable chunking?

That's my method:

@RequestMapping(value = "/form/{repository}/{objectId}", method = RequestMethod.GET, headers="()")
@ResponseBody
public FormHelper getFormConfig(HttpServletRequest req, HttpServletResponse resp, @PathVariable String repository,
        @PathVariable("objectId") String objectId) throws Exception

And that's the Spring XML config:

<import resource="classpath*:context-aaa.xml" />

<mvc:annotation-driven />

<bean
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="useDefaultSuffixPattern" value="false" />
</bean>

I had the same issue with Jersey library so I rewrote the project into Spring MVC, but it's still there...

Thanks in advance for any help. Mariusz

Mariusz Pala
  • 961
  • 1
  • 8
  • 17
  • Looks like JSON result contains the Content-length attribute and the result is not chunked. XML is returned chunked and thus I reported a bug: https://jira.spring.io/browse/SPR-11948 – Mariusz Pala Jul 04 '14 at 06:56
  • This might help: http://stackoverflow.com/questions/6299432/how-do-disable-transfer-encoding-in-tomcat-6 – CodeChimp Jul 04 '14 at 11:21
  • This answer points out that Content-length header is the only option to disable chunked transfer. I knew that already, unfortunately with spring I'm not able to controll such headers, so I reported that issue to the Spring team. – Mariusz Pala Jul 04 '14 at 11:29
  • Why can you not set the Content-Length? According to this JIRA it's possible on the MappingJacksonJsonView as of Spring 3.0.5: https://jira.spring.io/browse/SPR-7866 – CodeChimp Jul 04 '14 at 11:38
  • For JSON is it fixes and it's correctly setup now, but not for XML. – Mariusz Pala Jul 04 '14 at 14:45
  • Instead of using `@ResponseBody`, you could instead simply get an OutputStream from the HttpResponse and write out the XML with whatever content length you want. – CodeChimp Jul 04 '14 at 19:11
  • I know, but that means that I'd have to serialize the response to XML or JSON manually for every response, instead of using built-in functionality. – Mariusz Pala Jul 07 '14 at 07:03
  • You may not have a choice. – CodeChimp Jul 07 '14 at 11:26

1 Answers1

3

I was able to make that work by adding the filter below:

<filter>
    <filter-name>bufferFilter</filter-name>
    <filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>bufferFilter</filter-name>
    <url-pattern>/services/*</url-pattern>
</filter-mapping>

https://jira.spring.io/browse/SPR-11948

Mariusz Pala
  • 961
  • 1
  • 8
  • 17