I am using Spring 3.1.3 and and am wanting to return XML from my controller. I have my method in my controller annotated as such.
The String that is returned is not part of a JAXB object and is constructed dynamically. I wanted the response Content-Type to be "application/xml" so that the browser would display it as such. From debugging with firebug, the content type is set to "text/html" I then implemented a class that extended HandlerInterceptorAdapter and tried overriding preHandle (), postHandle (), and afterCompletion () to set:
@RequestMapping (value = "/dumpData", method = RequestMethod.GET, produces="application/xml")
public String dumpDataInXML (HttpServletResponse response) throws TransformerException
// implementation details left out...
// NOTE: my XML that is created starts with <?xml version="1.0" encoding="UTF-8"?>
I see my from my log all 3 methods were called, but the from firebug, the Content-Type is still "text/html" and to me it's as if setting the response header and content type were not honored or doesn't take affect. Anyone know what I am doing wrong?
response.setHeader ("content-type", "application/xhtml+xml");