类 MockHttpServletResponse

java.lang.Object
cn.taketoday.mock.web.MockHttpServletResponse
所有已实现的接口:
jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletResponse

public class MockHttpServletResponse extends Object implements jakarta.servlet.http.HttpServletResponse
Mock implementation of the HttpServletResponse interface.

this set of mocks is designed on a Servlet 4.0 baseline.

从以下版本开始:
4.0
作者:
Juergen Hoeller, Rod Johnson, Brian Clozel, Vedran Pavic, Sebastien Deleuze, Sam Brannen
  • 字段详细资料

    • CHARSET_PREFIX

      private static final String CHARSET_PREFIX
      另请参阅:
    • DATE_FORMAT

      private static final String DATE_FORMAT
      另请参阅:
    • GMT

      private static final TimeZone GMT
    • outputStreamAccessAllowed

      private boolean outputStreamAccessAllowed
    • writerAccessAllowed

      private boolean writerAccessAllowed
    • defaultCharacterEncoding

      private String defaultCharacterEncoding
    • characterEncoding

      private String characterEncoding
    • characterEncodingSet

      private boolean characterEncodingSet
      true if the character encoding has been explicitly set through HttpServletResponse methods or through a charset parameter on the Content-Type.
    • content

      private final ByteArrayOutputStream content
    • outputStream

      private final jakarta.servlet.ServletOutputStream outputStream
    • writer

      @Nullable private PrintWriter writer
    • contentLength

      private long contentLength
    • contentType

      @Nullable private String contentType
    • bufferSize

      private int bufferSize
    • committed

      private boolean committed
    • locale

      private Locale locale
    • cookies

      private final List<jakarta.servlet.http.Cookie> cookies
    • headers

      private final Map<String,HeaderValueHolder> headers
    • status

      private int status
    • errorMessage

      @Nullable private String errorMessage
    • forwardedUrl

      @Nullable private String forwardedUrl
    • includedUrls

      private final List<String> includedUrls
  • 构造器详细资料

    • MockHttpServletResponse

      public MockHttpServletResponse()
  • 方法详细资料

    • setOutputStreamAccessAllowed

      public void setOutputStreamAccessAllowed(boolean outputStreamAccessAllowed)
      Set whether getOutputStream() access is allowed.

      Default is true.

    • isOutputStreamAccessAllowed

      public boolean isOutputStreamAccessAllowed()
      Return whether getOutputStream() access is allowed.
    • setWriterAccessAllowed

      public void setWriterAccessAllowed(boolean writerAccessAllowed)
      Set whether getWriter() access is allowed.

      Default is true.

    • isWriterAccessAllowed

      public boolean isWriterAccessAllowed()
      Return whether getOutputStream() access is allowed.
    • setDefaultCharacterEncoding

      public void setDefaultCharacterEncoding(String characterEncoding)
      Set the default character encoding for the response.

      If this method is not invoked, ISO-8859-1 will be used as the default character encoding.

      If the character encoding for the response has not already been explicitly set via setCharacterEncoding(String) or setContentType(String), the character encoding for the response will be set to the supplied default character encoding.

      参数:
      characterEncoding - the default character encoding
      另请参阅:
    • isCharset

      public boolean isCharset()
      Determine whether the character encoding has been explicitly set through HttpServletResponse methods or through a charset parameter on the Content-Type.

      If false, getCharacterEncoding() will return the default character encoding.

    • setCharacterEncoding

      public void setCharacterEncoding(@Nullable String characterEncoding)
      指定者:
      setCharacterEncoding 在接口中 jakarta.servlet.ServletResponse
    • setExplicitCharacterEncoding

      private void setExplicitCharacterEncoding(@Nullable String characterEncoding)
    • updateContentTypePropertyAndHeader

      private void updateContentTypePropertyAndHeader()
    • getCharacterEncoding

      public String getCharacterEncoding()
      指定者:
      getCharacterEncoding 在接口中 jakarta.servlet.ServletResponse
    • getOutputStream

      public jakarta.servlet.ServletOutputStream getOutputStream()
      指定者:
      getOutputStream 在接口中 jakarta.servlet.ServletResponse
    • getWriter

      public PrintWriter getWriter() throws UnsupportedEncodingException
      指定者:
      getWriter 在接口中 jakarta.servlet.ServletResponse
      抛出:
      UnsupportedEncodingException
    • getContentAsByteArray

      public byte[] getContentAsByteArray()
    • getContentAsString

      public String getContentAsString() throws UnsupportedEncodingException
      Get the content of the response body as a String, using the charset specified for the response by the application, either through HttpServletResponse methods or through a charset parameter on the Content-Type. If no charset has been explicitly defined, the default character encoding will be used.
      返回:
      the content as a String
      抛出:
      UnsupportedEncodingException - if the character encoding is not supported
      另请参阅:
    • getContentAsString

      public String getContentAsString(Charset fallbackCharset) throws UnsupportedEncodingException
      Get the content of the response body as a String, using the provided fallbackCharset if no charset has been explicitly defined and otherwise using the charset specified for the response by the application, either through HttpServletResponse methods or through a charset parameter on the Content-Type.
      返回:
      the content as a String
      抛出:
      UnsupportedEncodingException - if the character encoding is not supported
      另请参阅:
    • setContentLength

      public void setContentLength(int contentLength)
      指定者:
      setContentLength 在接口中 jakarta.servlet.ServletResponse
    • getContentLength

      public int getContentLength()
    • setContentLengthLong

      public void setContentLengthLong(long contentLength)
      指定者:
      setContentLengthLong 在接口中 jakarta.servlet.ServletResponse
    • getContentLengthLong

      public long getContentLengthLong()
    • setContentType

      public void setContentType(@Nullable String contentType)
      指定者:
      setContentType 在接口中 jakarta.servlet.ServletResponse
    • getContentType

      @Nullable public String getContentType()
      指定者:
      getContentType 在接口中 jakarta.servlet.ServletResponse
    • setBufferSize

      public void setBufferSize(int bufferSize)
      指定者:
      setBufferSize 在接口中 jakarta.servlet.ServletResponse
    • getBufferSize

      public int getBufferSize()
      指定者:
      getBufferSize 在接口中 jakarta.servlet.ServletResponse
    • flushBuffer

      public void flushBuffer()
      指定者:
      flushBuffer 在接口中 jakarta.servlet.ServletResponse
    • resetBuffer

      public void resetBuffer()
      指定者:
      resetBuffer 在接口中 jakarta.servlet.ServletResponse
    • setCommittedIfBufferSizeExceeded

      private void setCommittedIfBufferSizeExceeded()
    • setCommitted

      public void setCommitted(boolean committed)
    • isCommitted

      public boolean isCommitted()
      指定者:
      isCommitted 在接口中 jakarta.servlet.ServletResponse
    • reset

      public void reset()
      指定者:
      reset 在接口中 jakarta.servlet.ServletResponse
    • setLocale

      public void setLocale(@Nullable Locale locale)
      指定者:
      setLocale 在接口中 jakarta.servlet.ServletResponse
    • getLocale

      public Locale getLocale()
      指定者:
      getLocale 在接口中 jakarta.servlet.ServletResponse
    • addCookie

      public void addCookie(jakarta.servlet.http.Cookie cookie)
      指定者:
      addCookie 在接口中 jakarta.servlet.http.HttpServletResponse
    • getCookieHeader

      private String getCookieHeader(jakarta.servlet.http.Cookie cookie)
    • getCookies

      public jakarta.servlet.http.Cookie[] getCookies()
    • getCookie

      @Nullable public jakarta.servlet.http.Cookie getCookie(String name)
    • containsHeader

      public boolean containsHeader(String name)
      指定者:
      containsHeader 在接口中 jakarta.servlet.http.HttpServletResponse
    • getHeaderNames

      public Collection<String> getHeaderNames()
      Return the names of all specified headers as a Set of Strings.

      As of Servlet 3.0, this method is also defined in HttpServletResponse.

      指定者:
      getHeaderNames 在接口中 jakarta.servlet.http.HttpServletResponse
      返回:
      the Set of header name Strings, or an empty Set if none
    • getHeader

      @Nullable public String getHeader(String name)
      Return the primary value for the given header as a String, if any. Will return the first value in case of multiple values.

      As of Servlet 3.0, this method is also defined in HttpServletResponse. it returns a stringified value for Servlet 3.0 compatibility. Consider using getHeaderValue(String) for raw Object access.

      指定者:
      getHeader 在接口中 jakarta.servlet.http.HttpServletResponse
      参数:
      name - the name of the header
      返回:
      the associated header value, or null if none
    • getHeaders

      public List<String> getHeaders(String name)
      Return all values for the given header as a List of Strings.

      As of Servlet 3.0, this method is also defined in HttpServletResponse. it returns a List of stringified values for Servlet 3.0 compatibility. Consider using getHeaderValues(String) for raw Object access.

      指定者:
      getHeaders 在接口中 jakarta.servlet.http.HttpServletResponse
      参数:
      name - the name of the header
      返回:
      the associated header values, or an empty List if none
    • getHeaderValue

      @Nullable public Object getHeaderValue(String name)
      Return the primary value for the given header, if any.

      Will return the first value in case of multiple values.

      参数:
      name - the name of the header
      返回:
      the associated header value, or null if none
    • getHeaderValues

      public List<Object> getHeaderValues(String name)
      Return all values for the given header as a List of value objects.
      参数:
      name - the name of the header
      返回:
      the associated header values, or an empty List if none
    • encodeURL

      public String encodeURL(String url)
      The default implementation returns the given URL String as-is.

      Can be overridden in subclasses, appending a session id or the like.

      指定者:
      encodeURL 在接口中 jakarta.servlet.http.HttpServletResponse
    • encodeRedirectURL

      public String encodeRedirectURL(String url)
      The default implementation delegates to encodeURL(java.lang.String), returning the given URL String as-is.

      Can be overridden in subclasses, appending a session id or the like in a redirect-specific fashion. For general URL encoding rules, override the common encodeURL(java.lang.String) method instead, applying to redirect URLs as well as to general URLs.

      指定者:
      encodeRedirectURL 在接口中 jakarta.servlet.http.HttpServletResponse
    • sendError

      public void sendError(int status, String errorMessage) throws IOException
      指定者:
      sendError 在接口中 jakarta.servlet.http.HttpServletResponse
      抛出:
      IOException
    • sendError

      public void sendError(int status) throws IOException
      指定者:
      sendError 在接口中 jakarta.servlet.http.HttpServletResponse
      抛出:
      IOException
    • sendRedirect

      public void sendRedirect(String url) throws IOException
      指定者:
      sendRedirect 在接口中 jakarta.servlet.http.HttpServletResponse
      抛出:
      IOException
    • getRedirectedUrl

      @Nullable public String getRedirectedUrl()
    • setDateHeader

      public void setDateHeader(String name, long value)
      指定者:
      setDateHeader 在接口中 jakarta.servlet.http.HttpServletResponse
    • addDateHeader

      public void addDateHeader(String name, long value)
      指定者:
      addDateHeader 在接口中 jakarta.servlet.http.HttpServletResponse
    • getDateHeader

      public long getDateHeader(String name)
    • formatDate

      private String formatDate(long date)
    • newDateFormat

      private DateFormat newDateFormat()
    • setHeader

      public void setHeader(String name, @Nullable String value)
      指定者:
      setHeader 在接口中 jakarta.servlet.http.HttpServletResponse
    • addHeader

      public void addHeader(String name, @Nullable String value)
      指定者:
      addHeader 在接口中 jakarta.servlet.http.HttpServletResponse
    • setIntHeader

      public void setIntHeader(String name, int value)
      指定者:
      setIntHeader 在接口中 jakarta.servlet.http.HttpServletResponse
    • addIntHeader

      public void addIntHeader(String name, int value)
      指定者:
      addIntHeader 在接口中 jakarta.servlet.http.HttpServletResponse
    • setHeaderValue

      private void setHeaderValue(String name, @Nullable Object value)
    • addHeaderValue

      private void addHeaderValue(String name, @Nullable Object value)
    • setSpecialHeader

      private boolean setSpecialHeader(String name, Object value, boolean replaceHeader)
    • doAddHeaderValue

      private void doAddHeaderValue(String name, Object value, boolean replace)
    • setCookie

      private void setCookie(jakarta.servlet.http.Cookie cookie)
      Set the Set-Cookie header to the supplied Cookie, overwriting any previous cookies.
      参数:
      cookie - the Cookie to set
      另请参阅:
    • setStatus

      public void setStatus(int status)
      指定者:
      setStatus 在接口中 jakarta.servlet.http.HttpServletResponse
    • getStatus

      public int getStatus()
      指定者:
      getStatus 在接口中 jakarta.servlet.http.HttpServletResponse
    • getErrorMessage

      @Nullable public String getErrorMessage()
    • setForwardedUrl

      public void setForwardedUrl(@Nullable String forwardedUrl)
    • getForwardedUrl

      @Nullable public String getForwardedUrl()
    • setIncludedUrl

      public void setIncludedUrl(@Nullable String includedUrl)
    • getIncludedUrl

      @Nullable public String getIncludedUrl()
    • addIncludedUrl

      public void addIncludedUrl(String includedUrl)
    • getIncludedUrls

      public List<String> getIncludedUrls()