public class MockHttpServletResponse extends java.lang.Object implements HttpServletResponse
HttpServletResponse
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's setContentLengthLong()
method.
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 and Description |
---|
MockHttpServletResponse() |
Modifier and Type | Method and Description |
---|---|
void |
addCookie(Cookie cookie) |
void |
addDateHeader(java.lang.String name,
long value) |
void |
addHeader(java.lang.String name,
java.lang.String value) |
void |
addIncludedUrl(java.lang.String includedUrl) |
void |
addIntHeader(java.lang.String name,
int value) |
boolean |
containsHeader(java.lang.String name) |
java.lang.String |
encodeRedirectUrl(java.lang.String url)
Deprecated.
|
java.lang.String |
encodeRedirectURL(java.lang.String url)
The default implementation delegates to
encodeURL(java.lang.String) ,
returning the given URL String as-is. |
java.lang.String |
encodeUrl(java.lang.String url)
Deprecated.
|
java.lang.String |
encodeURL(java.lang.String url)
The default implementation returns the given URL String as-is.
|
void |
flushBuffer() |
int |
getBufferSize() |
java.lang.String |
getCharacterEncoding() |
byte[] |
getContentAsByteArray() |
java.lang.String |
getContentAsString() |
int |
getContentLength() |
long |
getContentLengthLong() |
java.lang.String |
getContentType() |
Cookie |
getCookie(java.lang.String name) |
Cookie[] |
getCookies() |
long |
getDateHeader(java.lang.String name) |
java.lang.String |
getErrorMessage() |
java.lang.String |
getForwardedUrl() |
java.lang.String |
getHeader(java.lang.String name)
Return the primary value for the given header as a String, if any.
|
java.util.Collection<java.lang.String> |
getHeaderNames()
Return the names of all specified headers as a Set of Strings.
|
java.util.List<java.lang.String> |
getHeaders(java.lang.String name)
Return all values for the given header as a List of Strings.
|
java.lang.Object |
getHeaderValue(java.lang.String name)
Return the primary value for the given header, if any.
|
java.util.List<java.lang.Object> |
getHeaderValues(java.lang.String name)
Return all values for the given header as a List of value objects.
|
java.lang.String |
getIncludedUrl() |
java.util.List<java.lang.String> |
getIncludedUrls() |
java.util.Locale |
getLocale() |
ServletOutputStream |
getOutputStream() |
java.lang.String |
getRedirectedUrl() |
int |
getStatus() |
java.io.PrintWriter |
getWriter() |
boolean |
isCharset()
Return whether the character encoding has been set.
|
boolean |
isCommitted() |
boolean |
isOutputStreamAccessAllowed()
Return whether
getOutputStream() access is allowed. |
boolean |
isWriterAccessAllowed()
Return whether
getOutputStream() access is allowed. |
void |
reset() |
void |
resetBuffer() |
void |
sendError(int status) |
void |
sendError(int status,
java.lang.String errorMessage) |
void |
sendRedirect(java.lang.String url) |
void |
setBufferSize(int bufferSize) |
void |
setCharacterEncoding(java.lang.String characterEncoding) |
void |
setCommitted(boolean committed) |
void |
setContentLength(int contentLength) |
void |
setContentLengthLong(long contentLength) |
void |
setContentType(java.lang.String contentType) |
void |
setDateHeader(java.lang.String name,
long value) |
void |
setForwardedUrl(java.lang.String forwardedUrl) |
void |
setHeader(java.lang.String name,
java.lang.String value) |
void |
setIncludedUrl(java.lang.String includedUrl) |
void |
setIntHeader(java.lang.String name,
int value) |
void |
setLocale(java.util.Locale locale) |
void |
setOutputStreamAccessAllowed(boolean outputStreamAccessAllowed)
Set whether
getOutputStream() access is allowed. |
void |
setStatus(int status) |
void |
setStatus(int status,
java.lang.String errorMessage)
Deprecated.
|
void |
setWriterAccessAllowed(boolean writerAccessAllowed)
Set whether
getWriter() access is allowed. |
public void setOutputStreamAccessAllowed(boolean outputStreamAccessAllowed)
getOutputStream()
access is allowed.
Default is true
.
public boolean isOutputStreamAccessAllowed()
getOutputStream()
access is allowed.public void setWriterAccessAllowed(boolean writerAccessAllowed)
getWriter()
access is allowed.
Default is true
.
public boolean isWriterAccessAllowed()
getOutputStream()
access is allowed.public boolean isCharset()
If false
, getCharacterEncoding()
will return a default encoding value.
public void setCharacterEncoding(java.lang.String characterEncoding)
setCharacterEncoding
in interface ServletResponse
public java.lang.String getCharacterEncoding()
getCharacterEncoding
in interface ServletResponse
public ServletOutputStream getOutputStream()
getOutputStream
in interface ServletResponse
public java.io.PrintWriter getWriter() throws java.io.UnsupportedEncodingException
getWriter
in interface ServletResponse
java.io.UnsupportedEncodingException
public byte[] getContentAsByteArray()
public java.lang.String getContentAsString() throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public void setContentLength(int contentLength)
setContentLength
in interface ServletResponse
public int getContentLength()
public void setContentLengthLong(long contentLength)
setContentLengthLong
in interface ServletResponse
public long getContentLengthLong()
public void setContentType(java.lang.String contentType)
setContentType
in interface ServletResponse
public java.lang.String getContentType()
getContentType
in interface ServletResponse
public void setBufferSize(int bufferSize)
setBufferSize
in interface ServletResponse
public int getBufferSize()
getBufferSize
in interface ServletResponse
public void flushBuffer()
flushBuffer
in interface ServletResponse
public void resetBuffer()
resetBuffer
in interface ServletResponse
public void setCommitted(boolean committed)
public boolean isCommitted()
isCommitted
in interface ServletResponse
public void reset()
reset
in interface ServletResponse
public void setLocale(java.util.Locale locale)
setLocale
in interface ServletResponse
public java.util.Locale getLocale()
getLocale
in interface ServletResponse
public void addCookie(Cookie cookie)
addCookie
in interface HttpServletResponse
public Cookie[] getCookies()
public Cookie getCookie(java.lang.String name)
public boolean containsHeader(java.lang.String name)
containsHeader
in interface HttpServletResponse
public java.util.Collection<java.lang.String> getHeaderNames()
As of Servlet 3.0, this method is also defined HttpServletResponse.
getHeaderNames
in interface HttpServletResponse
Set
of header name Strings
, or an empty Set
if nonepublic java.lang.String getHeader(java.lang.String name)
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 using getHeaderValue(String)
for raw Object access.
getHeader
in interface HttpServletResponse
name
- the name of the headernull
if nonepublic java.util.List<java.lang.String> getHeaders(java.lang.String name)
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 using getHeaderValues(String)
for raw Object access.
getHeaders
in interface HttpServletResponse
name
- the name of the headerpublic java.lang.Object getHeaderValue(java.lang.String name)
Will return the first value in case of multiple values.
name
- the name of the headernull
if nonepublic java.util.List<java.lang.Object> getHeaderValues(java.lang.String name)
name
- the name of the headerpublic java.lang.String encodeURL(java.lang.String url)
Can be overridden in subclasses, appending a session id or the like.
encodeURL
in interface HttpServletResponse
public java.lang.String encodeRedirectURL(java.lang.String url)
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
in interface HttpServletResponse
@Deprecated public java.lang.String encodeUrl(java.lang.String url)
encodeUrl
in interface HttpServletResponse
@Deprecated public java.lang.String encodeRedirectUrl(java.lang.String url)
encodeRedirectUrl
in interface HttpServletResponse
public void sendError(int status, java.lang.String errorMessage) throws java.io.IOException
sendError
in interface HttpServletResponse
java.io.IOException
public void sendError(int status) throws java.io.IOException
sendError
in interface HttpServletResponse
java.io.IOException
public void sendRedirect(java.lang.String url) throws java.io.IOException
sendRedirect
in interface HttpServletResponse
java.io.IOException
public java.lang.String getRedirectedUrl()
public void setDateHeader(java.lang.String name, long value)
setDateHeader
in interface HttpServletResponse
public void addDateHeader(java.lang.String name, long value)
addDateHeader
in interface HttpServletResponse
public long getDateHeader(java.lang.String name)
public void setHeader(java.lang.String name, java.lang.String value)
setHeader
in interface HttpServletResponse
public void addHeader(java.lang.String name, java.lang.String value)
addHeader
in interface HttpServletResponse
public void setIntHeader(java.lang.String name, int value)
setIntHeader
in interface HttpServletResponse
public void addIntHeader(java.lang.String name, int value)
addIntHeader
in interface HttpServletResponse
public void setStatus(int status)
setStatus
in interface HttpServletResponse
@Deprecated public void setStatus(int status, java.lang.String errorMessage)
setStatus
in interface HttpServletResponse
public int getStatus()
getStatus
in interface HttpServletResponse
public java.lang.String getErrorMessage()
public void setForwardedUrl(java.lang.String forwardedUrl)
public java.lang.String getForwardedUrl()
public void setIncludedUrl(java.lang.String includedUrl)
public java.lang.String getIncludedUrl()
public void addIncludedUrl(java.lang.String includedUrl)
public java.util.List<java.lang.String> getIncludedUrls()