public interface IResponseRequestContextAddon<R extends IRequestContext<?>>
| Modifier and Type | Method and Description |
|---|---|
IResponseRequestContextAddon<R> |
addHeaderValue(String name,
String value)
Adds a value to a response header.
|
IResponseRequestContextAddon<R> |
addHeaderValues(String name,
List<String> values)
Adds a list of values to a response header.
|
void |
end()
Flushes everything and closes the response.
|
void |
flush()
Flushes the current response.
|
void |
flush(boolean end)
Flushes the current response.
|
String |
getCharactersCharsetName()
The charset to use to convert characters to bytes.
|
String |
getContentType()
The current
Content-Type sent or to be send. |
GzipOption |
getGzipOption()
The currently set gzip options.
|
List<String> |
getHeader(String name)
The values of a specific response header.
|
String |
getHeaderFirst(String name)
The first value of a specific header.
|
Map<String,List<String>> |
getHeaders()
The currently set response headers.
|
int |
getStatusCode()
The current
status code sent or to be send. |
byte[] |
getUnsentBytes()
Gets the current unsent bytes (AKA the buffer).
|
String |
getUnsentCharacters()
Gets the current unsent characters (AKA the buffer), using the
UTF-8 encoding. |
String |
getUnsentCharacters(String encoding)
Gets the current unsent characters (AKA the buffer), using the
specified encoding.
|
boolean |
isClosed()
Is the response closed? If so, nothing more can be sent...
|
boolean |
isHeadersSent()
Are the response headers sent? If this is the case,
then the headers can't be changed anymore.
|
void |
redirect(String newUrl,
boolean permanently)
Sets a redirection header.
|
void |
redirect(String newUrl,
int specific3xxCode)
Sets the redirection headers with a specified
3xx status code. |
IResponseRequestContextAddon<R> |
removeHeader(String name)
Removes an header by its name.
|
IResponseRequestContextAddon<R> |
resetBuffer()
Clears the buffer (the unsent buffer, of course).
|
IResponseRequestContextAddon<R> |
resetEverything()
Clears the buffer (the unsent buffer, of course), resets the cookies,
the headers, the
Content-Type and
sets the status code back to 200. |
void |
sendBytes(byte[] bytes)
Sends some
bytes, without flushing. |
void |
sendBytes(byte[] bytes,
String contentType)
Sends some
bytes using the specified Content-Type,
without flushing. |
void |
sendBytes(byte[] bytes,
String contentType,
boolean flush)
Sends some
bytes using the specified Content-Type and flushes,
if specified. |
void |
sendCharacters(String content)
Sends a String, using the encoding returned by
getCharactersCharsetName,
without flushing. |
void |
sendCharacters(String content,
String contentType)
Sends a String, using the encoding returned by
getCharactersCharsetName and
using the specified Content-Type, without flushing. |
void |
sendCharacters(String content,
String contentType,
boolean flush)
Sends a String, using the encoding returned by
getCharactersCharsetName
and using the specified Content-Type. |
void |
sendHtml(String html)
Sends a String as
text/html, UTF-8 encoded, without flushing. |
void |
sendHtml(String html,
boolean flush)
Sends a String as
text/html, UTF-8 encoded,
and flushes, if specified. |
void |
sendHtmlParse(String html,
Map<String,Object> params)
Parses the given String using the
ITemplatingEngine and
the given parameters, then sends the result as text/html,
UTF-8 encoded, without flushing. |
void |
sendHtmlParse(String html,
Map<String,Object> params,
boolean flush)
Parses the given String using the
ITemplatingEngine and
the given parameters, then sends the result as text/html,
UTF-8 encoded, and flushes, if specified. |
void |
sendHtmlTemplate(String templatePath,
boolean isClasspathPath,
Map<String,Object> params)
Finds the
HTML template using the ITemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, without flushing. |
void |
sendHtmlTemplate(String templatePath,
boolean isClasspathPath,
Map<String,Object> params,
boolean flush)
Finds the
HTML template using the ITemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, and flushes, if specified. |
void |
sendHtmlTemplate(String templatePath,
Map<String,Object> params)
Finds the
HTML template using the ITemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, without flushing. |
void |
sendHtmlTemplate(String templatePath,
Map<String,Object> params,
boolean flush)
Finds the
HTML template using the ITemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, and flushes, if specified. |
void |
sendJson(String jsonString)
Sends a
Json String using the application/json Content-Type,
without flushing. |
void |
sendJson(String jsonString,
boolean flush)
Sends a
Json String using the application/json Content-Type,
and flushes, if specified. |
void |
sendJsonObj(Object obj)
Serializes the object to
Json and sends as application/json, without flushing. |
void |
sendJsonObj(Object obj,
boolean flush)
Serializes the object to
Json, sends as application/json,
and flushes, if specified. |
void |
sendParse(String content,
String contentType,
Map<String,Object> params)
Parses the given String using the
ITemplatingEngine and
the given parameters, then sends the result using the specified
Content-Type, without flushing. |
void |
sendParse(String content,
String contentType,
Map<String,Object> params,
boolean flush)
Parses the given String using the
ITemplatingEngine and
the given parameters, then sends the result using the specified
Content-Type, and flushes, if specified. |
void |
sendPlainText(String string)
Sends a String as
text/plain, UTF-8 encoded, without flushing. |
void |
sendPlainText(String string,
boolean flush)
Sends a String as
text/plain, UTF-8 encoded,
and flushes, if specified. |
void |
sendTemplate(String templatePath,
boolean isClasspathPath,
String contentType,
Map<String,Object> params)
Finds the specified template using the
ITemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, without flushing. |
void |
sendTemplate(String templatePath,
boolean isClasspathPath,
String contentType,
Map<String,Object> params,
boolean flush)
Finds the specified template using the
ITemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, and flushes, if specified. |
void |
sendTemplate(String templatePath,
String contentType,
Map<String,Object> params)
Finds the specified template using the
ITemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, without flushing. |
void |
sendTemplate(String templatePath,
String contentType,
Map<String,Object> params,
boolean flush)
Finds the specified template using the
ITemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, and flushes, if specified. |
void |
sendXml(String xml)
Sends some
XML using the application/xml Content-Type,
without flushing. |
void |
sendXml(String xml,
boolean flush)
Sends some
XML using the application/xml Content-Type,
and flushes, if specified. |
void |
sendXmlObj(Object obj)
Serializes the object to
XML and sends as application/xml, without flushing. |
void |
sendXmlObj(Object obj,
boolean flush)
Serializes the object to
XML, sends as application/xml, and flushes, if specified. |
IResponseRequestContextAddon<R> |
setCacheSeconds(int cacheSeconds)
Adds caching headers.
|
IResponseRequestContextAddon<R> |
setCacheSeconds(int cacheSeconds,
boolean isPrivateCache)
Adds caching headers for the specified number
of seconds.
|
IResponseRequestContextAddon<R> |
setCharactersCharsetName(String name)
Sets the charset to use to convert characters to bytes.
|
IResponseRequestContextAddon<R> |
setContentType(String responseContentType)
The
Content-Type header to use for the response. |
IResponseRequestContextAddon<R> |
setGzipOption(GzipOption gzipOption)
Enable or disable gzipping of the response.
|
IResponseRequestContextAddon<R> |
setHeader(String name,
List<String> values)
Set multiple values to a response header.
|
IResponseRequestContextAddon<R> |
setHeader(String name,
String value)
Set the value to a response header.
|
IResponseRequestContextAddon<R> |
setStatusCode(int statusCode)
Sets the response's
status code to use. |
boolean isClosed()
void end()
route handlers will still
be called).boolean isHeadersSent()
void sendBytes(byte[] bytes)
bytes, without flushing.void sendBytes(byte[] bytes,
String contentType)
bytes using the specified Content-Type,
without flushing.void sendBytes(byte[] bytes,
String contentType,
boolean flush)
bytes using the specified Content-Type and flushes,
if specified.
Note that once the response is flushed, no header can be added or changed anymore.String getCharactersCharsetName()
"UTF-8".IResponseRequestContextAddon<R> setCharactersCharsetName(String name)
"UTF-8".
Make sure you use the same charset here
than the one that is sent as the "Content-Type" header (which
is also "UTF-8" by default, if you send data using
sendPlainText(), sendHtml() or sendJson()).void sendCharacters(String content)
getCharactersCharsetName,
without flushing.void sendCharacters(String content, String contentType)
getCharactersCharsetName and
using the specified Content-Type, without flushing.void sendCharacters(String content, String contentType, boolean flush)
getCharactersCharsetName
and using the specified Content-Type. Flushes the response, if specified.
Note that once the response is flushed, no header can be added or changed anymore.void sendPlainText(String string)
text/plain, UTF-8 encoded, without flushing.void sendPlainText(String string, boolean flush)
text/plain, UTF-8 encoded,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.void sendJson(String jsonString)
Json String using the application/json Content-Type,
without flushing.
Synonym of : sendCharacters(jsonString, "application/json")
void sendJson(String jsonString, boolean flush)
Json String using the application/json Content-Type,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.
Synonym of : sendCharacters(jsonString, "application/json", flush)
void sendJsonObj(Object obj)
Json and sends as application/json, without flushing.void sendJsonObj(Object obj, boolean flush)
Json, sends as application/json,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.void sendXml(String xml)
XML using the application/xml Content-Type,
without flushing.
Synonym of : sendCharacters(xml, "application/xml")
void sendXml(String xml, boolean flush)
XML using the application/xml Content-Type,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.
Synonym of : sendCharacters(xml, "application/xml", flush)
void sendXmlObj(Object obj)
XML and sends as application/xml, without flushing.void sendXmlObj(Object obj, boolean flush)
XML, sends as application/xml, and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.void sendHtml(String html)
text/html, UTF-8 encoded, without flushing.void sendHtml(String html, boolean flush)
text/html, UTF-8 encoded,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.void sendHtmlParse(String html, Map<String,Object> params)
ITemplatingEngine and
the given parameters, then sends the result as text/html,
UTF-8 encoded, without flushing.void sendHtmlParse(String html, Map<String,Object> params, boolean flush)
ITemplatingEngine and
the given parameters, then sends the result as text/html,
UTF-8 encoded, and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.void sendParse(String content, String contentType, Map<String,Object> params)
ITemplatingEngine and
the given parameters, then sends the result using the specified
Content-Type, without flushing.void sendParse(String content, String contentType, Map<String,Object> params, boolean flush)
ITemplatingEngine and
the given parameters, then sends the result using the specified
Content-Type, and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.void sendHtmlTemplate(String templatePath, Map<String,Object> params)
HTML template using the ITemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, without flushing.templatePath - must be a classpath's relative path.void sendHtmlTemplate(String templatePath, Map<String,Object> params, boolean flush)
HTML template using the ITemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.templatePath - must be a classpath's relative path.void sendTemplate(String templatePath, String contentType, Map<String,Object> params)
ITemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, without flushing.templatePath - must be a classpath's relative path.void sendTemplate(String templatePath, String contentType, Map<String,Object> params, boolean flush)
ITemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.templatePath - must be a classpath's relative path.void sendHtmlTemplate(String templatePath, boolean isClasspathPath, Map<String,Object> params)
HTML template using the ITemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, without flushing.isClasspathPath - if true, the 'templatePath' is considered as
a classpath's relative path. If false, it is considered as an absolute file
system path.void sendHtmlTemplate(String templatePath, boolean isClasspathPath, Map<String,Object> params, boolean flush)
HTML template using the ITemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.isClasspathPath - if true, the 'templatePath' is considered as
a classpath's relative path. If false, it is considered as an absolute file
system path.void sendTemplate(String templatePath, boolean isClasspathPath, String contentType, Map<String,Object> params)
ITemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, without flushing.isClasspathPath - if true, the 'templatePath' is considered as
a classpath's relative path. If false, it is considered as an absolute file
system path.void sendTemplate(String templatePath, boolean isClasspathPath, String contentType, Map<String,Object> params, boolean flush)
ITemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.isClasspathPath - if true, the 'templatePath' is considered as
a classpath's relative path. If false, it is considered as an absolute file
system path.void flush()
status code and Content-Type will be added.
Note that once the response is flushed, no header can be added or changed anymore.void flush(boolean end)
status code and content-type will be added.
Note that once the response is flushed, no header can be added or changed anymore.end - If true, the exchange will be closed and no more data
can be sent.IResponseRequestContextAddon<R> setStatusCode(int statusCode)
status code to use. Uses 200
by default.
Note that this status code can be changed automatically
if an exception is thrown.int getStatusCode()
status code sent or to be send.IResponseRequestContextAddon<R> setContentType(String responseContentType)
Content-Type header to use for the response. Most
sendXXX() methods will set this automatically.String getContentType()
Content-Type sent or to be send.void redirect(String newUrl, boolean permanently)
RedirectException instead if you want to redirect the user
immediately.permanently - If true, a
301 header will be sent. If false,
302 will be sent.void redirect(String newUrl, int specific3xxCode)
3xx status code.
This will NOT close the response and will NOT skip the remaining handlers!
Throw a RedirectException instead if you want to redirect the user
immediately.IResponseRequestContextAddon<R> addHeaderValue(String name, String value)
null, it won't be added.IResponseRequestContextAddon<R> addHeaderValues(String name, List<String> values)
null, nothing will be added.IResponseRequestContextAddon<R> setHeader(String name, String value)
null, the header will be
removed (same behavior as removeHeader(String name))IResponseRequestContextAddon<R> setHeader(String name, List<String> values)
null or empty, the header will be
removed (same behavior as removeHeader(String name))IResponseRequestContextAddon<R> removeHeader(String name)
Map<String,List<String>> getHeaders()
TreeMap with case insensitive keys.List<String> getHeader(String name)
String getHeaderFirst(String name)
null if the header is not found.IResponseRequestContextAddon<R> resetBuffer()
IResponseRequestContextAddon<R> resetEverything()
Content-Type and
sets the status code back to 200.byte[] getUnsentBytes()
String getUnsentCharacters()
UTF-8 encoding.String getUnsentCharacters(String encoding)
IResponseRequestContextAddon<R> setGzipOption(GzipOption gzipOption)
GzipOption.DEFAULT which
will gzip the response only for some Content-Types
and only if a gzip 'Accept-Encoding' header
has been received from the client.GzipOption getGzipOption()
IResponseRequestContextAddon<R> setCacheSeconds(int cacheSeconds)
seconds - the number of seconds this response should be cached.IResponseRequestContextAddon<R> setCacheSeconds(int cacheSeconds, boolean isPrivateCache)
seconds - the number of seconds this response should be cached.isPrivateCache - if true, the cache will
be flagged as "private".Copyright © 2016. All rights reserved.