Spring MVC (tested with 3.0.4 and 2.5.6) automatically appends charset to Content-Type headers in HTTP responses, including responses with Content-Type application/*, e.g. application/java-archive. This causes issues for certain consuming clients.
Raw servlets in Tomcat do not act in this way and a charset is not appended with raw servlets in Tomcat if the Content-Type is of type application/*.
The code I used to test a Raw servlet is below:
The response headers from the Raw tomcat servlet using the linux command:Code:public class TestServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("application/java-archive"); res.setContentLength(2); res.getOutputStream().write(new byte[]{0x01,0x02}); } }
wget --save-headers http://localhost:8080/testservlet/TestServlet
is:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/java-archive
Content-Length: 2
Date: Tue, 21 Sep 2010 12:29:31 GMT
Connection: keep-alive
The code for the spring view is below:
The response headers from the Spring controller using the linux command:Code:public class TestSpringView extends AbstractView{ @Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest req, HttpServletResponse res) throws Exception { res.setContentType("application/java-archive"); res.setContentLength(2); res.getOutputStream().write(new byte[]{0x01,0x02}); } }
wget --save-headers http://localhost:8080/testservlet/d/d/spring
is:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/java-archive;charset=ISO-8859-1
Content-Language: en-ZA
Content-Length: 2
Date: Tue, 21 Sep 2010 12:31:11 GMT
Connection: keep-alive
Note that the response from the spring controller automatically appends a default charset to the Content-Type header. How do I prevent this?
I have created a complete project with all source/libs/ant build scripts that demonstrates the issue at:
https://docs.google.com/fileview?id=...0ODJj&hl=en_GB


Reply With Quote