Package org.apache.wicket.mock
Class MockWebResponse
- java.lang.Object
-
- org.apache.wicket.request.Response
-
- org.apache.wicket.request.http.WebResponse
-
- org.apache.wicket.mock.MockWebResponse
-
public class MockWebResponse extends WebResponse
MockedWebResponse
.- Author:
- Matej Knopp
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.wicket.request.http.WebResponse
WebResponse.CacheScope
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.request.http.WebResponse
MAX_CACHE_DURATION
-
-
Constructor Summary
Constructors Constructor Description MockWebResponse()
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCookie(javax.servlet.http.Cookie cookie)
Add a cookie to the web responsevoid
addHeader(String name, String value)
Add a value to the servlet response stream.void
clearCookie(javax.servlet.http.Cookie cookie)
Convenience method for clearing a cookie.String
encodeRedirectURL(CharSequence url)
Encodes urls used to redirect.String
encodeURL(CharSequence url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.void
flush()
Flushes the response.byte[]
getBinaryResponse()
Object
getContainerResponse()
Provides access to the low-level container response object that implementaion of thisResponse
delegate to.Long
getContentLength()
String
getContentType()
List<javax.servlet.http.Cookie>
getCookies()
Instant
getDateHeader(String name)
String
getErrorMessage()
String
getHeader(String name)
Set<String>
getHeaderNames()
String
getRedirectUrl()
Integer
getStatus()
CharSequence
getTextResponse()
boolean
hasHeader(String name)
boolean
isHeaderSupported()
Indicates if the response supports setting headers.boolean
isRedirect()
void
reset()
Called when the Response needs to reset itself.void
sendError(int sc, String msg)
Send error status code with optional message.void
sendRedirect(String url)
Redirects the response to specified URL.void
setContentLength(long length)
Set the content length on the response, if appropriate in the subclass.void
setContentType(String mimeType)
Set the content type on the response, if appropriate in the subclass.void
setDateHeader(String name, Instant date)
Set a header to the date value in the servlet response stream.void
setHeader(String name, String value)
Set a header to the string value in the servlet response stream.void
setStatus(int sc)
Sets the status code for this response.void
write(byte[] array)
Writes the buffer to output.void
write(byte[] array, int offset, int length)
Writes the buffer to output.void
write(CharSequence sequence)
Writes theCharSequence
to output.-
Methods inherited from class org.apache.wicket.request.http.WebResponse
disableCaching, enableCaching, setAcceptRange, setAttachmentHeader, setContentRange, setInlineHeader, setLastModifiedTime
-
Methods inherited from class org.apache.wicket.request.Response
close, getOutputStream
-
-
-
-
Constructor Detail
-
MockWebResponse
public MockWebResponse()
Construct.
-
-
Method Detail
-
addCookie
public void addCookie(javax.servlet.http.Cookie cookie)
Description copied from class:WebResponse
Add a cookie to the web response- Specified by:
addCookie
in classWebResponse
-
clearCookie
public void clearCookie(javax.servlet.http.Cookie cookie)
Description copied from class:WebResponse
Convenience method for clearing a cookie.- Specified by:
clearCookie
in classWebResponse
- Parameters:
cookie
- The cookie to set- See Also:
WebResponse.addCookie(Cookie)
-
getCookies
public List<javax.servlet.http.Cookie> getCookies()
- Returns:
- cookies set in this response
-
sendRedirect
public void sendRedirect(String url)
Description copied from class:WebResponse
Redirects the response to specified URL. The implementation is responsible for properly encoding the URL. Implementations of this method should run passed inurl
parameters through theWebResponse.encodeRedirectURL(CharSequence)
method.- Specified by:
sendRedirect
in classWebResponse
-
getRedirectUrl
public String getRedirectUrl()
- Returns:
- redirect URL or
null
ifsendRedirect(String)
was not called.
-
isRedirect
public boolean isRedirect()
- Specified by:
isRedirect
in classWebResponse
- Returns:
true
if redirect URL was set,false
otherwise.
-
setContentLength
public void setContentLength(long length)
Description copied from class:WebResponse
Set the content length on the response, if appropriate in the subclass. This default implementation does nothing.- Specified by:
setContentLength
in classWebResponse
- Parameters:
length
- The length of the content
-
getContentLength
public Long getContentLength()
- Returns:
- content length (set by
setContentLength(long)
)
-
setContentType
public void setContentType(String mimeType)
Description copied from class:WebResponse
Set the content type on the response, if appropriate in the subclass. This default implementation does nothing.- Specified by:
setContentType
in classWebResponse
- Parameters:
mimeType
- The mime type
-
getContentType
public String getContentType()
- Returns:
- content mime type
-
setDateHeader
public void setDateHeader(String name, Instant date)
Description copied from class:WebResponse
Set a header to the date value in the servlet response stream.- Specified by:
setDateHeader
in classWebResponse
-
getDateHeader
public Instant getDateHeader(String name)
- Parameters:
name
-- Returns:
- date header with specified name
-
isHeaderSupported
public boolean isHeaderSupported()
Description copied from class:WebResponse
Indicates if the response supports setting headers. When this method returns false,WebResponse.setHeader(String, String)
and its variations will thrown anUnsupportedOperationException
.- Specified by:
isHeaderSupported
in classWebResponse
- Returns:
- True when this
WebResponse
supports setting headers.
-
setHeader
public void setHeader(String name, String value)
Description copied from class:WebResponse
Set a header to the string value in the servlet response stream.- Specified by:
setHeader
in classWebResponse
-
addHeader
public void addHeader(String name, String value)
Description copied from class:WebResponse
Add a value to the servlet response stream.- Specified by:
addHeader
in classWebResponse
-
getHeader
public String getHeader(String name)
- Parameters:
name
-- Returns:
- header string with specified name
-
hasHeader
public boolean hasHeader(String name)
- Parameters:
name
-- Returns:
true
if the header was set,false
otherwise
-
getHeaderNames
public Set<String> getHeaderNames()
- Returns:
- set of all header names
-
setStatus
public void setStatus(int sc)
Description copied from class:WebResponse
Sets the status code for this response.- Specified by:
setStatus
in classWebResponse
- Parameters:
sc
- status code
-
encodeURL
public String encodeURL(CharSequence url)
Description copied from class:Response
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
-
encodeRedirectURL
public String encodeRedirectURL(CharSequence url)
Description copied from class:WebResponse
Encodes urls used to redirect. Sometimes rules for encoding URLs for redirecting differ from encoding URLs for links, so this method is broken out away formResponse.encodeURL(CharSequence)
.- Specified by:
encodeRedirectURL
in classWebResponse
- Returns:
- encoded URL
-
write
public void write(CharSequence sequence)
Description copied from class:Response
Writes theCharSequence
to output.
-
getTextResponse
public CharSequence getTextResponse()
- Returns:
- text response
-
write
public void write(byte[] array)
Description copied from class:Response
Writes the buffer to output.
-
write
public void write(byte[] array, int offset, int length)
Description copied from class:Response
Writes the buffer to output.
-
getBinaryResponse
public byte[] getBinaryResponse()
- Returns:
- binary response
-
sendError
public void sendError(int sc, String msg)
Description copied from class:WebResponse
Send error status code with optional message.- Specified by:
sendError
in classWebResponse
-
getErrorMessage
public String getErrorMessage()
- Returns:
- error message
-
flush
public void flush()
Description copied from class:WebResponse
Flushes the response.- Specified by:
flush
in classWebResponse
-
reset
public void reset()
Description copied from class:Response
Called when the Response needs to reset itself. Subclasses can empty there buffer or build up state.
-
getContainerResponse
public Object getContainerResponse()
Description copied from class:Response
Provides access to the low-level container response object that implementaion of thisResponse
delegate to. This allows users to access features provided by the container response but not by generalized WicketResponse
objects.- Specified by:
getContainerResponse
in classResponse
- Returns:
- low-level container response object, or
null
if none
-
-