I have an app with Spring MVC 3.1.3 and the UI developed with Dojo 1.4. The application has few controllers which handle binary files uploaded through dojo.io.iframe.send. The controller sends a json response which has to be surrounded with
<html><body><textarea>{my json response}</textarea></body></html>.
I’ve implemented a custom filter defined in web.xml:
<filter>
<filter-name>dojoIframeFilter</filter-name>
<filter-class>com.app.web.MultipartAjaxFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>dojoIframeFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
The filter’s doFilter has this behaviour, taken from http://www.oracle.com/technetwork/java/filters-137243.html
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (request.getContentType() != null
&& request.getContentType().contains("multipart/form-data")) {
CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response);
chain.doFilter(request, wrapper);
log.info(wrapper.toString());
//Modify response here
}
else {
chain.doFilter(request, response);
}
}
The wrapper’s output is empty. I’ve also tried many other combinations such as placing the custom filter for spring’s dispatcher servlet, doing away with the if block inside doFilter none of which works. I also tried writing a Spring interceptor which also failed. Could anybody please suggest any other idea ?
Thanks in advance.
UPDATE: I disabled spring security and tested with plain spring mvc but the problem remains. I have modified the title and the question description.
Friends, we need to subclass ServletOutputStream also in addition to in order to successfully modify the ServletResponse. Please see http://docstore.mik.ua/orelly/xml/jxslt/ch08_04.htm for a detailed solution.