Class SiteResponse
- All Implemented Interfaces:
Response
- Direct Known Subclasses:
MockResponse
SiteRequest.
Without a listener, the content is kept in memory, and you can get it
with getBytes() and getText() once the request has been
handled. With a SiteResponseListener, the content is given to the
listener while it's being written, so that it isn't kept.
getHttpHeaders() provides the headers as they would go over
HTTP, with a Set-Cookie header for each cookie.
- Since:
- 1.11.0
- See Also:
-
Field Summary
Fields inherited from class rife.engine.AbstractResponse
contentType_, gzipByteOutputStream_, gzipOutputStream_, lastElement_, outputStream_, responseOutputStream_, textBuffer_, textBufferEnabled_ -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSiteResponse(SiteRequest request) Creates the response of a request. -
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 length that was set.Retrieves the content type of the response, as it's set in theContent-Typeheader.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.Retrieves the names of the headers that were set, without the cookies.getHeaders(String name) Returns all the values of the specified response header as aCollectionofStringobjects.Retrieves the headers of this response as they would go over HTTP, with aSet-Cookieheader for each cookie.Retrieves the underlying servlet response, which doesn't exist when a site is run by aSiteRunner.intgetIntHeader(String name) Returns the value of the specified response header as anint.Retrieves the cookies that were added to this response.Returns the error reason of this response, as it was given withsendError(int, String).Retrieves the headers of this response with one value for each name, which is what the responses of web views on iOS and Android take.intReturns the status code of this response.getText()Retrieves the content of this response as text, with the character encoding of the response.booleanIndicates whether this response is a detached event stream, which stays open after its element returned.booleanIndicates whether this response has ended, either normally, with a failure, or because its request was cancelled.booleanIndicates whether the request was handled by the site or by its static files.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) Methods inherited from class rife.engine.AbstractResponse
clearBuffer, close, enableTextBuffer, flush, getLastElement, getOutputStream, getRequest, isContentTypeSet, isTextBufferEnabled, markOutputStarted, print, print, print, setContentType, setLastElement, sseEventSentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface rife.engine.Response
printBlock
-
Constructor Details
-
SiteResponse
Creates the response of a request.- Parameters:
request- the request of the response- Since:
- 1.11.0
-
-
Method Details
-
isHandled
public boolean isHandled()Indicates whether the request was handled by the site or by its static files.When no route handled the request and no static file was found, the status is
404and this isfalse, so that your application can still answer the request in its own way. When an element sends a404itself, this remainstrue.- Returns:
trueif the request was handled; orfalseotherwise- Since:
- 1.11.0
-
isFinished
public boolean isFinished()Indicates whether this response has ended, either normally, with a failure, or because its request was cancelled.- Returns:
trueif the response has ended; orfalseotherwise- Since:
- 1.11.0
-
isDetached
public boolean isDetached()Indicates whether this response is a detached event stream, which stays open after its element returned.- Returns:
trueif the response is a detached event stream; orfalseotherwise- Since:
- 1.11.0
-
getBytes
public byte[] getBytes()Retrieves an array of all the bytes that have been written to this response.For a
HEADrequest this is empty, since a servlet container doesn't send the content of the response. It's also empty when the response is given to a listener, since the content isn't kept then.- Returns:
- an array of bytes with the response content
- Since:
- 1.11.0
- See Also:
-
getText
Retrieves the content of this response as text, with the character encoding of the response.- Returns:
- the response content as text
- Since:
- 1.11.0
- See Also:
-
getContentType
Retrieves the content type of the response, as it's set in theContent-Typeheader.- Specified by:
getContentTypein interfaceResponse- Overrides:
getContentTypein classAbstractResponse- Returns:
- the content type; or
nullif it wasn't set - Since:
- 1.11.0
- 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()Retrieves the content length that was set.- Returns:
- the content length; or
-1if it wasn't set - Since:
- 1.11.0
-
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 -
getNewCookies
Retrieves the cookies that were added to this response. A later cookie with the same name, domain and path replaces an earlier one.- Returns:
- the cookies of the response
- Since:
- 1.11.0
-
getHttpHeaders
Retrieves the headers of this response as they would go over HTTP, with aSet-Cookieheader for each cookie. The header names are case-insensitive.When there's no listener, the
Content-Lengthheader is also provided once the response is finished.- Returns:
- the names of the headers with their values
- Since:
- 1.11.0
-
getSingleValueHttpHeaders
Retrieves the headers of this response with one value for each name, which is what the responses of web views on iOS and Android take. The values of a header are joined with a comma, like HTTP allows, and the header names are case-insensitive.The
Set-Cookieheaders are left out, since they can't be joined that way. A web view app keeps its cookies with aSiteCookieJarinstead.- Returns:
- the names of the headers with their value
- Since:
- 1.11.0
- See Also:
-
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.11.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.11.0
-
getHeaderNames
Retrieves the names of the headers that were set, without the cookies.- Returns:
- the header names
- Since:
- 1.11.0
- See Also:
-
getHeaders
Returns all the values of the specified response header as aCollectionofStringobjects.If the response did not include any headers of the specified name, this method returns an empty
Collection. The header name is case-insensitive.- 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.11.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.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:
IllegalArgumentException- if the header value can't be converted to anint- Since:
- 1.11.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.11.0
-
getStatus
public int getStatus()Returns the status code of this response.- Returns:
- an
integerexpressing the status code of this response - Since:
- 1.11.0
-
getReason
Returns the error reason of this response, as it was given withsendError(int, String).- Returns:
- a
Stringexpressing the reason of this response error; ornullif there was none - Since:
- 1.11.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
Retrieves the underlying servlet response, which doesn't exist when a site is run by aSiteRunner.- Returns:
null- Since:
- 1.11.0
-