title: Servlet filter wrapper - trouble changing content type
body: <p>I have RESTful web service which is consumed by javascript.  This service returns a content type of "application/json".  However, for IE the content type must be "text/html".  So I written a filter and wrapper to change the content type when IE is detected as the client.  My logic seems to have no effect on the content type.  What am I doing wrong?</p>
  
  <p>The filter:</p>
  
  <pre><code>public class IE8Filter implements Filter {
  
      private Logger logger = LoggerHelper.getLogger();
  
      @Override
      public void destroy() {}
  
      @Override
      public void doFilter(ServletRequest req, ServletResponse res,
              FilterChain chain) throws IOException, ServletException {
  
           HttpServletRequest request = (HttpServletRequest) req;
           HttpServletResponse response = (HttpServletResponse) res;
  
           String userAgent = request.getHeader("User-Agent");
           logger.debugf("User Agent  = '%s'", userAgent);
  
           IE8FilterResponseWrapper wrapper = new IE8FilterResponseWrapper(response);
  
  
  
           chain.doFilter(req, wrapper);
  
  
           if (userAgent.contains("MSIE 8") || userAgent.contains("MSIE 7")) {
  
               wrapper.setContentType("text/html");
               logger.debugf("Content Type  = '%s'", wrapper.getContentType());
           }
  
  
      }
  
      @Override
      public void init(FilterConfig arg0) throws ServletException {}
  
  }
  </code></pre>
  
  <p>The wrapper:</p>
  
  <pre><code>public class IE8FilterResponseWrapper extends HttpServletResponseWrapper {
  
  
      private String contentType;
  
      public IE8FilterResponseWrapper(HttpServletResponse response) {
          super(response);
      }
  
      public void setContentType(String type) { 
          this.contentType = type;
          super.setContentType(type); 
      } 
  
       public String getContentType() { 
           return contentType; 
       } 
  }
  </code></pre>