3 Replies Latest reply on May 5, 2014 4:47 AM by ctomc

    Empty response body in a custom 404 page going through a custom HttpServletResponseWrapper

    alexislaporte

      Hello everyone,

       

      I have a weird one with WildFly. We just upgraded our servers from JBoss 7, everything went quite right.

       

      Except our 404 pages are now empty (blank), even though the custom servlet is accessed (the code is run, we even have our own HTTP headers set in the page).

       

      I tracked the bug, I suspected our servlet filters. I came to see it was a filter that creates a custom HttpServletResponseWrapper and sends it to the chain. It's very classic:


      CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response);
      chain.doFilter(request, wrapper);
      
      String html = wrapper.toString();
      
        // business logic on html
      
      PrintWriter out = response.getWriter();
      out.write(html);
      out.close();
      


      CharResponseWrapper being very simple


      public class CharResponseWrapper extends HttpServletResponseWrapper {
        private CharArrayWriter output;
      
      
        public CharResponseWrapper(HttpServletResponse response) {
        super(response);
        this.output = new CharArrayWriter();
        }
      
      
        public String toString() {
        return output.toString();
        }
      

       

      It works fine, the variable html we get from the 'wrapper' is always set, even for my 404. But when we pass it to the real response writer it gets lost only for 404. In comparison, 500 custom pages work well (their code is quite the same than our 404).


      I think the underlying machine (Undertow?) might not be using the response writer for 404, which might explain why I get nothing in the response body. As far I as know of JBoss and JEE that's what I can think of.

       

      Besides, I must tell that everything was accessed through Apache, using a custom (local) domain name (such as http://my-website.local). So I tried to access the pages using http://localhost:8080/project-root/ -which is uncommon and might generate errors. And

      1. site kind of worked (except for errors due to this uncommon domain name - that's to be expected)
      2. 500 errors did not go to my custom pages at all, it merely printed a page titled 'ERROR' with a message 'Error processing request' and the stacktrace
      3. 404 still went to the custom servlet, and diplayed nothing

       

      Any thoughts?

       

      Thanks for your help,

       

      Alexis.