public class

MockHttpServletResponse

extends Object
implements HttpServletResponse
java.lang.Object
   ↳ org.springframework.mock.web.MockHttpServletResponse

Class Overview

Mock implementation of the javax.servlet.http.HttpServletResponse interface. Supports the Servlet 2.5 API level.

Used for testing the web framework; also useful for testing application controllers.

Summary

Constants
int DEFAULT_SERVER_PORT
[Expand]
Inherited Constants
From interface javax.servlet.http.HttpServletResponse
Public Constructors
MockHttpServletResponse()
Public Methods
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)
The default implementation delegates to encodeURL(String), returning the given URL String as-is.
String encodeRedirectUrl(String url)
String encodeURL(String url)
The default implementation returns the given URL String as-is.
String encodeUrl(String url)
void flushBuffer()
int getBufferSize()
String getCharacterEncoding()
byte[] getContentAsByteArray()
String getContentAsString()
int getContentLength()
String getContentType()
Cookie getCookie(String name)
Cookie[] getCookies()
String getErrorMessage()
String getForwardedUrl()
Object getHeader(String name)
Return the primary value for the given header, if any.
Set<String> getHeaderNames()
Return the names of all specified headers as a Set of Strings.
List<Object> getHeaders(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 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, String errorMessage)
void sendRedirect(String url)
void setBufferSize(int bufferSize)
void setCharacterEncoding(String characterEncoding)
void setCommitted(boolean committed)
void setContentLength(int 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 whether getOutputStream() access is allowed.
void setStatus(int status)
void setStatus(int status, String errorMessage)
void setWriterAccessAllowed(boolean writerAccessAllowed)
Set whether getWriter() access is allowed.
[Expand]
Inherited Methods
From class java.lang.Object
From interface javax.servlet.ServletResponse
From interface javax.servlet.http.HttpServletResponse

Constants

public static final int DEFAULT_SERVER_PORT

Constant Value: 80 (0x00000050)

Public Constructors

public MockHttpServletResponse ()

Public Methods

public void addCookie (Cookie cookie)

public void addDateHeader (String name, long value)

public void addHeader (String name, String value)

public void addIncludedUrl (String includedUrl)

public void addIntHeader (String name, int value)

public boolean containsHeader (String name)

public String encodeRedirectURL (String url)

The default implementation delegates to encodeURL(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(String) method instead, appyling to redirect URLs as well as to general URLs.

public String encodeRedirectUrl (String url)

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.

public String encodeUrl (String url)

public void flushBuffer ()

public int getBufferSize ()

public String getCharacterEncoding ()

public byte[] getContentAsByteArray ()

public String getContentAsString ()

public int getContentLength ()

public String getContentType ()

public Cookie getCookie (String name)

public Cookie[] getCookies ()

public String getErrorMessage ()

public String getForwardedUrl ()

public Object getHeader (String name)

Return the primary value for the given header, if any.

Will return the first value in case of multiple values.

Parameters
name the name of the header
Returns
  • the associated header value, or null if none

public Set<String> getHeaderNames ()

Return the names of all specified headers as a Set of Strings.

Returns
  • the Set of header name Strings, or an empty Set if none

public List<Object> getHeaders (String name)

Return all values for the given header as a List of value objects.

Parameters
name the name of the header
Returns
  • the associated header values, or an empty List if none

public String getIncludedUrl ()

public List<String> getIncludedUrls ()

public Locale getLocale ()

public ServletOutputStream getOutputStream ()

public String getRedirectedUrl ()

public int getStatus ()

public PrintWriter getWriter ()

public boolean isCommitted ()

public boolean isOutputStreamAccessAllowed ()

Return whether getOutputStream() access is allowed.

public boolean isWriterAccessAllowed ()

Return whether getOutputStream() access is allowed.

public void reset ()

public void resetBuffer ()

public void sendError (int status)

Throws
IOException

public void sendError (int status, String errorMessage)

Throws
IOException

public void sendRedirect (String url)

Throws
IOException

public void setBufferSize (int bufferSize)

public void setCharacterEncoding (String characterEncoding)

public void setCommitted (boolean committed)

public void setContentLength (int contentLength)

public void setContentType (String contentType)

public void setDateHeader (String name, long value)

public void setForwardedUrl (String forwardedUrl)

public void setHeader (String name, String value)

public void setIncludedUrl (String includedUrl)

public void setIntHeader (String name, int value)

public void setLocale (Locale locale)

public void setOutputStreamAccessAllowed (boolean outputStreamAccessAllowed)

Set whether getOutputStream() access is allowed.

Default is true.

public void setStatus (int status)

public void setStatus (int status, String errorMessage)

public void setWriterAccessAllowed (boolean writerAccessAllowed)

Set whether getWriter() access is allowed.

Default is true.