Class MockResponse
- All Implemented Interfaces:
Response
Response implementation that is suitable for testing a
web application outside a servlet container.- Since:
- 1.0
-
Field Summary
Fields inherited from class rife.engine.AbstractResponse
gzipByteOutputStream_, gzipOutputStream_, lastElement_, outputStream_, responseOutputStream_, textBuffer_, textBufferEnabled_ -
Method Summary
Modifier and TypeMethodDescriptionprotected OutputStreamThis method needs to be implemented by the extending back-end class and will be called byAbstractResponseduring the RIFE2-specific additional behaviour.protected void_setContentType(String contentType) This method needs to be implemented by the extending back-end class and will be called byAbstractResponseduring the RIFE2-specific additional behaviour.voidvoidaddDateHeader(String name, long date) voidvoidaddIntHeader(String name, int integer) booleancontainsHeader(String name) byte[]getBytes()Retrieves an array of all the bytes that have been written to this response.intRetrieves the content type that was explicitly set for this response.longgetDateHeader(String name) Returns the value of the specified response header as a long value that represents a Date object.Returns the value of the specified response header as aString.Returns the value of the specified response header as aString.getHeaders(String name) Returns all the values of the specified response header as anCollectionofStringobjects.Retrieves the underlyingHttpServletResponse.intgetIntHeader(String name) Returns the value of the specified response header as anint.Retrieves the list of cookies that have been added in this response.Retrieves the content of this response as parsed HTML.Returns the error reason of this response.intReturns the status code of this response.Retrieves the template instance that was printed to the response.getText()Retrieves the content of this response as text.voidPrints the content of a template to the request text output.voidremoveHeader(String name) Removes a response header with the given name.voidsendError(int statusCode) voidvoidsendRedirect(String location) voidsetContentLength(int length) voidsetDateHeader(String name, long date) voidvoidsetIntHeader(String name, int value) voidvoidsetStatus(int statusCode) xpathBoolean(String expression) Evaluate an XPath expression in the context of the response text and return the result as a boolean.xpathBoolean(String expression, Object context) Evaluate an XPath expression in the provided context object and return the result as a boolean.Evaluate an XPath expression in the context of the response text and return the result as a DOM node.Evaluate an XPath expression in the provided context object and return the result as a DOM node.xpathNodeSet(String expression) Evaluate an XPath expression in the context of the response text and return the result as a list of DOM nodes.xpathNodeSet(String expression, Object context) Evaluate an XPath expression in the provided context object and return the result as a list of DOM nodes.xpathNumber(String expression) Evaluate an XPath expression in the context of the response text and return the result as a number.xpathNumber(String expression, Object context) Evaluate an XPath expression in the provided context object and return the result as a number.xpathString(String expression) Evaluate an XPath expression in the context of the response text and return the result as a string.xpathString(String expression, Object context) Evaluate an XPath expression in the provided context object and return the result as a string.Methods inherited from class rife.engine.AbstractResponse
clearBuffer, close, enableTextBuffer, flush, getLastElement, getOutputStream, getRequest, isContentTypeSet, isTextBufferEnabled, print, print, setContentType, setLastElement
-
Method Details
-
getBytes
public byte[] getBytes()Retrieves an array of all the bytes that have been written to this response.- Returns:
- an array of bytes with the response content
- Since:
- 1.0
- See Also:
-
getText
Retrieves the content of this response as text.- Returns:
- the response content as text
- Since:
- 1.0
- See Also:
-
getTemplate
Retrieves the template instance that was printed to the response.- Returns:
- the template instance that was printed to the response; or
nullof no template was printed to the response - Since:
- 1.0
- See Also:
-
getParsedHtml
Retrieves the content of this response as parsed HTML.- Returns:
- the response content as parsed HTML
- Since:
- 1.0
- See Also:
-
getContentType
Description copied from interface:ResponseRetrieves the content type that was explicitly set for this response.- Specified by:
getContentTypein interfaceResponse- Overrides:
getContentTypein classAbstractResponse- Returns:
- the content type as a String; or
nullif the content type wasn't set - See Also:
-
xpathNodeSet
Evaluate an XPath expression in the context of the response text and return the result as a list of DOM nodes.More information about XPath can be found in the original specification or in this tutorial.
- Returns:
- the result as a
NodeList - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNode
Evaluate an XPath expression in the context of the response text and return the result as a DOM node.- Returns:
- the result as a
Node - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathString
Evaluate an XPath expression in the context of the response text and return the result as a string.- Returns:
- the result as a
Node - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathBoolean
Evaluate an XPath expression in the context of the response text and return the result as a boolean.- Returns:
- the result as a
Node - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNumber
Evaluate an XPath expression in the context of the response text and return the result as a number.- Returns:
- the result as a
Node - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNodeSet
Evaluate an XPath expression in the provided context object and return the result as a list of DOM nodes.More information about XPath can be found in the original specification or in this tutorial.
- Returns:
- the result as a
NodeList - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNode
Evaluate an XPath expression in the provided context object and return the result as a DOM node.- Returns:
- the result as a
Node - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathString
Evaluate an XPath expression in the provided context object and return the result as a string.- Returns:
- the result as a
Node - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathBoolean
Evaluate an XPath expression in the provided context object and return the result as a boolean.- Returns:
- the result as a
Node - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
xpathNumber
Evaluate an XPath expression in the provided context object and return the result as a number.- Returns:
- the result as a
Node - Throws:
XPathExpressionException- if expression cannot be evaluated.- Since:
- 1.0
- See Also:
-
print
Description copied from interface:ResponsePrints the content of a template to the request text output.- Specified by:
printin interfaceResponse- Overrides:
printin classAbstractResponse- Parameters:
template- the template that will be printed- Throws:
EngineException- if an error occurs during the output of the template content- See Also:
-
_setContentType
Description copied from class:AbstractResponseThis method needs to be implemented by the extending back-end class and will be called byAbstractResponseduring the RIFE2-specific additional behaviour. It behaves exactly like itscounter-part in the Response interface.- Specified by:
_setContentTypein classAbstractResponse- See Also:
-
getCharacterEncoding
Description copied from interface:Response -
setContentLength
public void setContentLength(int length) Description copied from interface:Response -
getContentLength
public int getContentLength() -
sendRedirect
Description copied from interface:Response -
_getOutputStream
Description copied from class:AbstractResponseThis method needs to be implemented by the extending back-end class and will be called byAbstractResponseduring the RIFE2-specific additional behaviour. It behaves exactly like itscounter-part in the Request interface.- Specified by:
_getOutputStreamin classAbstractResponse- See Also:
-
addCookie
Description copied from interface:Response -
getNewCookieNames
Retrieves the list of cookies that have been added in this response.- Returns:
- the list of added cookies; or
an empty list if no cookies have been added
- Since:
- 1.0
-
getDateHeader
Returns the value of the specified response header as a long value that represents a Date object. Use this method with headers that contain dates.The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case-insensitive.
If the response did not have a header of the specified name, this method returns
-1. If the header can't be converted to a date, the method throws anIllegalArgumentException.- Parameters:
name- the name of the header- Returns:
- a
longvalue representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT; or-1if the named header was not included with the response - Throws:
IllegalArgumentException- if the header value can't be converted to a date- Since:
- 1.0
-
getHeader
Returns the value of the specified response header as aString. If the response did not include a header of the specified name, this method returnsnull. The header name is case-insensitive. You can use this method with any response header.- Parameters:
name- the name of the header- Returns:
- a
Stringcontaining the value of the response header; ornullif the response does not have a header of that name - Since:
- 1.0
-
getHeaderNames
Returns the value of the specified response header as aString. If the response did not include a header of the specified name, this method returnsnull. The header name is case-insensitive. You can use this method with any response header.- Returns:
- a
Collectionof all the header names sent with this response; orif the response has no headers, an empty
Collection - Since:
- 1.0
-
getHeaders
Returns all the values of the specified response header as anCollectionofStringobjects.If the response did not include any headers of the specified name, this method returns an empty
Collection. The header name is case-insensitive. You can use this method with any response header.- Parameters:
name- the name of the header- Returns:
- a
Collectioncontaining the values of the response header; orif the response does not have any headers of that name return an empty
Collection - Since:
- 1.0
-
getIntHeader
Returns the value of the specified response header as anint. If the response does not have a header of the specified name, this method returns-1. If the header cannot be converted to aninteger, this method throws aNumberFormatException.The header name is case-insensitive.
- Parameters:
name- the name of the header- Returns:
- an
integerexpressing the value of the response header; or-1if the response doesn't have a header of this name - Throws:
NumberFormatException- if the header value can't be converted to anint- Since:
- 1.0
-
addHeader
Description copied from interface:Response -
addDateHeader
Description copied from interface:Response -
addIntHeader
Description copied from interface:Response -
containsHeader
Description copied from interface:Response -
setDateHeader
Description copied from interface:Response -
setHeader
Description copied from interface:Response -
setIntHeader
Description copied from interface:Response -
removeHeader
Removes a response header with the given name.- Parameters:
name- the name of the header to remove- Since:
- 1.0
-
getStatus
public int getStatus()Returns the status code of this response.- Returns:
- an
integerexpressing the status code of this response - Since:
- 1.0
-
getReason
Returns the error reason of this response.- Returns:
- an
Stringexpressing the reason of this response error - Since:
- 1.0
-
setStatus
public void setStatus(int statusCode) Description copied from interface:Response -
sendError
Description copied from interface:Response- Throws:
EngineException
-
sendError
Description copied from interface:Response- Throws:
EngineException
-
encodeURL
Description copied from interface:Response -
setLocale
Description copied from interface:Response -
getLocale
Description copied from interface:Response -
getWriter
Description copied from interface:Response- Throws:
IOException
-
getHttpServletResponse
Description copied from interface:ResponseRetrieves the underlyingHttpServletResponse.- Returns:
- the underlying
HttpServletResponseinstance; ornullif this response isn't backed byHttpServletResponse
-