类 MockHttpServletResponse
- java.lang.Object
- org.springframework.mock.web.MockHttpServletResponse
- 所有已实现的接口:
HttpServletResponse,ServletResponse
public class MockHttpServletResponse extends Object implements HttpServletResponse
Mock implementation of theHttpServletResponseinterface.As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. Beyond that,
MockHttpServletResponseis also compatible with Servlet 3.1'ssetContentLengthLong()method.- 从以下版本开始:
- 1.0.2
- 作者:
- Juergen Hoeller, Rod Johnson, Brian Clozel
字段概要
从接口继承的字段 javax.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
构造器概要
构造器 构造器 说明 MockHttpServletResponse()
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 voidaddCookie(Cookie cookie)voidaddDateHeader(String name, long value)voidaddHeader(String name, String value)voidaddIncludedUrl(String includedUrl)voidaddIntHeader(String name, int value)booleancontainsHeader(String name)StringencodeRedirectUrl(String url)已过时。StringencodeRedirectURL(String url)The default implementation delegates toencodeURL(java.lang.String), returning the given URL String as-is.StringencodeUrl(String url)已过时。StringencodeURL(String url)The default implementation returns the given URL String as-is.voidflushBuffer()intgetBufferSize()StringgetCharacterEncoding()byte[]getContentAsByteArray()StringgetContentAsString()intgetContentLength()longgetContentLengthLong()StringgetContentType()CookiegetCookie(String name)Cookie[]getCookies()longgetDateHeader(String name)StringgetErrorMessage()StringgetForwardedUrl()StringgetHeader(String name)Return the primary value for the given header as a String, if any.Collection<String>getHeaderNames()Return the names of all specified headers as a Set of Strings.List<String>getHeaders(String name)Return all values for the given header as a List of Strings.ObjectgetHeaderValue(String name)Return the primary value for the given header, if any.List<Object>getHeaderValues(String name)Return all values for the given header as a List of value objects.StringgetIncludedUrl()List<String>getIncludedUrls()LocalegetLocale()ServletOutputStreamgetOutputStream()StringgetRedirectedUrl()intgetStatus()PrintWritergetWriter()booleanisCharset()Return whether the character encoding has been set.booleanisCommitted()booleanisOutputStreamAccessAllowed()Return whethergetOutputStream()access is allowed.booleanisWriterAccessAllowed()Return whethergetOutputStream()access is allowed.voidreset()voidresetBuffer()voidsendError(int status)voidsendError(int status, String errorMessage)voidsendRedirect(String url)voidsetBufferSize(int bufferSize)voidsetCharacterEncoding(String characterEncoding)voidsetCommitted(boolean committed)voidsetContentLength(int contentLength)voidsetContentLengthLong(long contentLength)voidsetContentType(String contentType)voidsetDateHeader(String name, long value)voidsetForwardedUrl(String forwardedUrl)voidsetHeader(String name, String value)voidsetIncludedUrl(String includedUrl)voidsetIntHeader(String name, int value)voidsetLocale(Locale locale)voidsetOutputStreamAccessAllowed(boolean outputStreamAccessAllowed)Set whethergetOutputStream()access is allowed.voidsetStatus(int status)voidsetStatus(int status, String errorMessage)已过时。voidsetWriterAccessAllowed(boolean writerAccessAllowed)Set whethergetWriter()access is allowed.
构造器详细资料
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.
isCharset
public boolean isCharset()
Return whether the character encoding has been set.If
false,getCharacterEncoding()will return a default encoding value.
setCharacterEncoding
public void setCharacterEncoding(String characterEncoding)
- 指定者:
setCharacterEncoding在接口中ServletResponse
getCharacterEncoding
public String getCharacterEncoding()
- 指定者:
getCharacterEncoding在接口中ServletResponse
getOutputStream
public ServletOutputStream getOutputStream()
- 指定者:
getOutputStream在接口中ServletResponse
getWriter
public PrintWriter getWriter() throws UnsupportedEncodingException
- 指定者:
getWriter在接口中ServletResponse- 抛出:
UnsupportedEncodingException
getContentAsByteArray
public byte[] getContentAsByteArray()
getContentAsString
public String getContentAsString() throws UnsupportedEncodingException
setContentLength
public void setContentLength(int contentLength)
- 指定者:
setContentLength在接口中ServletResponse
getContentLength
public int getContentLength()
setContentLengthLong
public void setContentLengthLong(long contentLength)
- 指定者:
setContentLengthLong在接口中ServletResponse
getContentLengthLong
public long getContentLengthLong()
setContentType
public void setContentType(String contentType)
- 指定者:
setContentType在接口中ServletResponse
getContentType
public String getContentType()
- 指定者:
getContentType在接口中ServletResponse
setBufferSize
public void setBufferSize(int bufferSize)
- 指定者:
setBufferSize在接口中ServletResponse
getBufferSize
public int getBufferSize()
- 指定者:
getBufferSize在接口中ServletResponse
flushBuffer
public void flushBuffer()
- 指定者:
flushBuffer在接口中ServletResponse
resetBuffer
public void resetBuffer()
- 指定者:
resetBuffer在接口中ServletResponse
setCommitted
public void setCommitted(boolean committed)
isCommitted
public boolean isCommitted()
- 指定者:
isCommitted在接口中ServletResponse
reset
public void reset()
- 指定者:
reset在接口中ServletResponse
setLocale
public void setLocale(Locale locale)
- 指定者:
setLocale在接口中ServletResponse
getLocale
public Locale getLocale()
- 指定者:
getLocale在接口中ServletResponse
addCookie
public void addCookie(Cookie cookie)
- 指定者:
addCookie在接口中HttpServletResponse
getCookies
public Cookie[] getCookies()
containsHeader
public boolean containsHeader(String name)
- 指定者:
containsHeader在接口中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在接口中HttpServletResponse- 返回:
- the
Setof header nameStrings, or an emptySetif none
getHeader
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. As of Spring 3.1, it returns a stringified value for Servlet 3.0 compatibility. Consider usinggetHeaderValue(String)for raw Object access.- 指定者:
getHeader在接口中HttpServletResponse- 参数:
name- the name of the header- 返回:
- the associated header value, or
nullif 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. As of Spring 3.1, it returns a List of stringified values for Servlet 3.0 compatibility. Consider usinggetHeaderValues(String)for raw Object access.- 指定者:
getHeaders在接口中HttpServletResponse- 参数:
name- the name of the header- 返回:
- the associated header values, or an empty List if none
getHeaderValue
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
nullif 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在接口中HttpServletResponse
encodeRedirectURL
public String encodeRedirectURL(String url)
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在接口中HttpServletResponse
encodeUrl
@Deprecated public String encodeUrl(String url)
已过时。- 指定者:
encodeUrl在接口中HttpServletResponse
encodeRedirectUrl
@Deprecated public String encodeRedirectUrl(String url)
已过时。- 指定者:
encodeRedirectUrl在接口中HttpServletResponse
sendError
public void sendError(int status, String errorMessage) throws IOException
- 指定者:
sendError在接口中HttpServletResponse- 抛出:
IOException
sendError
public void sendError(int status) throws IOException
- 指定者:
sendError在接口中HttpServletResponse- 抛出:
IOException
sendRedirect
public void sendRedirect(String url) throws IOException
- 指定者:
sendRedirect在接口中HttpServletResponse- 抛出:
IOException
getRedirectedUrl
public String getRedirectedUrl()
setDateHeader
public void setDateHeader(String name, long value)
- 指定者:
setDateHeader在接口中HttpServletResponse
addDateHeader
public void addDateHeader(String name, long value)
- 指定者:
addDateHeader在接口中HttpServletResponse
getDateHeader
public long getDateHeader(String name)
setHeader
public void setHeader(String name, String value)
- 指定者:
setHeader在接口中HttpServletResponse
addHeader
public void addHeader(String name, String value)
- 指定者:
addHeader在接口中HttpServletResponse
setIntHeader
public void setIntHeader(String name, int value)
- 指定者:
setIntHeader在接口中HttpServletResponse
addIntHeader
public void addIntHeader(String name, int value)
- 指定者:
addIntHeader在接口中HttpServletResponse
setStatus
public void setStatus(int status)
- 指定者:
setStatus在接口中HttpServletResponse
setStatus
@Deprecated public void setStatus(int status, String errorMessage)
已过时。- 指定者:
setStatus在接口中HttpServletResponse
getStatus
public int getStatus()
- 指定者:
getStatus在接口中HttpServletResponse
getErrorMessage
public String getErrorMessage()
setForwardedUrl
public void setForwardedUrl(String forwardedUrl)
getForwardedUrl
public String getForwardedUrl()
setIncludedUrl
public void setIncludedUrl(String includedUrl)
getIncludedUrl
public String getIncludedUrl()
addIncludedUrl
public void addIncludedUrl(String includedUrl)
getIncludedUrls
public List<String> getIncludedUrls()