|
|||||||||
| Home >> All >> [ servletunit overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
servletunit
Class HttpServletResponseSimulator

java.lang.Objectservletunit.HttpServletResponseSimulator
- All Implemented Interfaces:
- javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse
- public class HttpServletResponseSimulator
- extends java.lang.Object
- implements javax.servlet.http.HttpServletResponse
- extends java.lang.Object
| Fields inherited from interface javax.servlet.http.HttpServletResponse |
SC_FOUND, SC_TEMPORARY_REDIRECT |
| Constructor Summary | |
HttpServletResponseSimulator()
|
|
| Method Summary | |
void |
addCookie(javax.servlet.http.Cookie cookie)
Add a cookie to this response, which will then be stored in the browser. |
void |
addDateHeader(java.lang.String name,
long date)
This method is not supported. |
void |
addHeader(java.lang.String name,
java.lang.String value)
Adds a response header with the given name and value. |
void |
addIntHeader(java.lang.String name,
int value)
Adds a response header with the given name and integer value. |
boolean |
containsHeader(java.lang.String name)
returns true if a header with the given name has already been set |
java.lang.String |
encodeRedirectUrl(java.lang.String url)
Returns the given URL unmodified |
java.lang.String |
encodeRedirectURL(java.lang.String url)
Returns the given URL unmodified. |
java.lang.String |
encodeUrl(java.lang.String url)
Returns the given URL unmodified. |
java.lang.String |
encodeURL(java.lang.String url)
Returns the given URL unmodified |
javax.servlet.http.Cookie |
findCookie(java.lang.String name)
Returns a cookie with a given, or null if this cookie has not been added to the repsonse. |
void |
flushBuffer()
This method is not supported. |
int |
getBufferSize()
This method is not supported. |
java.lang.String |
getCharacterEncoding()
This method is not supported. |
int |
getContentLength()
returns the content length previously set in setContentLength() |
java.lang.String |
getContentType()
returns the content type previously set in setContentType() |
java.lang.String |
getHeader(java.lang.String name)
Returns a given header field, or null if this header has not been set. |
java.util.Locale |
getLocale()
Returns the locale assigned to the response. |
java.lang.String |
getMessage()
|
javax.servlet.ServletOutputStream |
getOutputStream()
Returns a javax.servlet.ServletOutputStream suitable for writing binary data in the response. |
int |
getStatusCode()
Returns the status code for this response, which is useful for testing expected errors. |
java.io.PrintWriter |
getWriter()
Returns a PrintWriter object that
can send character text to the client. |
java.lang.StringBuffer |
getWriterBuffer()
Use this method to pick up the string buffer which will hold the contents of the string buffer. |
boolean |
isCommitted()
Returns a boolean indicating if the response has been committed. |
void |
removeHeader(java.lang.String name)
Removes a given header |
void |
reset()
Reinitializes all local variables. |
void |
resetBuffer()
This method is not supported. |
void |
sendError(int sc)
Sends an error response to the client using the specified status clearing the buffer. |
void |
sendError(int sc,
java.lang.String msg)
Sends an error response to the client using the specified status clearing the buffer. |
void |
sendRedirect(java.lang.String location)
Resets the response and sets the appropriate redirect headers. |
void |
setBufferSize(int size)
This method is not supported. |
void |
setCharacterEncoding(java.lang.String charEncoding)
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. |
void |
setContentLength(int len)
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header. |
void |
setContentType(java.lang.String type)
Sets the content type of the response being sent to the client. |
void |
setDateHeader(java.lang.String name,
long date)
This method is not supported. |
void |
setHeader(java.lang.String name,
java.lang.String value)
adds the name/value pair to the headers |
void |
setIntHeader(java.lang.String name,
int value)
Adds the given name/value pair to the headers collection. |
void |
setIsCommitted(boolean isCommitted)
|
void |
setLocale(java.util.Locale loc)
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate. |
void |
setOutputStream(java.io.OutputStream out)
The default action of calling the getOutputStream method
is to return a javax.servlet.ServletOutputStream object
that sends the data to System.out. |
void |
setStatus(int sc)
Sets the given status code. |
void |
setStatus(int sc,
java.lang.String sm)
Sets the given status and an associated message. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
servOStream
private java.io.OutputStream servOStream
calledGetWriter
private boolean calledGetWriter
calledGetOutputStream
private boolean calledGetOutputStream
stringWriter
private java.io.StringWriter stringWriter
printWriter
private java.io.PrintWriter printWriter
locale
private java.util.Locale locale
contentLength
private int contentLength
contentType
private java.lang.String contentType
status
private int status
message
private java.lang.String message
headers
private java.util.HashMap headers
cookies
private java.util.HashMap cookies
charEncoding
java.lang.String charEncoding
isCommitted
private boolean isCommitted
SC_CONTINUE
public static final int SC_CONTINUE
- See Also:
- Constant Field Values
SC_SWITCHING_PROTOCOLS
public static final int SC_SWITCHING_PROTOCOLS
- See Also:
- Constant Field Values
SC_OK
public static final int SC_OK
- See Also:
- Constant Field Values
SC_CREATED
public static final int SC_CREATED
- See Also:
- Constant Field Values
SC_ACCEPTED
public static final int SC_ACCEPTED
- See Also:
- Constant Field Values
SC_NON_AUTHORITATIVE_INFORMATION
public static final int SC_NON_AUTHORITATIVE_INFORMATION
- See Also:
- Constant Field Values
SC_NO_CONTENT
public static final int SC_NO_CONTENT
- See Also:
- Constant Field Values
SC_RESET_CONTENT
public static final int SC_RESET_CONTENT
- See Also:
- Constant Field Values
SC_PARTIAL_CONTENT
public static final int SC_PARTIAL_CONTENT
- See Also:
- Constant Field Values
SC_MULTIPLE_CHOICES
public static final int SC_MULTIPLE_CHOICES
- See Also:
- Constant Field Values
SC_MOVED_PERMANENTLY
public static final int SC_MOVED_PERMANENTLY
- See Also:
- Constant Field Values
SC_MOVED_TEMPORARILY
public static final int SC_MOVED_TEMPORARILY
- See Also:
- Constant Field Values
SC_SEE_OTHER
public static final int SC_SEE_OTHER
- See Also:
- Constant Field Values
SC_NOT_MODIFIED
public static final int SC_NOT_MODIFIED
- See Also:
- Constant Field Values
SC_USE_PROXY
public static final int SC_USE_PROXY
- See Also:
- Constant Field Values
SC_BAD_REQUEST
public static final int SC_BAD_REQUEST
- See Also:
- Constant Field Values
SC_UNAUTHORIZED
public static final int SC_UNAUTHORIZED
- See Also:
- Constant Field Values
SC_PAYMENT_REQUIRED
public static final int SC_PAYMENT_REQUIRED
- See Also:
- Constant Field Values
SC_FORBIDDEN
public static final int SC_FORBIDDEN
- See Also:
- Constant Field Values
SC_NOT_FOUND
public static final int SC_NOT_FOUND
- See Also:
- Constant Field Values
SC_METHOD_NOT_ALLOWED
public static final int SC_METHOD_NOT_ALLOWED
- See Also:
- Constant Field Values
SC_NOT_ACCEPTABLE
public static final int SC_NOT_ACCEPTABLE
- See Also:
- Constant Field Values
SC_PROXY_AUTHENTICATION_REQUIRED
public static final int SC_PROXY_AUTHENTICATION_REQUIRED
- See Also:
- Constant Field Values
SC_REQUEST_TIMEOUT
public static final int SC_REQUEST_TIMEOUT
- See Also:
- Constant Field Values
SC_CONFLICT
public static final int SC_CONFLICT
- See Also:
- Constant Field Values
SC_GONE
public static final int SC_GONE
- See Also:
- Constant Field Values
SC_LENGTH_REQUIRED
public static final int SC_LENGTH_REQUIRED
- See Also:
- Constant Field Values
SC_PRECONDITION_FAILED
public static final int SC_PRECONDITION_FAILED
- See Also:
- Constant Field Values
SC_REQUEST_ENTITY_TOO_LARGE
public static final int SC_REQUEST_ENTITY_TOO_LARGE
- See Also:
- Constant Field Values
SC_REQUEST_URI_TOO_LONG
public static final int SC_REQUEST_URI_TOO_LONG
- See Also:
- Constant Field Values
SC_UNSUPPORTED_MEDIA_TYPE
public static final int SC_UNSUPPORTED_MEDIA_TYPE
- See Also:
- Constant Field Values
SC_REQUESTED_RANGE_NOT_SATISFIABLE
public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE
- See Also:
- Constant Field Values
SC_EXPECTATION_FAILED
public static final int SC_EXPECTATION_FAILED
- See Also:
- Constant Field Values
SC_INTERNAL_SERVER_ERROR
public static final int SC_INTERNAL_SERVER_ERROR
- See Also:
- Constant Field Values
SC_NOT_IMPLEMENTED
public static final int SC_NOT_IMPLEMENTED
- See Also:
- Constant Field Values
SC_BAD_GATEWAY
public static final int SC_BAD_GATEWAY
- See Also:
- Constant Field Values
SC_SERVICE_UNAVAILABLE
public static final int SC_SERVICE_UNAVAILABLE
- See Also:
- Constant Field Values
SC_GATEWAY_TIMEOUT
public static final int SC_GATEWAY_TIMEOUT
- See Also:
- Constant Field Values
SC_HTTP_VERSION_NOT_SUPPORTED
public static final int SC_HTTP_VERSION_NOT_SUPPORTED
- See Also:
- Constant Field Values
| Constructor Detail |
HttpServletResponseSimulator
public HttpServletResponseSimulator()
| Method Detail |
addCookie
public void addCookie(javax.servlet.http.Cookie cookie)
- Add a cookie to this response, which will then be stored in the browser.
- Specified by:
addCookiein interfacejavax.servlet.http.HttpServletResponse
findCookie
public javax.servlet.http.Cookie findCookie(java.lang.String name)
- Returns a cookie with a given, or null if this cookie has
not been added to the repsonse.
addDateHeader
public void addDateHeader(java.lang.String name, long date)
- This method is not supported.
- Specified by:
addDateHeaderin interfacejavax.servlet.http.HttpServletResponse
addHeader
public void addHeader(java.lang.String name, java.lang.String value)
- Adds a response header with the given name and value.
- Specified by:
addHeaderin interfacejavax.servlet.http.HttpServletResponse
getHeader
public java.lang.String getHeader(java.lang.String name)
- Returns a given header field, or null if this header
has not been set.
addIntHeader
public void addIntHeader(java.lang.String name, int value)
- Adds a response header with the given name and integer value.
- Specified by:
addIntHeaderin interfacejavax.servlet.http.HttpServletResponse
containsHeader
public boolean containsHeader(java.lang.String name)
- returns true if a header with the given name
has already been set
- Specified by:
containsHeaderin interfacejavax.servlet.http.HttpServletResponse
encodeRedirectUrl
public java.lang.String encodeRedirectUrl(java.lang.String url)
- Returns the given URL unmodified
- Specified by:
encodeRedirectUrlin interfacejavax.servlet.http.HttpServletResponse
encodeRedirectURL
public java.lang.String encodeRedirectURL(java.lang.String url)
- Returns the given URL unmodified.
- Specified by:
encodeRedirectURLin interfacejavax.servlet.http.HttpServletResponse
encodeUrl
public java.lang.String encodeUrl(java.lang.String url)
- Returns the given URL unmodified.
- Specified by:
encodeUrlin interfacejavax.servlet.http.HttpServletResponse
encodeURL
public java.lang.String encodeURL(java.lang.String url)
- Returns the given URL unmodified
- Specified by:
encodeURLin interfacejavax.servlet.http.HttpServletResponse
flushBuffer
public void flushBuffer()
throws java.io.IOException
- This method is not supported.
- Specified by:
flushBufferin interfacejavax.servlet.ServletResponse
getBufferSize
public int getBufferSize()
- This method is not supported.
- Specified by:
getBufferSizein interfacejavax.servlet.ServletResponse
getCharacterEncoding
public java.lang.String getCharacterEncoding()
- This method is not supported.
- Specified by:
getCharacterEncodingin interfacejavax.servlet.ServletResponse
getLocale
public java.util.Locale getLocale()
- Returns the locale assigned to the response.
- Specified by:
getLocalein interfacejavax.servlet.ServletResponse
getOutputStream
public javax.servlet.ServletOutputStream getOutputStream() throws java.io.IOException
- Returns a javax.servlet.ServletOutputStream suitable for writing binary
data in the response. The servlet container does not encode the
binary data.
Calling flush() on the ServletOutputStream commits the response. Either this method or
getWriter()55 may be called to write the body, not both.- Specified by:
getOutputStreamin interfacejavax.servlet.ServletResponse
getWriter
public java.io.PrintWriter getWriter() throws java.io.IOException
- Returns a
PrintWriterobject that can send character text to the client. The character encoding used is the one specified in thecharset=property of thesetContentType(java.lang.String)55 method, which must be called before calling this method for the charset to take effect.If necessary, the MIME type of the response is modified to reflect the character encoding used.
Calling flush() on the PrintWriter commits the response.
Either this method or
getOutputStream()55 may be called to write the body, not both.- Specified by:
getWriterin interfacejavax.servlet.ServletResponse
getWriterBuffer
public java.lang.StringBuffer getWriterBuffer()
- Use this method to pick up the string buffer which will hold
the contents of the string buffer. You can then
write your test case to examine the contents of this
buffer and match it against an expected output.
isCommitted
public boolean isCommitted()
- Description copied from interface:
javax.servlet.ServletResponse - Returns a boolean indicating if the response has been
committed. A committed response has already had its status
code and headers written.
- Specified by:
isCommittedin interfacejavax.servlet.ServletResponse
setIsCommitted
public void setIsCommitted(boolean isCommitted)
reset
public void reset()
- Reinitializes all local variables.
Note, in most servlet containers, you may get an
IllegalStateException if you call this method
after committing the response.
That behavior is not replicated here.
- Specified by:
resetin interfacejavax.servlet.ServletResponse
resetBuffer
public void resetBuffer()
- This method is not supported.
- Specified by:
resetBufferin interfacejavax.servlet.ServletResponse
sendError
public void sendError(int sc)
throws java.io.IOException
- Sends an error response to the client using the specified
status clearing the buffer. This method always throws
an AssertionFailedError with the corresponding error
number.
- Specified by:
sendErrorin interfacejavax.servlet.http.HttpServletResponse
sendError
public void sendError(int sc,
java.lang.String msg)
throws java.io.IOException
- Sends an error response to the client using the specified
status clearing the buffer. This method always throws
an AssertionFailedError with the corresponding error
number and descriptive text.
- Specified by:
sendErrorin interfacejavax.servlet.http.HttpServletResponse
sendRedirect
public void sendRedirect(java.lang.String location) throws java.io.IOException
- Resets the response and sets the appropriate redirect headers.
- Specified by:
sendRedirectin interfacejavax.servlet.http.HttpServletResponse
setBufferSize
public void setBufferSize(int size)
- This method is not supported.
- Specified by:
setBufferSizein interfacejavax.servlet.ServletResponse
setContentLength
public void setContentLength(int len)
- Sets the length of the content body in the response
In HTTP servlets, this method sets the HTTP Content-Length header.
- Specified by:
setContentLengthin interfacejavax.servlet.ServletResponse
getContentLength
public int getContentLength()
- returns the content length previously set in setContentLength()
setContentType
public void setContentType(java.lang.String type)
- Sets the content type of the response being sent to
the client. The content type may include the type of character
encoding used, for example,
text/html; charset=ISO-8859-4.If obtaining a
PrintWriter, this method should be called first.- Specified by:
setContentTypein interfacejavax.servlet.ServletResponse
getContentType
public java.lang.String getContentType()
- returns the content type previously set in setContentType()
- Specified by:
getContentTypein interfacejavax.servlet.ServletResponse
setDateHeader
public void setDateHeader(java.lang.String name, long date)
- This method is not supported.
- Specified by:
setDateHeaderin interfacejavax.servlet.http.HttpServletResponse
setHeader
public void setHeader(java.lang.String name, java.lang.String value)
- adds the name/value pair to the headers
- Specified by:
setHeaderin interfacejavax.servlet.http.HttpServletResponse
removeHeader
public void removeHeader(java.lang.String name)
- Removes a given header
setIntHeader
public void setIntHeader(java.lang.String name, int value)
- Adds the given name/value pair to the headers collection.
- Specified by:
setIntHeaderin interfacejavax.servlet.http.HttpServletResponse
setLocale
public void setLocale(java.util.Locale loc)
- Sets the locale of the response, setting the headers (including the
Content-Type's charset) as appropriate. This method should be called
before a call to
getWriter()55 . By default, the response locale is the default locale for the server.- Specified by:
setLocalein interfacejavax.servlet.ServletResponse
setOutputStream
public void setOutputStream(java.io.OutputStream out)
- The default action of calling the
getOutputStreammethod is to return ajavax.servlet.ServletOutputStreamobject that sends the data toSystem.out. If you don't want the output sent toSystem.outyou can use this method to set where the output will go. Please note, subsequent calls togetOutputStreamwill reset the output path toSystem.out. This prevents the OutputStream returned by calling getOutputStream from writing to a closed stream
setStatus
public void setStatus(int sc)
- Sets the given status code.
- Specified by:
setStatusin interfacejavax.servlet.http.HttpServletResponse
setStatus
public void setStatus(int sc,
java.lang.String sm)
- Sets the given status and an associated message.
- Specified by:
setStatusin interfacejavax.servlet.http.HttpServletResponse
getStatusCode
public int getStatusCode()
- Returns the status code for this response, which is useful for testing expected errors.
setCharacterEncoding
public void setCharacterEncoding(java.lang.String charEncoding)
- Description copied from interface:
javax.servlet.ServletResponse - Sets the character encoding (MIME charset) of the response
being sent to the client, for example, to UTF-8.
If the character encoding has already been set by
ServletResponse.setContentType(java.lang.String)>
ServletResponse.setContentType(java.lang.String)55 or ServletResponse.setLocale(java.util.Locale)>ServletResponse.setLocale(java.util.Locale)55 , this method overrides it. Calling ServletResponse.setContentType(java.lang.String)>ServletResponse.setContentType(java.lang.String)55 with theStringoftext/htmland calling this method with theStringofUTF-8is equivalent with callingsetContentTypewith theStringoftext/html; charset=UTF-8.This method can be called repeatedly to change the character encoding. This method has no effect if it is called after
getWriterhas been called or after the response has been committed.Containers must communicate the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the character encoding is communicated as part of the
Content-Typeheader for text media types. Note that the character encoding cannot be communicated via HTTP headers if the servlet does not specify a content type; however, it is still used to encode text written via the servlet response's writer.- Specified by:
setCharacterEncodingin interfacejavax.servlet.ServletResponse
getMessage
public java.lang.String getMessage()
|
|||||||||
| Home >> All >> [ servletunit overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
servletunit.HttpServletResponseSimulator