类 MockHttpServletResponse
- java.lang.Object
- org.springframework.mock.web.MockHttpServletResponse
- 所有已实现的接口:
HttpServletResponse
,ServletResponse
public class MockHttpServletResponse extends Object implements HttpServletResponse
Mock implementation of theHttpServletResponse
interface.As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. Beyond that,
MockHttpServletResponse
is 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()
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 void
addCookie(Cookie cookie)
void
addDateHeader(String name, long value)
void
addHeader(String name, String value)
void
addIncludedUrl(String includedUrl)
void
addIntHeader(String name, int value)
boolean
containsHeader(String name)
String
encodeRedirectUrl(String url)
已过时。String
encodeRedirectURL(String url)
The default implementation delegates toencodeURL(java.lang.String)
, returning the given URL String as-is.String
encodeUrl(String url)
已过时。String
encodeURL(String url)
The default implementation returns the given URL String as-is.void
flushBuffer()
int
getBufferSize()
String
getCharacterEncoding()
byte[]
getContentAsByteArray()
String
getContentAsString()
int
getContentLength()
long
getContentLengthLong()
String
getContentType()
Cookie
getCookie(String name)
Cookie[]
getCookies()
long
getDateHeader(String name)
String
getErrorMessage()
String
getForwardedUrl()
String
getHeader(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.Object
getHeaderValue(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.String
getIncludedUrl()
List<String>
getIncludedUrls()
Locale
getLocale()
ServletOutputStream
getOutputStream()
String
getRedirectedUrl()
int
getStatus()
PrintWriter
getWriter()
boolean
isCharset()
Return whether the character encoding has been set.boolean
isCommitted()
boolean
isOutputStreamAccessAllowed()
Return whethergetOutputStream()
access is allowed.boolean
isWriterAccessAllowed()
Return whethergetOutputStream()
access is allowed.void
reset()
void
resetBuffer()
void
sendError(int status)
void
sendError(int status, String errorMessage)
void
sendRedirect(String url)
void
setBufferSize(int bufferSize)
void
setCharacterEncoding(String characterEncoding)
void
setCommitted(boolean committed)
void
setContentLength(int contentLength)
void
setContentLengthLong(long contentLength)
void
setContentType(String contentType)
void
setDateHeader(String name, long value)
void
setForwardedUrl(String forwardedUrl)
void
setHeader(String name, String value)
void
setIncludedUrl(String includedUrl)
void
setIntHeader(String name, int value)
void
setLocale(Locale locale)
void
setOutputStreamAccessAllowed(boolean outputStreamAccessAllowed)
Set whethergetOutputStream()
access is allowed.void
setStatus(int status)
void
setStatus(int status, String errorMessage)
已过时。void
setWriterAccessAllowed(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
Set
of header nameStrings
, or an emptySet
if 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
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
. 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
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
在接口中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()