类 MockHttpServletResponse
- 所有已实现的接口:
jakarta.servlet.http.HttpServletResponse,jakarta.servlet.ServletResponse
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
-
嵌套类概要
嵌套类修饰符和类型类说明private classInner class that adapts the PrintWriter to mark the response as committed once the buffer size is exceeded.private classInner class that adapts the ServletOutputStream to mark the response as committed once the buffer size is exceeded. -
字段概要
字段修饰符和类型字段说明private intprivate Stringprivate booleantrueif the character encoding has been explicitly set throughHttpServletResponsemethods or through acharsetparameter on theContent-Type.private static final Stringprivate booleanprivate final ByteArrayOutputStreamprivate longprivate Stringprivate final List<jakarta.servlet.http.Cookie>private static final Stringprivate Stringprivate Stringprivate Stringprivate static final TimeZoneprivate final Map<String,HeaderValueHolder> private Localeprivate final jakarta.servlet.ServletOutputStreamprivate booleanprivate intprivate PrintWriterprivate boolean从接口继承的字段 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 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidaddCookie(jakarta.servlet.http.Cookie cookie) voidaddDateHeader(String name, long value) voidprivate voidaddHeaderValue(String name, Object value) voidaddIncludedUrl(String includedUrl) voidaddIntHeader(String name, int value) booleancontainsHeader(String name) private voiddoAddHeaderValue(String name, Object value, boolean replace) encodeRedirectURL(String url) The default implementation delegates toencodeURL(java.lang.String), returning the given URL String as-is.The default implementation returns the given URL String as-is.voidprivate StringformatDate(long date) intbyte[]Get the content of the response body as aString, using the charset specified for the response by the application, either throughHttpServletResponsemethods or through a charset parameter on theContent-Type.getContentAsString(Charset fallbackCharset) Get the content of the response body as aString, using the providedfallbackCharsetif no charset has been explicitly defined and otherwise using the charset specified for the response by the application, either throughHttpServletResponsemethods or through a charset parameter on theContent-Type.intlongjakarta.servlet.http.Cookieprivate StringgetCookieHeader(jakarta.servlet.http.Cookie cookie) jakarta.servlet.http.Cookie[]longgetDateHeader(String name) Return the primary value for the given header as a String, if any.Return the names of all specified headers as a Set of Strings.getHeaders(String name) Return all values for the given header as a List of Strings.getHeaderValue(String name) Return the primary value for the given header, if any.getHeaderValues(String name) Return all values for the given header as a List of value objects.jakarta.servlet.ServletOutputStreamintbooleanDetermine whether the character encoding has been explicitly set throughHttpServletResponsemethods or through acharsetparameter on theContent-Type.booleanbooleanReturn whethergetOutputStream()access is allowed.booleanReturn whethergetOutputStream()access is allowed.private DateFormatvoidreset()voidvoidsendError(int status) voidvoidsendRedirect(String url) voidsetBufferSize(int bufferSize) voidsetCharacterEncoding(String characterEncoding) voidsetCommitted(boolean committed) private voidvoidsetContentLength(int contentLength) voidsetContentLengthLong(long contentLength) voidsetContentType(String contentType) private voidsetCookie(jakarta.servlet.http.Cookie cookie) Set theSet-Cookieheader to the suppliedCookie, overwriting any previous cookies.voidsetDateHeader(String name, long value) voidsetDefaultCharacterEncoding(String characterEncoding) Set the default character encoding for the response.private voidsetExplicitCharacterEncoding(String characterEncoding) voidsetForwardedUrl(String forwardedUrl) voidprivate voidsetHeaderValue(String name, Object value) voidsetIncludedUrl(String includedUrl) voidsetIntHeader(String name, int value) voidvoidsetOutputStreamAccessAllowed(boolean outputStreamAccessAllowed) Set whethergetOutputStream()access is allowed.private booleansetSpecialHeader(String name, Object value, boolean replaceHeader) voidsetStatus(int status) voidsetWriterAccessAllowed(boolean writerAccessAllowed) Set whethergetWriter()access is allowed.private void从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 jakarta.servlet.http.HttpServletResponse
getTrailerFields, setTrailerFields
-
字段详细资料
-
CHARSET_PREFIX
- 另请参阅:
-
DATE_FORMAT
- 另请参阅:
-
GMT
-
outputStreamAccessAllowed
private boolean outputStreamAccessAllowed -
writerAccessAllowed
private boolean writerAccessAllowed -
defaultCharacterEncoding
-
characterEncoding
-
characterEncodingSet
private boolean characterEncodingSettrueif the character encoding has been explicitly set throughHttpServletResponsemethods or through acharsetparameter on theContent-Type. -
-
outputStream
private final jakarta.servlet.ServletOutputStream outputStream -
writer
-
contentLength
private long contentLength -
contentType
-
bufferSize
private int bufferSize -
committed
private boolean committed -
locale
-
cookies
-
headers
-
status
private int status -
errorMessage
-
forwardedUrl
-
includedUrls
-
-
构造器详细资料
-
MockHttpServletResponse
public MockHttpServletResponse()
-
-
方法详细资料
-
setOutputStreamAccessAllowed
public void setOutputStreamAccessAllowed(boolean outputStreamAccessAllowed) Set whethergetOutputStream()access is allowed.Default is
true. -
isOutputStreamAccessAllowed
public boolean isOutputStreamAccessAllowed()Return whethergetOutputStream()access is allowed. -
setWriterAccessAllowed
public void setWriterAccessAllowed(boolean writerAccessAllowed) Set whethergetWriter()access is allowed.Default is
true. -
isWriterAccessAllowed
public boolean isWriterAccessAllowed()Return whethergetOutputStream()access is allowed. -
setDefaultCharacterEncoding
Set the default character encoding for the response.If this method is not invoked,
ISO-8859-1will be used as the default character encoding.If the character encoding for the response has not already been explicitly set via
setCharacterEncoding(String)orsetContentType(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 throughHttpServletResponsemethods or through acharsetparameter on theContent-Type.If
false,getCharacterEncoding()will return the default character encoding. -
setCharacterEncoding
- 指定者:
setCharacterEncoding在接口中jakarta.servlet.ServletResponse
-
setExplicitCharacterEncoding
-
updateContentTypePropertyAndHeader
private void updateContentTypePropertyAndHeader() -
getCharacterEncoding
- 指定者:
getCharacterEncoding在接口中jakarta.servlet.ServletResponse
-
getOutputStream
public jakarta.servlet.ServletOutputStream getOutputStream()- 指定者:
getOutputStream在接口中jakarta.servlet.ServletResponse
-
getWriter
- 指定者:
getWriter在接口中jakarta.servlet.ServletResponse- 抛出:
UnsupportedEncodingException
-
getContentAsByteArray
public byte[] getContentAsByteArray() -
getContentAsString
Get the content of the response body as aString, using the charset specified for the response by the application, either throughHttpServletResponsemethods or through a charset parameter on theContent-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
Get the content of the response body as aString, using the providedfallbackCharsetif no charset has been explicitly defined and otherwise using the charset specified for the response by the application, either throughHttpServletResponsemethods or through a charset parameter on theContent-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
- 指定者:
setContentType在接口中jakarta.servlet.ServletResponse
-
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
- 指定者:
setLocale在接口中jakarta.servlet.ServletResponse
-
getLocale
- 指定者:
getLocale在接口中jakarta.servlet.ServletResponse
-
addCookie
public void addCookie(jakarta.servlet.http.Cookie cookie) - 指定者:
addCookie在接口中jakarta.servlet.http.HttpServletResponse
-
getCookieHeader
-
getCookies
public jakarta.servlet.http.Cookie[] getCookies() -
getCookie
-
containsHeader
- 指定者:
containsHeader在接口中jakarta.servlet.http.HttpServletResponse
-
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
Setof header nameStrings, or an emptySetif none
-
getHeader
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 usinggetHeaderValue(String)for raw Object access.- 指定者:
getHeader在接口中jakarta.servlet.http.HttpServletResponse- 参数:
name- the name of the header- 返回:
- the associated header value, or
nullif none
-
getHeaders
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 usinggetHeaderValues(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
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
nullif none
-
getHeaderValues
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
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
The default implementation delegates toencodeURL(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
- 指定者:
sendError在接口中jakarta.servlet.http.HttpServletResponse- 抛出:
IOException
-
sendError
- 指定者:
sendError在接口中jakarta.servlet.http.HttpServletResponse- 抛出:
IOException
-
sendRedirect
- 指定者:
sendRedirect在接口中jakarta.servlet.http.HttpServletResponse- 抛出:
IOException
-
getRedirectedUrl
-
setDateHeader
- 指定者:
setDateHeader在接口中jakarta.servlet.http.HttpServletResponse
-
addDateHeader
- 指定者:
addDateHeader在接口中jakarta.servlet.http.HttpServletResponse
-
getDateHeader
-
formatDate
-
newDateFormat
-
setHeader
- 指定者:
setHeader在接口中jakarta.servlet.http.HttpServletResponse
-
addHeader
- 指定者:
addHeader在接口中jakarta.servlet.http.HttpServletResponse
-
setIntHeader
- 指定者:
setIntHeader在接口中jakarta.servlet.http.HttpServletResponse
-
addIntHeader
- 指定者:
addIntHeader在接口中jakarta.servlet.http.HttpServletResponse
-
setHeaderValue
-
addHeaderValue
-
setSpecialHeader
-
doAddHeaderValue
-
setCookie
private void setCookie(jakarta.servlet.http.Cookie cookie) Set theSet-Cookieheader to the suppliedCookie, overwriting any previous cookies.- 参数:
cookie- theCookieto set- 另请参阅:
-
setStatus
public void setStatus(int status) - 指定者:
setStatus在接口中jakarta.servlet.http.HttpServletResponse
-
getStatus
public int getStatus()- 指定者:
getStatus在接口中jakarta.servlet.http.HttpServletResponse
-
getErrorMessage
-
setForwardedUrl
-
getForwardedUrl
-
setIncludedUrl
-
getIncludedUrl
-
addIncludedUrl
-
getIncludedUrls
-