Class CapturingResponseWrapper

java.lang.Object
jakarta.servlet.ServletResponseWrapper
jakarta.servlet.http.HttpServletResponseWrapper
com.atlassian.jira.util.http.response.CapturingResponseWrapper
All Implemented Interfaces:
jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletResponse

public class CapturingResponseWrapper extends jakarta.servlet.http.HttpServletResponseWrapper
This HttpServletResponseWrapper can capture an initial amount of response data and the headers/cookies that may be set on the response.

THREAD SAFETY - One of these must be constructed on each HTTP request/response and hence only one thread may write to it at the one time. This suits the whole servlet engine idea,

Since:
v3.13.2
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    This class represent the HTTP headers that have been output to this ResponseWrapper
  • Field Summary

    Fields inherited from interface jakarta.servlet.http.HttpServletResponse

    SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
  • Constructor Summary

    Constructors
    Constructor
    Description
    CapturingResponseWrapper(jakarta.servlet.http.HttpServletResponse httpServletResponse, int maxCaptureLen)
    This will wrap the HttpServletResponse and capture up to maxCaptureLen of the response output.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addCookie(jakarta.servlet.http.Cookie cookie)
    Overridden to capture cookie information.
    void
    addDateHeader(String s, long l)
    Overridden to capture HTTP header information
    void
    Overridden to capture HTTP header information
    void
    addIntHeader(String s, int i)
     
    byte[]
    This returns the bytes that have been captured on the ResponseWrapper.
    This returns a list of all the Cookie's that have been set on this response
    This returns a list of all the CapturingResponseWrapper.HttpHeader's that have been set on this response
    jakarta.servlet.ServletOutputStream
     
     
    void
    setDateHeader(String s, long l)
    Overridden to capture HTTP header information
    void
    Overridden to capture HTTP header information
    void
    setIntHeader(String s, int i)
    Overridden to capture HTTP header information
    int
    This returns the number of bytes that have been captured so far.

    Methods inherited from class jakarta.servlet.http.HttpServletResponseWrapper

    containsHeader, encodeRedirectURL, encodeURL, getHeader, getHeaderNames, getHeaders, getStatus, getTrailerFields, sendError, sendError, sendRedirect, setStatus, setTrailerFields

    Methods inherited from class jakarta.servlet.ServletResponseWrapper

    flushBuffer, getBufferSize, getCharacterEncoding, getContentType, getLocale, getResponse, isCommitted, isWrapperFor, isWrapperFor, reset, resetBuffer, setBufferSize, setCharacterEncoding, setContentLength, setContentLengthLong, setContentType, setLocale, setResponse

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface jakarta.servlet.ServletResponse

    flushBuffer, getBufferSize, getCharacterEncoding, getContentType, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setContentLength, setContentLengthLong, setContentType, setLocale
  • Constructor Details

    • CapturingResponseWrapper

      public CapturingResponseWrapper(jakarta.servlet.http.HttpServletResponse httpServletResponse, int maxCaptureLen)
      This will wrap the HttpServletResponse and capture up to maxCaptureLen of the response output.
      Parameters:
      httpServletResponse - the servlet response
      maxCaptureLen - the maximum number of bytes to capture
  • Method Details

    • getBytes

      public byte[] getBytes()
      This returns the bytes that have been captured on the ResponseWrapper.
      Returns:
      the bytes that have been captured on the ResponseWrapper
    • size

      public int size()
      This returns the number of bytes that have been captured so far.
      Returns:
      the the number of bytes that have been captured so far.
    • getCookieList

      public List getCookieList()
      This returns a list of all the Cookie's that have been set on this response
      Returns:
      a list of all the Cookie's that have been set on this response
    • getHeaderList

      public List getHeaderList()
      This returns a list of all the CapturingResponseWrapper.HttpHeader's that have been set on this response
      Returns:
      a list of all the CapturingResponseWrapper.HttpHeader's that have been set on this response
    • addCookie

      public void addCookie(jakarta.servlet.http.Cookie cookie)
      Overridden to capture cookie information.
      Specified by:
      addCookie in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      addCookie in class jakarta.servlet.http.HttpServletResponseWrapper
    • setDateHeader

      public void setDateHeader(String s, long l)
      Overridden to capture HTTP header information
      Specified by:
      setDateHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      setDateHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • addDateHeader

      public void addDateHeader(String s, long l)
      Overridden to capture HTTP header information
      Specified by:
      addDateHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      addDateHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • setHeader

      public void setHeader(String s, String s1)
      Overridden to capture HTTP header information
      Specified by:
      setHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      setHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • addHeader

      public void addHeader(String s, String s1)
      Overridden to capture HTTP header information
      Specified by:
      addHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      addHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • setIntHeader

      public void setIntHeader(String s, int i)
      Overridden to capture HTTP header information
      Specified by:
      setIntHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      setIntHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • addIntHeader

      public void addIntHeader(String s, int i)
      Specified by:
      addIntHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      addIntHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • getWriter

      public PrintWriter getWriter() throws IOException
      Specified by:
      getWriter in interface jakarta.servlet.ServletResponse
      Overrides:
      getWriter in class jakarta.servlet.ServletResponseWrapper
      Throws:
      IOException
    • getOutputStream

      public jakarta.servlet.ServletOutputStream getOutputStream() throws IOException
      Specified by:
      getOutputStream in interface jakarta.servlet.ServletResponse
      Overrides:
      getOutputStream in class jakarta.servlet.ServletResponseWrapper
      Throws:
      IOException