Package com.jalios.servlet.http
Class MockHttpServletResponse
java.lang.Object
com.jalios.servlet.http.MockHttpServletResponse
- All Implemented Interfaces:
javax.servlet.http.HttpServletResponse,javax.servlet.ServletResponse
public class MockHttpServletResponse
extends Object
implements javax.servlet.http.HttpServletResponse
Mock implementation of the
HttpServletResponse interface. Supports the Servlet 2.5 API level.-
Field Summary
FieldsFields inherited from interface 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCookie(javax.servlet.http.Cookie cookie) voidaddDateHeader(String name, long value) voidvoidaddIncludedUrl(String includedUrl) voidaddIntHeader(String name, int value) booleancontainsHeader(String name) encodeRedirectUrl(String url) 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.voidintbyte[]intjavax.servlet.http.Cookiejavax.servlet.http.Cookie[]Return the primary value for the given header, 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 value objects.javax.servlet.ServletOutputStreamintbooleanbooleanReturn whethergetOutputStream()access is allowed.booleanReturn whethergetOutputStream()access is allowed.voidreset()voidvoidsendError(int status) voidvoidsendRedirect(String url) voidsetBufferSize(int bufferSize) voidsetCharacterEncoding(String characterEncoding) voidsetCommitted(boolean committed) voidsetContentLength(int contentLength) voidsetContentLengthLong(long arg0) voidsetContentType(String contentType) voidsetDateHeader(String name, long value) voidsetForwardedUrl(String forwardedUrl) voidvoidsetIncludedUrl(String includedUrl) voidsetIntHeader(String name, int value) voidvoidsetOutputStreamAccessAllowed(boolean outputStreamAccessAllowed) Set whethergetOutputStream()access is allowed.voidsetStatus(int status) voidvoidsetWriterAccessAllowed(boolean writerAccessAllowed) Set whethergetWriter()access is allowed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.servlet.http.HttpServletResponse
getTrailerFields, setTrailerFields
-
Field Details
-
DEFAULT_SERVER_PORT
public static final int DEFAULT_SERVER_PORT- See Also:
-
-
Constructor Details
-
MockHttpServletResponse
public MockHttpServletResponse()
-
-
Method Details
-
setOutputStreamAccessAllowed
public void setOutputStreamAccessAllowed(boolean outputStreamAccessAllowed) Set whethergetOutputStream()access is allowed.Default is
true.- Parameters:
outputStreamAccessAllowed- boolean
-
isOutputStreamAccessAllowed
public boolean isOutputStreamAccessAllowed()Return whethergetOutputStream()access is allowed.- Returns:
- boolean
-
setWriterAccessAllowed
public void setWriterAccessAllowed(boolean writerAccessAllowed) Set whethergetWriter()access is allowed.Default is
true.- Parameters:
writerAccessAllowed- boolean
-
isWriterAccessAllowed
public boolean isWriterAccessAllowed()Return whethergetOutputStream()access is allowed.- Returns:
- boolean
-
setCharacterEncoding
- Specified by:
setCharacterEncodingin interfacejavax.servlet.ServletResponse
-
getCharacterEncoding
- Specified by:
getCharacterEncodingin interfacejavax.servlet.ServletResponse
-
getOutputStream
public javax.servlet.ServletOutputStream getOutputStream()- Specified by:
getOutputStreamin interfacejavax.servlet.ServletResponse
-
getWriter
- Specified by:
getWriterin interfacejavax.servlet.ServletResponse- Throws:
UnsupportedEncodingException
-
getContentAsByteArray
public byte[] getContentAsByteArray() -
getContentAsString
- Throws:
UnsupportedEncodingException
-
setContentLength
public void setContentLength(int contentLength) - Specified by:
setContentLengthin interfacejavax.servlet.ServletResponse
-
getContentLength
public int getContentLength() -
setContentType
- Specified by:
setContentTypein interfacejavax.servlet.ServletResponse
-
getContentType
- Specified by:
getContentTypein interfacejavax.servlet.ServletResponse
-
setBufferSize
public void setBufferSize(int bufferSize) - Specified by:
setBufferSizein interfacejavax.servlet.ServletResponse
-
getBufferSize
public int getBufferSize()- Specified by:
getBufferSizein interfacejavax.servlet.ServletResponse
-
flushBuffer
public void flushBuffer()- Specified by:
flushBufferin interfacejavax.servlet.ServletResponse
-
resetBuffer
public void resetBuffer()- Specified by:
resetBufferin interfacejavax.servlet.ServletResponse
-
setCommitted
public void setCommitted(boolean committed) -
isCommitted
public boolean isCommitted()- Specified by:
isCommittedin interfacejavax.servlet.ServletResponse
-
reset
public void reset()- Specified by:
resetin interfacejavax.servlet.ServletResponse
-
setLocale
- Specified by:
setLocalein interfacejavax.servlet.ServletResponse
-
getLocale
- Specified by:
getLocalein interfacejavax.servlet.ServletResponse
-
addCookie
public void addCookie(javax.servlet.http.Cookie cookie) - Specified by:
addCookiein interfacejavax.servlet.http.HttpServletResponse
-
getCookies
public javax.servlet.http.Cookie[] getCookies() -
getCookie
-
containsHeader
- Specified by:
containsHeaderin interfacejavax.servlet.http.HttpServletResponse
-
getHeaderNames
Return the names of all specified headers as a Set of Strings.- Specified by:
getHeaderNamesin interfacejavax.servlet.http.HttpServletResponse- Returns:
- the
Setof header nameStrings, or an emptySetif none
-
getHeader
Return the primary value for the given header, if any.Will return the first value in case of multiple values.
- Specified by:
getHeaderin interfacejavax.servlet.http.HttpServletResponse- Parameters:
name- the name of the header- Returns:
- the associated header value, or
nullif none
-
getHeaders
Return all values for the given header as a List of value objects.- Specified by:
getHeadersin interfacejavax.servlet.http.HttpServletResponse- Parameters:
name- the name of the header- Returns:
- 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.
- Specified by:
encodeURLin interfacejavax.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, appyling to redirect URLs as well as to general URLs.- Specified by:
encodeRedirectURLin interfacejavax.servlet.http.HttpServletResponse
-
encodeUrl
- Specified by:
encodeUrlin interfacejavax.servlet.http.HttpServletResponse
-
encodeRedirectUrl
- Specified by:
encodeRedirectUrlin interfacejavax.servlet.http.HttpServletResponse
-
sendError
- Specified by:
sendErrorin interfacejavax.servlet.http.HttpServletResponse- Throws:
IOException
-
sendError
- Specified by:
sendErrorin interfacejavax.servlet.http.HttpServletResponse- Throws:
IOException
-
sendRedirect
- Specified by:
sendRedirectin interfacejavax.servlet.http.HttpServletResponse- Throws:
IOException
-
getRedirectedUrl
-
setDateHeader
- Specified by:
setDateHeaderin interfacejavax.servlet.http.HttpServletResponse
-
addDateHeader
- Specified by:
addDateHeaderin interfacejavax.servlet.http.HttpServletResponse
-
setHeader
- Specified by:
setHeaderin interfacejavax.servlet.http.HttpServletResponse
-
addHeader
- Specified by:
addHeaderin interfacejavax.servlet.http.HttpServletResponse
-
setIntHeader
- Specified by:
setIntHeaderin interfacejavax.servlet.http.HttpServletResponse
-
addIntHeader
- Specified by:
addIntHeaderin interfacejavax.servlet.http.HttpServletResponse
-
setStatus
public void setStatus(int status) - Specified by:
setStatusin interfacejavax.servlet.http.HttpServletResponse
-
setStatus
- Specified by:
setStatusin interfacejavax.servlet.http.HttpServletResponse
-
getStatus
public int getStatus()- Specified by:
getStatusin interfacejavax.servlet.http.HttpServletResponse
-
getErrorMessage
-
setForwardedUrl
-
getForwardedUrl
-
setIncludedUrl
-
getIncludedUrl
-
addIncludedUrl
-
getIncludedUrls
-
setContentLengthLong
public void setContentLengthLong(long arg0) - Specified by:
setContentLengthLongin interfacejavax.servlet.ServletResponse
-