title: How to get Response Body from servletResponse in Spring Boot Filter
body: <p>I want to get <code>Response Body</code> from <code>ServletResponse</code> to make a hash signature from it before passing to the client. I couldn't get the way to do it. For getting the request body from <code>ServletRequest</code>  I have implemented like the following:</p>
  <pre><code>import java.io.BufferedReader;
  import java.io.ByteArrayInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  
  import javax.servlet.ReadListener;
  import javax.servlet.ServletInputStream;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletRequestWrapper;
  
  public class RequestWrapper extends HttpServletRequestWrapper{
  
      private final String body;
       
      public RequestWrapper(HttpServletRequest request) throws IOException 
      {
          //So that other request method behave just like before
          super(request);
           
          StringBuilder stringBuilder = new StringBuilder();
          BufferedReader bufferedReader = null;
          try {
              InputStream inputStream = request.getInputStream();
              if (inputStream != null) {
                  bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                  char[] charBuffer = new char[128];
                  int bytesRead = -1;
                  while ((bytesRead = bufferedReader.read(charBuffer)) &gt; 0) {
                      stringBuilder.append(charBuffer, 0, bytesRead);
                  }
              } else {
                  stringBuilder.append(&quot;&quot;);
              }
          } catch (IOException ex) {
              throw ex;
          } finally {
              if (bufferedReader != null) {
                  try {
                      bufferedReader.close();
                  } catch (IOException ex) {
                      throw ex;
                  }
              }
          }
          //Store request pody content in 'body' variable 
          body = stringBuilder.toString();
      }
   
      @Override
      public ServletInputStream getInputStream() throws IOException {
          final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
          ServletInputStream servletInputStream = new ServletInputStream() {
              public int read() throws IOException {
                  return byteArrayInputStream.read();
              }
  
              @Override
              public boolean isFinished() {
  
                  return false;
              }
  
              @Override
              public boolean isReady() {
  
                  return false;
              }
  
              @Override
              public void setReadListener(ReadListener listener) {
  
                  
              }
          };
          return servletInputStream;
      }
   
      @Override
      public BufferedReader getReader() throws IOException {
          return new BufferedReader(new InputStreamReader(this.getInputStream()));
      }
   
      //Use this method to read the request body N times
      public String getBody() {
          return this.body;
      }
  }
  </code></pre>
  <p>How can I do similar to <code>ServletResponse</code>?</p>