Module org.apache.wicket.core
Class MockHttpServletResponse
java.lang.Object
org.apache.wicket.protocol.http.mock.MockHttpServletResponse
- All Implemented Interfaces:
jakarta.servlet.http.HttpServletResponse
,jakarta.servlet.ServletResponse
,IMetaDataBufferingWebResponse
public class MockHttpServletResponse
extends Object
implements jakarta.servlet.http.HttpServletResponse, IMetaDataBufferingWebResponse
Mock servlet response. Implements all of the methods from the standard HttpServletResponse class
plus helper methods to aid viewing the generated response.
- Author:
- Chris Turner
-
Field Summary
Fields inherited from interface jakarta.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
ConstructorDescriptionMockHttpServletResponse
(MockHttpServletRequest servletRequest) Create the response object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCookie
(jakarta.servlet.http.Cookie cookie) Add a cookie to the response.void
addDateHeader
(String name, long l) Add a date header.void
Add the given header value, including an additional entry if one already exists.void
addIntHeader
(String name, int i) Add an int header value.static void
append2digits
(StringBuilder buf, int i) boolean
containsHeader
(String name) Check if the response contains the given header name.encodeRedirectURL
(String url) Encode the redirectLocation URL.Encode the URL.void
Flush the buffer.static String
formatDate
(long l) static void
formatDate
(StringBuilder buf, Calendar calendar, boolean cookie) Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookiesbyte[]
Get the binary content that was written to the servlet stream.int
Return the current buffer sizeGet the character encoding of the response.List<jakarta.servlet.http.Cookie>
Get all of the cookies that have been added to the response.Get the text document that was written as part of this response.Get the error message.Return the value of the given named header.Get the names of all of the headers.getHeaders
(String name) Get the encoded localejakarta.servlet.ServletOutputStream
Get the output stream for writing binary data from the servlet.Get the location that was redirected to.int
Get the status code.Get the print writer for writing text output for this response.void
Reset the response ready for reuse.boolean
Always returns false.boolean
isError()
Return whether the servlet returned an error code or not.boolean
Check whether the response was redirected or not.void
reset()
Delegate to initialize method.void
Clears the buffer.void
sendError
(int code) Send an error code.void
Send an error code.void
sendRedirect
(String location) Indicate sending of a redirectLocation to a particular named resource.void
setBufferSize
(int size) Method ignored.void
setCharacterEncoding
(String characterEncoding) Set the character encoding.void
setContentLength
(int length) Set the content length.void
setContentLengthLong
(long len) void
setContentType
(String type) Set the content type.void
setDateHeader
(String name, long l) Set a date header.void
Set the given header value.void
setIntHeader
(String name, int i) Set an int header value.void
Set the locale in the response header.void
setStatus
(int status) Set the status for this response.void
writeMetaData
(WebResponse webResponse) transfer cookies to given web responseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jakarta.servlet.http.HttpServletResponse
getTrailerFields, setTrailerFields
-
Constructor Details
-
MockHttpServletResponse
Create the response object.- Parameters:
servletRequest
-
-
-
Method Details
-
addCookie
Add a cookie to the response.- Specified by:
addCookie
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
cookie
- The cookie to add
-
addDateHeader
Add a date header.- Specified by:
addDateHeader
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
- The header valuel
- The long value
-
addHeader
Add the given header value, including an additional entry if one already exists.- Specified by:
addHeader
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
- The name for the headervalue
- The value for the header
-
addIntHeader
Add an int header value.- Specified by:
addIntHeader
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
- The header namei
- The value
-
containsHeader
Check if the response contains the given header name.- Specified by:
containsHeader
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
- The name to check- Returns:
- Whether header in response or not
-
encodeRedirectURL
Encode the redirectLocation URL. Does no changes as this test implementation uses cookie based url tracking.- Specified by:
encodeRedirectURL
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
url
- The url to encode- Returns:
- The encoded url
-
encodeURL
Encode the URL. Does no changes as this test implementation uses cookie based url tracking.- Specified by:
encodeURL
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
url
- The url to encode- Returns:
- The encoded url
-
flushBuffer
Flush the buffer.- Specified by:
flushBuffer
in interfacejakarta.servlet.ServletResponse
- Throws:
IOException
-
getBinaryContent
Get the binary content that was written to the servlet stream.- Returns:
- The binary content
-
getBufferSize
Return the current buffer size- Specified by:
getBufferSize
in interfacejakarta.servlet.ServletResponse
- Returns:
- The buffer size
-
getCharacterEncoding
Get the character encoding of the response.- Specified by:
getCharacterEncoding
in interfacejakarta.servlet.ServletResponse
- Returns:
- The character encoding
-
getCookies
Get all of the cookies that have been added to the response.- Returns:
- The collection of cookies
-
getDocument
Get the text document that was written as part of this response.- Returns:
- The document
-
getErrorMessage
Get the error message.- Returns:
- The error message, or null if no message
-
getHeader
Return the value of the given named header.- Specified by:
getHeader
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
- The header name- Returns:
- The value, or null
-
getHeaderNames
Get the names of all of the headers.- Specified by:
getHeaderNames
in interfacejakarta.servlet.http.HttpServletResponse
- Returns:
- The header names
-
getLocale
Get the encoded locale- Specified by:
getLocale
in interfacejakarta.servlet.ServletResponse
- Returns:
- The locale
-
getOutputStream
Get the output stream for writing binary data from the servlet.- Specified by:
getOutputStream
in interfacejakarta.servlet.ServletResponse
- Returns:
- The binary output stream.
-
getRedirectLocation
Get the location that was redirected to.- Returns:
- The redirect location, or null if not a redirect
-
getStatus
Get the status code.- Specified by:
getStatus
in interfacejakarta.servlet.http.HttpServletResponse
- Returns:
- The status code
-
getWriter
Get the print writer for writing text output for this response.- Specified by:
getWriter
in interfacejakarta.servlet.ServletResponse
- Returns:
- The writer
- Throws:
IOException
- Not used
-
initialize
Reset the response ready for reuse. -
isCommitted
Always returns false.- Specified by:
isCommitted
in interfacejakarta.servlet.ServletResponse
- Returns:
- Always false
-
isError
Return whether the servlet returned an error code or not.- Returns:
- Whether an error occurred or not
-
isRedirect
Check whether the response was redirected or not.- Returns:
- Whether the state was redirected or not
-
reset
Delegate to initialize method.- Specified by:
reset
in interfacejakarta.servlet.ServletResponse
-
resetBuffer
Clears the buffer.- Specified by:
resetBuffer
in interfacejakarta.servlet.ServletResponse
-
sendError
Send an error code. This implementation just sets the internal error state information.- Specified by:
sendError
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
code
- The code- Throws:
IOException
- Not used
-
sendError
Send an error code. This implementation just sets the internal error state information.- Specified by:
sendError
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
code
- The error codemsg
- The error message- Throws:
IOException
- Not used
-
sendRedirect
Indicate sending of a redirectLocation to a particular named resource. This implementation just keeps hold of the redirectLocation info and makes it available for query.- Specified by:
sendRedirect
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
location
- The location to redirectLocation to- Throws:
IOException
- Not used
-
setBufferSize
Method ignored.- Specified by:
setBufferSize
in interfacejakarta.servlet.ServletResponse
- Parameters:
size
- The size
-
setCharacterEncoding
Set the character encoding.- Specified by:
setCharacterEncoding
in interfacejakarta.servlet.ServletResponse
- Parameters:
characterEncoding
- The character encoding
-
setContentLength
Set the content length.- Specified by:
setContentLength
in interfacejakarta.servlet.ServletResponse
- Parameters:
length
- The length
-
setContentLengthLong
- Specified by:
setContentLengthLong
in interfacejakarta.servlet.ServletResponse
-
setContentType
Set the content type.- Specified by:
setContentType
in interfacejakarta.servlet.ServletResponse
- Parameters:
type
- The content type
-
getContentType
- Specified by:
getContentType
in interfacejakarta.servlet.ServletResponse
- Returns:
- value of content-type header
-
setDateHeader
Set a date header.- Specified by:
setDateHeader
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
- The header namel
- The long value
-
formatDate
- Parameters:
l
-- Returns:
- formatted date
-
formatDate
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies- Parameters:
buf
-calendar
-cookie
-
-
append2digits
- Parameters:
buf
-i
-
-
setHeader
Set the given header value.- Specified by:
setHeader
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
- The name for the headervalue
- The value for the header
-
setIntHeader
Set an int header value.- Specified by:
setIntHeader
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
- The header namei
- The value
-
setLocale
Set the locale in the response header.- Specified by:
setLocale
in interfacejakarta.servlet.ServletResponse
- Parameters:
locale
- The locale
-
setStatus
Set the status for this response.- Specified by:
setStatus
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
status
- The status
-
getBinaryResponse
- Returns:
- binary response
-
getHeaders
- Specified by:
getHeaders
in interfacejakarta.servlet.http.HttpServletResponse
- Parameters:
name
-- Returns:
- headers with given name
-
writeMetaData
Description copied from interface:IMetaDataBufferingWebResponse
transfer cookies to given web response- Specified by:
writeMetaData
in interfaceIMetaDataBufferingWebResponse
- Parameters:
webResponse
- web response that should receive the current cookies
-