|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.protocol.http.mock.MockHttpServletResponse
public class MockHttpServletResponse
Mock servlet response. Implements all of the methods from the standard HttpServletResponse class plus helper methods to aid viewing the generated response.
Field Summary |
---|
Fields 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 | |
---|---|
MockHttpServletResponse(MockHttpServletRequest servletRequest)
Create the response object. |
Method Summary | |
---|---|
void |
addCookie(javax.servlet.http.Cookie cookie)
Add a cookie to the response. |
void |
addDateHeader(String name,
long l)
Add a date header. |
void |
addHeader(String name,
String value)
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. |
String |
encodeRedirectUrl(String url)
Encode the redirectLocation URL. |
String |
encodeRedirectURL(String url)
Encode the redirectLocation URL. |
String |
encodeUrl(String url)
Encode the URL. |
String |
encodeURL(String url)
Encode the URL. |
void |
flushBuffer()
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 cookies |
byte[] |
getBinaryContent()
Get the binary content that was written to the servlet stream. |
String |
getBinaryResponse()
|
int |
getBufferSize()
Return the current buffer size |
String |
getCharacterEncoding()
Get the character encoding of the response. |
String |
getContentType()
|
List<javax.servlet.http.Cookie> |
getCookies()
Get all of the cookies that have been added to the response. |
String |
getDocument()
Get the text document that was written as part of this response. |
String |
getErrorMessage()
Get the error message. |
String |
getHeader(String name)
Return the value of the given named header. |
Set<String> |
getHeaderNames()
Get the names of all of the headers. |
Collection<String> |
getHeaders(String name)
|
Locale |
getLocale()
Get the encoded locale |
javax.servlet.ServletOutputStream |
getOutputStream()
Get the output stream for writing binary data from the servlet. |
String |
getRedirectLocation()
Get the location that was redirected to. |
int |
getStatus()
Get the status code. |
String |
getTextResponse()
Deprecated. use getDocument() |
PrintWriter |
getWriter()
Get the print writer for writing text output for this response. |
void |
initialize()
Reset the response ready for reuse. |
boolean |
isCommitted()
Always returns false. |
boolean |
isError()
Return whether the servlet returned an error code or not. |
boolean |
isRedirect()
Check whether the response was redirected or not. |
void |
reset()
Delegate to initialize method. |
void |
resetBuffer()
Clears the buffer. |
void |
sendError(int code)
Send an error code. |
void |
sendError(int code,
String msg)
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 |
setContentType(String type)
Set the content type. |
void |
setDateHeader(String name,
long l)
Set a date header. |
void |
setHeader(String name,
String value)
Set the given header value. |
void |
setIntHeader(String name,
int i)
Set an int header value. |
void |
setLocale(Locale locale)
Set the locale in the response header. |
void |
setStatus(int status)
Set the status for this response. |
void |
setStatus(int status,
String msg)
Deprecated. |
void |
writeMetaData(WebResponse webResponse)
transfer cookies to given web response |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MockHttpServletResponse(MockHttpServletRequest servletRequest)
servletRequest
- Method Detail |
---|
public void addCookie(javax.servlet.http.Cookie cookie)
addCookie
in interface javax.servlet.http.HttpServletResponse
cookie
- The cookie to addpublic void addDateHeader(String name, long l)
addDateHeader
in interface javax.servlet.http.HttpServletResponse
name
- The header valuel
- The long valuepublic void addHeader(String name, String value)
addHeader
in interface javax.servlet.http.HttpServletResponse
name
- The name for the headervalue
- The value for the headerpublic void addIntHeader(String name, int i)
addIntHeader
in interface javax.servlet.http.HttpServletResponse
name
- The header namei
- The valuepublic boolean containsHeader(String name)
containsHeader
in interface javax.servlet.http.HttpServletResponse
name
- The name to check
public String encodeRedirectUrl(String url)
encodeRedirectUrl
in interface javax.servlet.http.HttpServletResponse
url
- The url to encode
public String encodeRedirectURL(String url)
encodeRedirectURL
in interface javax.servlet.http.HttpServletResponse
url
- The url to encode
public String encodeUrl(String url)
encodeUrl
in interface javax.servlet.http.HttpServletResponse
url
- The url to encode
public String encodeURL(String url)
encodeURL
in interface javax.servlet.http.HttpServletResponse
url
- The url to encode
public void flushBuffer() throws IOException
flushBuffer
in interface javax.servlet.ServletResponse
IOException
public byte[] getBinaryContent()
public int getBufferSize()
getBufferSize
in interface javax.servlet.ServletResponse
public String getCharacterEncoding()
getCharacterEncoding
in interface javax.servlet.ServletResponse
public List<javax.servlet.http.Cookie> getCookies()
public String getDocument()
public String getErrorMessage()
public String getHeader(String name)
name
- The header name
public Set<String> getHeaderNames()
public Locale getLocale()
getLocale
in interface javax.servlet.ServletResponse
public javax.servlet.ServletOutputStream getOutputStream()
getOutputStream
in interface javax.servlet.ServletResponse
public String getRedirectLocation()
public int getStatus()
public PrintWriter getWriter() throws IOException
getWriter
in interface javax.servlet.ServletResponse
IOException
- Not usedpublic void initialize()
public boolean isCommitted()
isCommitted
in interface javax.servlet.ServletResponse
public boolean isError()
public boolean isRedirect()
public void reset()
reset
in interface javax.servlet.ServletResponse
public void resetBuffer()
resetBuffer
in interface javax.servlet.ServletResponse
public void sendError(int code) throws IOException
sendError
in interface javax.servlet.http.HttpServletResponse
code
- The code
IOException
- Not usedpublic void sendError(int code, String msg) throws IOException
sendError
in interface javax.servlet.http.HttpServletResponse
code
- The error codemsg
- The error message
IOException
- Not usedpublic void sendRedirect(String location) throws IOException
sendRedirect
in interface javax.servlet.http.HttpServletResponse
location
- The location to redirectLocation to
IOException
- Not usedpublic void setBufferSize(int size)
setBufferSize
in interface javax.servlet.ServletResponse
size
- The sizepublic void setCharacterEncoding(String characterEncoding)
setCharacterEncoding
in interface javax.servlet.ServletResponse
characterEncoding
- The character encodingpublic void setContentLength(int length)
setContentLength
in interface javax.servlet.ServletResponse
length
- The lengthpublic void setContentType(String type)
setContentType
in interface javax.servlet.ServletResponse
type
- The content typepublic String getContentType()
getContentType
in interface javax.servlet.ServletResponse
public void setDateHeader(String name, long l)
setDateHeader
in interface javax.servlet.http.HttpServletResponse
name
- The header namel
- The long valuepublic static String formatDate(long l)
l
-
public static void formatDate(StringBuilder buf, Calendar calendar, boolean cookie)
buf
- calendar
- cookie
- public static void append2digits(StringBuilder buf, int i)
buf
- i
- public void setHeader(String name, String value)
setHeader
in interface javax.servlet.http.HttpServletResponse
name
- The name for the headervalue
- The value for the headerpublic void setIntHeader(String name, int i)
setIntHeader
in interface javax.servlet.http.HttpServletResponse
name
- The header namei
- The valuepublic void setLocale(Locale locale)
setLocale
in interface javax.servlet.ServletResponse
locale
- The localepublic void setStatus(int status)
setStatus
in interface javax.servlet.http.HttpServletResponse
status
- The status@Deprecated public void setStatus(int status, String msg)
setStatus
in interface javax.servlet.http.HttpServletResponse
status
- The statusmsg
- The message@Deprecated public String getTextResponse()
getDocument()
public String getBinaryResponse()
public Collection<String> getHeaders(String name)
name
-
public void writeMetaData(WebResponse webResponse)
IMetaDataBufferingWebResponse
writeMetaData
in interface IMetaDataBufferingWebResponse
webResponse
- web response that should receive the current cookies
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |