public class SpincastResponseRequestContextAddon<R extends RequestContext<?>> extends Object implements ResponseRequestContextAddon<R>
| Modifier and Type | Field and Description |
|---|---|
protected static boolean |
IS_RESPONSE_CHARACTERS_BASED_BY_DEFAULT |
protected org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
SpincastResponseRequestContextAddon(R requestContext,
Server server,
JsonManager jsonManager,
XmlManager xmlManager,
SpincastConfig spincastConfig,
SpincastUtils spincastUtils,
ETagFactory etagFactory,
FlashMessagesHolder flashMessagesHolder,
FlashMessageFactory flashMessageFactory,
CookieFactory cookieFactory) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAlert(AlertLevel alertType,
String alertText)
Adds an Alert that is, in general, displayed at the top
of the page to show the user an Error, a Warning or a
confirmation message.
|
protected void |
addAlertsToModel() |
protected void |
addCookieSafe(String name,
String value,
Integer nbrSecondsToLive) |
void |
addForm(Form form)
Adds a
Form object to the response's
model and links its validation messages to the
default "validation" root element. |
void |
addForm(Form form,
String validationElementName)
Adds a
Form object to the response's
model and links its validation messages to the
specified validation element. |
ResponseRequestContextAddon<R> |
addHeaderValue(String name,
String value)
Adds a value to a response header.
|
ResponseRequestContextAddon<R> |
addHeaderValues(String name,
List<String> values)
Adds a list of values to a response header.
|
protected Alert |
createAlert(AlertLevel alertType,
String alertText) |
Cookie |
createCookie(String name)
Creates a cookie using the given name (
null value). |
void |
deleteAllCookiesUserHas()
Deletes all cookies! Not only
the new cookies that have been added to the response, but
also the cookies that have been received in the request!
|
void |
deleteCookie(String name)
Deletes a cookie.
|
void |
end()
Flushes everything and closes the response.
|
void |
flush()
Flushes the current response.
|
void |
flush(boolean close)
Flushes the current response.
|
protected ByteArrayOutputStream |
getBuffer() |
String |
getCharactersCharsetName()
The charset to use to convert characters to bytes.
|
String |
getContentType()
The current
Content-Type sent or to be send. |
Cookie |
getCookieAdded(String name)
Gets a cookie already added to the response, by its name.
|
protected CookieFactory |
getCookieFactory() |
Map<String,Cookie> |
getCookiesAdded()
Gets the cookies already added to the response as a Map,
using their names as the keys.
|
protected ETagFactory |
getEtagFactory() |
protected Object |
getExchange() |
protected FlashMessageFactory |
getFlashMessageFactory() |
protected FlashMessagesHolder |
getFlashMessagesHolder() |
GZIPOutputStream |
getGzipBuffer() |
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.
|
protected JsonManager |
getJsonManager() |
JsonObject |
getModel()
The
JsonObject which serves as the model for
the response. |
protected ByteArrayOutputStream |
getOut() |
protected R |
getRequestContext() |
protected Server |
getServer() |
protected SpincastConfig |
getSpincastConfig() |
protected SpincastUtils |
getSpincastUtils() |
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.
|
protected XmlManager |
getXmlManager() |
protected boolean |
isAddAlertsToModel()
Should Alert messages (and therefore Flash message)
be added to the model when sending this one as Json or XML?
|
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.
|
protected boolean |
isRequestSizeValidated() |
protected boolean |
isResponseCharactersBased()
Try to determine is the response is characters based or not.
|
protected boolean |
isShouldGzip() |
void |
redirect()
Sets a temporarily redirection header (302) to the
current page.
|
void |
redirect(FlashMessage flashMessage)
Sets a temporarily redirection header (302) to the
current page, with a Flash message to display.
|
void |
redirect(FlashMessageLevel flashMessageType,
String flashMessageText)
Sets a temporarily redirection header (302) to the
current page, with a Flash message to display.
|
void |
redirect(FlashMessageLevel flashMessageType,
String flashMessageText,
JsonObject flashMessageVariables)
Sets a temporarily redirection header (302) to the
current page, with a Flash message to display.
|
void |
redirect(String newUrl)
Sets a temporarily redirection header (302).
|
void |
redirect(String newUrl,
boolean permanently)
Sets a redirection header.
|
void |
redirect(String newUrl,
boolean permanently,
FlashMessage flashMessage)
Sets a redirection header, with a Flash message to display.
|
void |
redirect(String newUrl,
boolean permanently,
FlashMessageLevel flashMessageType,
String flashMessageText)
Sets a redirection header, with a Flash message to display.
|
void |
redirect(String newUrl,
boolean permanently,
FlashMessageLevel flashMessageType,
String flashMessageText,
JsonObject flashMessageVariables)
Sets a redirection header, with a Flash message to display.
|
void |
redirect(String newUrl,
FlashMessage flashMessage)
Sets a temporarily redirection header (302),
with a Flash message to display.
|
void |
redirect(String newUrl,
FlashMessageLevel flashMessageType,
String flashMessageText)
Sets a temporarily redirection header (302),
with a Flash message to display.
|
void |
redirect(String newUrl,
FlashMessageLevel flashMessageType,
String flashMessageText,
JsonObject flashMessageVariables)
Sets a temporarily redirection header (302),
with a Flash message to display.
|
void |
redirect(String newUrl,
int specific3xxCode)
Sets the redirection headers with a specified
3xx status code. |
void |
redirect(String newUrl,
int specific3xxCode,
FlashMessage flashMessage)
Sets the redirection headers with a specified
3xx status code,
and a Flash message to display. |
void |
redirect(String newUrl,
int specific3xxCode,
FlashMessageLevel flashMessageType,
String flashMessageText)
Sets the redirection headers with a specified
3xx status code,
and a Flash message to display. |
void |
redirect(String newUrl,
int specific3xxCode,
FlashMessageLevel flashMessageType,
String flashMessageText,
JsonObject flashMessageVariables)
Sets the redirection headers with a specified
3xx status code,
and a Flash message to display. |
void |
redirect(String newUrl,
JsonObject flashMessageVariables)
Sets a temporarily redirection header (302),
with a Flash variables.
|
ResponseRequestContextAddon<R> |
removeHeader(String name)
Removes an header by its name.
|
ResponseRequestContextAddon<R> |
resetBuffer()
Clears the buffer (the unsent buffer, of course).
|
ResponseRequestContextAddon<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. |
ResponseRequestContextAddon<R> |
resetEverything(boolean resetCookies)
Clears the buffer (the unsent buffer, of course),
the headers, the
Content-Type and
sets the status code back to 200. |
protected String |
saveFlashMessage(String url,
FlashMessage flashMessage)
Saves a Flash message.
|
protected void |
send(byte[] bytes,
String contentType,
boolean flush) |
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)
Send some bytes + flush if specified.
|
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 string,
boolean flush)
Sends a String as
text/html, UTF-8 encoded,
and flushes, if specified. |
void |
sendJson()
Sends the model as
application/json, without flushing. |
void |
sendJson(boolean flush)
Sends the model as
application/json,
and flushes, if specified. |
void |
sendJson(Object obj)
Serializes the object to
Json and sends as
application/json, without flushing. |
void |
sendJson(Object obj,
boolean flush)
Serializes the object to
Json, sends as application/json,
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 |
sendParse(String content,
String contentType)
Parses the given String using the
TemplatingEngine,
then sends the result using the specified
Content-Type, without flushing. |
void |
sendParse(String content,
String contentType,
boolean flush)
Parses the given String using the
TemplatingEngine,
then sends the result using the specified
Content-Type, and flushes, if specified. |
void |
sendParseHtml(String html)
Parses the given String using the
TemplatingEngine and
the given parameters, then sends the result as text/html,
UTF-8 encoded. |
void |
sendParseHtml(String html,
boolean flush)
Parses the given String using the
TemplatingEngine and
the given parameters, then sends the result as text/html,
UTF-8 encoded, 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)
Finds the specified template using the
TemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, without flushing. |
void |
sendTemplate(String templatePath,
boolean isClasspathPath,
String contentType,
boolean flush)
Finds the specified template using the
TemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, and flushes, if specified. |
void |
sendTemplate(String templatePath,
String contentType)
Finds the specified template using the
TemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, without flushing. |
void |
sendTemplate(String templatePath,
String contentType,
boolean flush)
Finds the specified template using the
TemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, and flushes, if specified. |
void |
sendTemplateHtml(String templatePath)
Finds the
HTML template using the TemplatingEngine,
evaluates it using the model that have been added to the response, then sends the
result as text/html, UTF-8 encoded, without flushing. |
void |
sendTemplateHtml(String templatePath,
boolean isClasspathPath)
Finds the
HTML template using the TemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded. |
void |
sendTemplateHtml(String templatePath,
boolean isClasspathPath,
boolean flush)
Finds the
HTML template using the TemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded, and flushes, if specified. |
void |
sendXml()
Sends the model as
application/xml,
without flushing. |
void |
sendXml(boolean flush)
Sends the model as
application/xml,
and flushes, if specified. |
void |
sendXml(Object obj)
Serializes the object to
XML and sends
as application/xml, without flushing. |
void |
sendXml(Object obj,
boolean flush)
Serializes the object to
XML, sends as application/xml, 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. |
ResponseRequestContextAddon<R> |
setCacheSeconds(int cacheSeconds)
Adds caching headers.
|
ResponseRequestContextAddon<R> |
setCacheSeconds(int cacheSeconds,
boolean isPrivateCache)
Adds caching headers for the specified number
of seconds.
|
ResponseRequestContextAddon<R> |
setCharactersCharsetName(String charactersCharsetName)
Sets the charset to use to convert characters to bytes.
|
ResponseRequestContextAddon<R> |
setContentType(String responseContentType)
The
Content-Type header to use for the response. |
void |
setCookie(Cookie cookie)
Sets a cookie.
|
void |
setCookie(String name,
String value,
int nbrSecondsToLive)
Sets a cookie using the specified name, value
and number of seconds to live.
|
void |
setCookie(String name,
String value,
int nbrSecondsToLive,
boolean httpOnly)
Sets a cookie using the specified name, value,
number of seconds to live and if it's http only.
|
void |
setCookie(String name,
String value,
String path,
String domain,
Date expires,
boolean secure,
boolean httpOnly,
CookieSameSite cookieSameSite,
boolean discard,
int version)
Sets a cookie, using all available configurations.
|
void |
setCookie10years(String name,
String value)
Sets a permanent cookie (10 years) using the specified
name and value.
|
void |
setCookie10yearsSafe(String name,
String value)
Sets a permanent cookie (10 years) using the specified
name and value.
|
void |
setCookie1year(String name,
String value)
Sets a permanent cookie (1 years) using the specified
name and value.
|
void |
setCookie1yearSafe(String name,
String value)
Sets a permanent cookie (1 years) using the specified
name and value.
|
void |
setCookieSession(String name,
String value)
Sets a cookie using the specified name and value.
|
void |
setCookieSessionSafe(String name,
String value)
Sets a cookie using the specified name and value.
|
ResponseRequestContextAddon<R> |
setGzipOption(GzipOption gzipOption)
Enable or disable gzipping of the response.
|
ResponseRequestContextAddon<R> |
setHeader(String name,
List<String> values)
Set multiple values to a response header.
|
ResponseRequestContextAddon<R> |
setHeader(String name,
String value)
Set the value to a response header.
|
protected void |
setIsShouldGzip(boolean isShouldGzip) |
void |
setModel(JsonObject model)
Replaces the current response model completely.
|
protected void |
setRequestSizeValidated(boolean requestSizeValidated) |
ResponseRequestContextAddon<R> |
setStatusCode(int responseStatusCode)
Sets the response's
status code to use. |
protected boolean |
validateCookie(Cookie cookie) |
protected final org.slf4j.Logger logger
protected static final boolean IS_RESPONSE_CHARACTERS_BASED_BY_DEFAULT
@Inject public SpincastResponseRequestContextAddon(R requestContext, Server server, JsonManager jsonManager, XmlManager xmlManager, SpincastConfig spincastConfig, SpincastUtils spincastUtils, ETagFactory etagFactory, FlashMessagesHolder flashMessagesHolder, FlashMessageFactory flashMessageFactory, CookieFactory cookieFactory)
protected R getRequestContext()
protected Server getServer()
protected Object getExchange()
protected JsonManager getJsonManager()
protected XmlManager getXmlManager()
protected SpincastConfig getSpincastConfig()
protected SpincastUtils getSpincastUtils()
protected ETagFactory getEtagFactory()
protected FlashMessagesHolder getFlashMessagesHolder()
protected FlashMessageFactory getFlashMessageFactory()
protected CookieFactory getCookieFactory()
protected ByteArrayOutputStream getBuffer()
protected ByteArrayOutputStream getOut()
public JsonObject getModel()
ResponseRequestContextAddonJsonObject which serves as the model for
the response. This object will be used by the templating
engine or will be sent as is, often as an
application/json response.
This object is mutable.
getModel in interface ResponseRequestContextAddon<R extends RequestContext<?>>public GZIPOutputStream getGzipBuffer()
protected boolean isRequestSizeValidated()
protected void setRequestSizeValidated(boolean requestSizeValidated)
public ResponseRequestContextAddon<R> setGzipOption(GzipOption gzipOption)
ResponseRequestContextAddonGzipOption.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.setGzipOption in interface ResponseRequestContextAddon<R extends RequestContext<?>>public GzipOption getGzipOption()
ResponseRequestContextAddongetGzipOption in interface ResponseRequestContextAddon<R extends RequestContext<?>>public int getStatusCode()
ResponseRequestContextAddonstatus code sent or to be send.getStatusCode in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> setStatusCode(int responseStatusCode)
ResponseRequestContextAddonstatus code to use. Uses 200
by default.
Note that this status code can be changed automatically
if an exception is thrown.setStatusCode in interface ResponseRequestContextAddon<R extends RequestContext<?>>public String getContentType()
ResponseRequestContextAddonContent-Type sent or to be send.getContentType in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> setContentType(String responseContentType)
ResponseRequestContextAddonContent-Type header to use for the response. Most
sendXXX() methods will set this automatically.setContentType in interface ResponseRequestContextAddon<R extends RequestContext<?>>protected boolean isResponseCharactersBased()
public boolean isClosed()
ResponseRequestContextAddonisClosed in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void redirect()
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void redirect(FlashMessage flashMessage)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void redirect(FlashMessageLevel flashMessageType, String flashMessageText)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void redirect(FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void redirect(String newUrl)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void redirect(String newUrl, FlashMessage flashMessage)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>flashMessage - A Flash Message to pass to the target page.public void redirect(String newUrl, FlashMessageLevel flashMessageType, String flashMessageText)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>flashMessageType - The type of a Flash Message to pass to the target page.flashMessageText - The text of a Flash Message to pass to the target page.public void redirect(String newUrl, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>flashMessageType - The type of a Flash Message to pass to the target page.flashMessageText - The text of a Flash Message to pass to the target page.flashMessageVariables - The variables of a Flash Message to pass to the target page.public void redirect(String newUrl, JsonObject flashMessageVariables)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>flashMessageVariables - The variables of a Flash Message to pass to the target page.public void redirect(String newUrl, boolean permanently)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>permanently - If true, a
301 header will be sent. If false,
302 will be sent.public void redirect(String newUrl, boolean permanently, FlashMessage flashMessage)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>permanently - If true, a
301 header will be sent. If false,
302 will be sent.flashMessage - A Flash Message to pass to the target page.public void redirect(String newUrl, boolean permanently, FlashMessageLevel flashMessageType, String flashMessageText)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>permanently - If true, a
301 header will be sent. If false,
302 will be sent.flashMessageType - The type of a Flash Message to pass to the target page.flashMessageText - The text of a Flash Message to pass to the target page.public void redirect(String newUrl, boolean permanently, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables)
ResponseRequestContextAddon
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>permanently - If true, a
301 header will be sent. If false,
302 will be sent.flashMessageType - The type of a Flash Message to pass to the target page.flashMessageText - The text of a Flash Message to pass to the target page.flashMessageVariables - The variables of a Flash Message to pass to the target page.public void redirect(String newUrl, int specific3xxCode)
ResponseRequestContextAddon3xx 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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void redirect(String newUrl, int specific3xxCode, FlashMessageLevel flashMessageType, String flashMessageText)
ResponseRequestContextAddon3xx status code,
and a Flash message to display.
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>flashMessageType - The type of a Flash Message to pass to the target page.flashMessageText - The text of a Flash Message to pass to the target page.public void redirect(String newUrl, int specific3xxCode, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables)
ResponseRequestContextAddon3xx status code,
and a Flash message to display.
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>flashMessageType - The type of a Flash Message to pass to the target page.flashMessageText - The text of a Flash Message to pass to the target page.flashMessageVariables - The variables of a Flash Message to pass to the target page.public void redirect(String newUrl, int specific3xxCode, FlashMessage flashMessage)
ResponseRequestContextAddon3xx status code,
and a Flash message to display.
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.
redirect in interface ResponseRequestContextAddon<R extends RequestContext<?>>flashMessage - A Flash Message to pass to the target page.protected String saveFlashMessage(String url, FlashMessage flashMessage)
public void sendBytes(byte[] bytes)
ResponseRequestContextAddonbytes, without flushing.sendBytes in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendBytes(byte[] bytes,
String contentType)
ResponseRequestContextAddonbytes using the specified Content-Type,
without flushing.sendBytes in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendBytes(byte[] bytes,
String contentType,
boolean flush)
sendBytes in interface ResponseRequestContextAddon<R extends RequestContext<?>>protected void send(byte[] bytes,
String contentType,
boolean flush)
public void sendCharacters(String content, String contentType)
ResponseRequestContextAddongetCharactersCharsetName and
using the specified Content-Type, without flushing.sendCharacters in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendCharacters(String content, String contentType, boolean flush)
ResponseRequestContextAddongetCharactersCharsetName
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.sendCharacters in interface ResponseRequestContextAddon<R extends RequestContext<?>>public String getCharactersCharsetName()
ResponseRequestContextAddon"UTF-8".getCharactersCharsetName in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> setCharactersCharsetName(String charactersCharsetName)
ResponseRequestContextAddon"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()).setCharactersCharsetName in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendPlainText(String string)
ResponseRequestContextAddontext/plain, UTF-8 encoded, without flushing.sendPlainText in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendPlainText(String string, boolean flush)
ResponseRequestContextAddontext/plain, UTF-8 encoded,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.sendPlainText in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendHtml(String html)
ResponseRequestContextAddontext/html, UTF-8 encoded, without flushing.sendHtml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendHtml(String string, boolean flush)
ResponseRequestContextAddontext/html, UTF-8 encoded,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.sendHtml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendParseHtml(String html)
ResponseRequestContextAddonTemplatingEngine and
the given parameters, then sends the result as text/html,
UTF-8 encoded.sendParseHtml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendParseHtml(String html, boolean flush)
ResponseRequestContextAddonTemplatingEngine 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.sendParseHtml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendParse(String content, String contentType)
ResponseRequestContextAddonTemplatingEngine,
then sends the result using the specified
Content-Type, without flushing.sendParse in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendParse(String content, String contentType, boolean flush)
ResponseRequestContextAddonTemplatingEngine,
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.sendParse in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendTemplateHtml(String templatePath)
ResponseRequestContextAddonHTML template using the TemplatingEngine,
evaluates it using the model that have been added to the response, then sends the
result as text/html, UTF-8 encoded, without flushing.sendTemplateHtml in interface ResponseRequestContextAddon<R extends RequestContext<?>>templatePath - must be a classpath's relative path.public void sendTemplateHtml(String templatePath, boolean isClasspathPath)
ResponseRequestContextAddonHTML template using the TemplatingEngine, evaluates it using
the given parameters, then sends the
result as text/html, UTF-8 encoded.sendTemplateHtml in interface ResponseRequestContextAddon<R extends RequestContext<?>>isClasspathPath - if true, the 'templatePath' is considered as
a classpath's relative path. If false, it is considered as an absolute file
system path.public void sendTemplateHtml(String templatePath, boolean isClasspathPath, boolean flush)
ResponseRequestContextAddonHTML template using the TemplatingEngine, 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.sendTemplateHtml in interface ResponseRequestContextAddon<R extends RequestContext<?>>isClasspathPath - if true, the 'templatePath' is considered as
a classpath's relative path. If false, it is considered as an absolute file
system path.public void sendTemplate(String templatePath, String contentType)
ResponseRequestContextAddonTemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, without flushing.sendTemplate in interface ResponseRequestContextAddon<R extends RequestContext<?>>templatePath - must be a classpath's relative path.public void sendTemplate(String templatePath, String contentType, boolean flush)
ResponseRequestContextAddonTemplatingEngine, 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.sendTemplate in interface ResponseRequestContextAddon<R extends RequestContext<?>>templatePath - must be a classpath's relative path.public void sendTemplate(String templatePath, boolean isClasspathPath, String contentType)
ResponseRequestContextAddonTemplatingEngine, evaluates it using
the given parameters, then sends the
result using the given contentType, without flushing.sendTemplate in interface ResponseRequestContextAddon<R extends RequestContext<?>>isClasspathPath - if true, the 'templatePath' is considered as
a classpath's relative path. If false, it is considered as an absolute file
system path.public void sendTemplate(String templatePath, boolean isClasspathPath, String contentType, boolean flush)
ResponseRequestContextAddonTemplatingEngine, 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.sendTemplate in interface ResponseRequestContextAddon<R extends RequestContext<?>>isClasspathPath - if true, the 'templatePath' is considered as
a classpath's relative path. If false, it is considered as an absolute file
system path.public void sendJson()
ResponseRequestContextAddonapplication/json, without flushing.sendJson in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendJson(boolean flush)
ResponseRequestContextAddonapplication/json,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.
sendJson in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendJson(String jsonString)
ResponseRequestContextAddonJson String using the application/json Content-Type,
without flushing.
Synonym of : sendCharacters(jsonString, "application/json")
sendJson in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendJson(String jsonString, boolean flush)
ResponseRequestContextAddonJson 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)
sendJson in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendJson(Object obj)
ResponseRequestContextAddonJson and sends as
application/json, without flushing.
If the specified Object is a String, it will
be considered as already being JSON and will be
send as is.
sendJson in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendJson(Object obj, boolean flush)
ResponseRequestContextAddonJson, sends as application/json,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.
If the specified Object is a String, it will
be considered as already being JSON and will be
send as is.
sendJson in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendXml()
ResponseRequestContextAddonapplication/xml,
without flushing.sendXml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendXml(boolean flush)
ResponseRequestContextAddonapplication/xml,
and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.
sendXml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendXml(String xml)
ResponseRequestContextAddonXML using the application/xml Content-Type,
without flushing.
Synonym of : sendCharacters(xml, "application/xml")
sendXml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendXml(String xml, boolean flush)
ResponseRequestContextAddonXML 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)
sendXml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendXml(Object obj)
ResponseRequestContextAddonXML and sends
as application/xml, without flushing.
If the specified Object is a String, it will
be considered as already being XML and will be
send as is.
sendXml in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void sendXml(Object obj, boolean flush)
ResponseRequestContextAddonXML, sends as application/xml, and flushes, if specified.
Note that once the response is flushed, no header can be added or changed anymore.
If the specified Object is a String, it will
be considered as already being XML and will be
send as is.
sendXml in interface ResponseRequestContextAddon<R extends RequestContext<?>>protected void addAlertsToModel()
protected boolean isAddAlertsToModel()
public ResponseRequestContextAddon<R> resetBuffer()
ResponseRequestContextAddonresetBuffer in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> resetEverything()
ResponseRequestContextAddonContent-Type and
sets the status code back to 200.resetEverything in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> resetEverything(boolean resetCookies)
ResponseRequestContextAddonContent-Type and
sets the status code back to 200.resetEverything in interface ResponseRequestContextAddon<R extends RequestContext<?>>resetCookies - if true, cookies that have been
added on the current response will be reset too.public byte[] getUnsentBytes()
ResponseRequestContextAddongetUnsentBytes in interface ResponseRequestContextAddon<R extends RequestContext<?>>public String getUnsentCharacters()
ResponseRequestContextAddonUTF-8 encoding.getUnsentCharacters in interface ResponseRequestContextAddon<R extends RequestContext<?>>public String getUnsentCharacters(String encoding)
ResponseRequestContextAddongetUnsentCharacters in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> removeHeader(String name)
ResponseRequestContextAddonremoveHeader in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> setHeader(String name, String value)
ResponseRequestContextAddonnull, the header will be
removed (same behavior as removeHeader(String name))setHeader in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> setHeader(String name, List<String> values)
ResponseRequestContextAddonnull or empty, the header will be
removed (same behavior as removeHeader(String name))setHeader in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> addHeaderValue(String name, String value)
ResponseRequestContextAddonnull, it won't be added.addHeaderValue in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> addHeaderValues(String name, List<String> values)
ResponseRequestContextAddonnull, nothing will be added.addHeaderValues in interface ResponseRequestContextAddon<R extends RequestContext<?>>public Map<String,List<String>> getHeaders()
ResponseRequestContextAddonTreeMap with case insensitive keys.getHeaders in interface ResponseRequestContextAddon<R extends RequestContext<?>>public List<String> getHeader(String name)
ResponseRequestContextAddongetHeader in interface ResponseRequestContextAddon<R extends RequestContext<?>>public String getHeaderFirst(String name)
ResponseRequestContextAddonnull if the header is not found.getHeaderFirst in interface ResponseRequestContextAddon<R extends RequestContext<?>>public boolean isHeadersSent()
ResponseRequestContextAddonisHeadersSent in interface ResponseRequestContextAddon<R extends RequestContext<?>>protected void setIsShouldGzip(boolean isShouldGzip)
protected boolean isShouldGzip()
public void end()
ResponseRequestContextAddonroute handlers will still
be called).end in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void flush()
ResponseRequestContextAddonstatus code and Content-Type will be added.
Note that once the response is flushed, no header can be added or changed anymore.flush in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void flush(boolean close)
ResponseRequestContextAddonstatus code and content-type will be added.
Note that once the response is flushed, no header can be added or changed anymore.flush in interface ResponseRequestContextAddon<R extends RequestContext<?>>close - If true, the response will be closed and no more data
can be sent. This has the same effect than calling ResponseRequestContextAddon.end().public ResponseRequestContextAddon<R> setCacheSeconds(int cacheSeconds)
ResponseRequestContextAddonsetCacheSeconds in interface ResponseRequestContextAddon<R extends RequestContext<?>>public ResponseRequestContextAddon<R> setCacheSeconds(int cacheSeconds, boolean isPrivateCache)
ResponseRequestContextAddonsetCacheSeconds in interface ResponseRequestContextAddon<R extends RequestContext<?>>isPrivateCache - if true, the cache will
be flagged as "private".public void setModel(JsonObject model)
ResponseRequestContextAddon
Use ResponseRequestContextAddon.getModel() instead to get the current
model instance and add properties to it.
setModel in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void addAlert(AlertLevel alertType, String alertText)
ResponseRequestContextAddon
Those alerts are available using the "spincast.alerts"
templating variable. If any, a Flash Messages is also
added to this variable.
addAlert in interface ResponseRequestContextAddon<R extends RequestContext<?>>protected Alert createAlert(AlertLevel alertType, String alertText)
public Map<String,Cookie> getCookiesAdded()
ResponseRequestContextAddon
NOTE : use the RequestRequestContextAddon.getCookiesValues()
from the request() add-on instead
to get the cookies sent by the user!
getCookiesAdded in interface ResponseRequestContextAddon<R extends RequestContext<?>>public Cookie getCookieAdded(String name)
ResponseRequestContextAddon
NOTE : use the RequestRequestContextAddon.getCookieValue(String)
from the request() add-on instead
to get a cookie sent by the user!
getCookieAdded in interface ResponseRequestContextAddon<R extends RequestContext<?>>null if not found.public void setCookie(Cookie cookie)
ResponseRequestContextAddonsetCookie in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookieSession(String name, String value)
ResponseRequestContextAddon
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain
and the cookie is valid for the time of the session only.
setCookieSession in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookieSessionSafe(String name, String value)
ResponseRequestContextAddonCookieSameSite value of CookieSameSite.LAX.
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain
and the cookie is valid for the time of the session only.
setCookieSessionSafe in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookie1year(String name, String value)
ResponseRequestContextAddon
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain.
setCookie1year in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookie1yearSafe(String name, String value)
ResponseRequestContextAddonCookieSameSite value of CookieSameSite.LAX.
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain.
setCookie1yearSafe in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookie10years(String name, String value)
ResponseRequestContextAddon
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain.
setCookie10years in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookie10yearsSafe(String name, String value)
ResponseRequestContextAddonCookieSameSite value of CookieSameSite.LAX.
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain.
setCookie10yearsSafe in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookie(String name, String value, int nbrSecondsToLive)
ResponseRequestContextAddon
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain.
setCookie in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookie(String name, String value, int nbrSecondsToLive, boolean httpOnly)
ResponseRequestContextAddon
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain.
setCookie in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void setCookie(String name, String value, String path, String domain, Date expires, boolean secure, boolean httpOnly, CookieSameSite cookieSameSite, boolean discard, int version)
ResponseRequestContextAddonsetCookie in interface ResponseRequestContextAddon<R extends RequestContext<?>>protected boolean validateCookie(Cookie cookie)
public void deleteCookie(String name)
ResponseRequestContextAddonexpires date in the
past so the user's browser will remove it.
isExpired() will return true after you called
this method.deleteCookie in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void deleteAllCookiesUserHas()
ResponseRequestContextAddon
In fact, this method sets the expires date of the
cookies in the past so the user's browser will remove them.
deleteAllCookiesUserHas in interface ResponseRequestContextAddon<R extends RequestContext<?>>public Cookie createCookie(String name)
ResponseRequestContextAddonnull value).
By default, the public host (SpincastConfig.getPublicServerHost())
is uses as the cookie's domain
and the cookie is valid for the time
of the session only.
You have to add the cookie using the
ResponseRequestContextAddon.setCookie(Cookie) method after it is
properly created.
createCookie in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void addForm(Form form)
ResponseRequestContextAddonForm object to the response's
model and links its validation messages to the
default "validation" root element.
In other words, adding a form will result in those elements to the response's model :
addForm in interface ResponseRequestContextAddon<R extends RequestContext<?>>public void addForm(Form form, String validationElementName)
ResponseRequestContextAddonForm object to the response's
model and links its validation messages to the
specified validation element.
In other words, adding a form will result in those elements to the response's model :
addForm in interface ResponseRequestContextAddon<R extends RequestContext<?>>Copyright © 2019. All rights reserved.