title: java.lang.IllegalStateException: getReader() has already been called for this request
body: <p>I want to add logging to my Servlet, so I've created Filter which should display request and go to the Servlet. But unfortunately I've encoutered exception:</p>
  
  <pre><code>java.lang.IllegalStateException: getReader() has already been called for this request
      at org.apache.catalina.connector.Request.getInputStream(Request.java:948)
      at org.apache.catalina.connector.RequestFacade.getInputStream(RequestFacade.java:338)
      at com.noelios.restlet.ext.servlet.ServletCall.getRequestEntityStream(ServletCall.java:190)
  </code></pre>
  
  <p>So to fix this problem I've found solution with Wrapper, but it doesn't work. What else can I use/change in code? Any ideas?</p>
  
  <p>[MyHttpServletRequestWrapper]</p>
  
  <pre><code>public class MyHttpServletRequestWrapper extends HttpServletRequestWrapper
  {
      public MyHttpServletRequestWrapper(HttpServletRequest request)
      {
          super(request);
      }
  
      private String getBodyAsString()
      {
          StringBuffer buff = new StringBuffer();
          buff.append(" BODY_DATA START [ ");
          char[] charArr = new char[getContentLength()];
          try
          {
              BufferedReader reader = new BufferedReader(getReader());
              reader.read(charArr, 0, charArr.length);
              reader.close();
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
          buff.append(charArr);
          buff.append(" ] BODY_DATA END ");
          return buff.toString();
      }
  
      public String toString()
      {
          return getBodyAsString();
      }
  }
  </code></pre>
  
  <p>[MyFilter]</p>
  
  <pre><code>public class MyFilterimplements Filter
  {
      @Override
      public void init(FilterConfig filterConfig) throws ServletException
      {
      }
  
      @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
      {
          final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
          final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
  
          final HttpServletRequestWrapper requestWrapper = new MyHttpServletRequestWrapper(httpServletRequest);
          final String requestBody = requestWrapper.toString();
  
          chain.doFilter(request, response);
      }
  }
  </code></pre>