Class Context
- Since:
- 1.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
static final double
static final float
static final int
static final long
static final int
Status code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request.static final int
Status code (304) indicating that a conditional GET operation found that the resource was available and not modified. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCookie
(CookieBuilder builder) Adds theCookie
created by aCookieBuilder
to the response.void
addDateHeader
(String name, long date) Adds a response header with the given name and date-value.void
Adds a response header with the given name and integer value.void
Adds a response header with the given name and value.Returns the value of the named attribute.Returns a list of attribute names available to this request.body()
Retrieves the body of this context's request as a string.byte[]
Retrieves the body of this context's request as a byte array.Returns the name of the character encoding used in the body of this request.void
Clears the text buffer is it's enabled.Returns the MIME type of the body of the request, or null if the type is not known.Returns the portion of the request URI that indicates the context of the request.Returns the unique identifier of the current continuation.boolean
cookieBoolean
(String name) Retrieves the value of a named cookie and converts it to a boolean.boolean
cookieBoolean
(String name, boolean defaultValue) Retrieves the value of a named cookie and converts it to a boolean, using a default value if no input value is present.double
cookieDouble
(String name) Retrieves the value of a named cookie and converts it to a double.double
cookieDouble
(String name, double defaultValue) Retrieves the value of a named cookie and converts it to a double, using a default value if no input value is present.float
cookieFloat
(String name) Retrieves the value of a named cookie and converts it to a float.float
cookieFloat
(String name, float defaultValue) Retrieves the value of a named cookie and converts it to a float, using a default value if no input value is present.int
Retrieves the value of a named cookie and converts it to an integer.int
Retrieves the value of a named cookie and converts it to an integer, using a default value if no input value is present.long
cookieLong
(String name) Retrieves the value of a named cookie and converts it to a long.long
cookieLong
(String name, long defaultValue) Retrieves the value of a named cookie and converts it to a long, using a default value if no input value is present.Retrieves the names of the cookies.cookieValue
(String name) Retrieves the value of a cookie.cookieValue
(String name, String defaultValue) Retrieves the value of a named cookie, using a default value as fallback.Retrieves all current cookies names with their values.void
defer()
Interrupts the execution in RIFE2 completely and defers it to the servlet container.void
enableTextBuffer
(boolean enabled) Enables or disables the response text buffer.Retrieves the exception that was triggered during the RIFE2 web engine execution.Retrieves an uploaded file.Retrieves the list of uploaded file names.files()
Retrieves the files that were uploaded in this context.Retrieves all files that have been uploaded for a particular name.void
flush()
Forces all the streamed content to be output to the client.static Context
fromTemplate
(Template template) Retrieves the context that was stored in a template attribute.gateUrl()
Retrieves the URL portion that corresponds to the entrance gate of the RIFE2 web engine, this is usually equivalent with the HTTP request context path.void
generateEmptyForm
(Template template, Class beanClass) Generates a form that corresponds to an empty instance of a bean class.void
generateEmptyForm
(Template template, Class beanClass, String prefix) Generates a form that corresponds to an empty instance of a bean class.void
generateForm
(Template template, Object beanInstance) Generates a form that corresponds to a bean instance.void
generateForm
(Template template, Object beanInstance, String prefix) Generates a form that corresponds to a bean instance.boolean
hasAttribute
(String name) Checks if a request attribute exists.boolean
Indicates whether a continuation identifier is availableboolean
Checks whether a cookie is present.boolean
Checks if a particular file has been uploaded in this context.boolean
hasParameterValue
(String name) Checks whether a value has been provided to a parameter.boolean
hasProperty
(String name) Checks for the existence of a property in this context'sHierarchicalProperties
.Returns the value of the specified request header as a String.long
headerDate
(String name) Returns the value of the specified request header as a long value that represents a date.int
Returns the value of the specified request header as an int.Returns a list of all the header names in the request.Returns all the values of the specified request header as a list ofString
objects.boolean
isFileEmpty
(String name) Checks if an uploaded file wasn't sent or if it is empty.boolean
isParameterEmpty
(String name) Checks whether a parameter is empty.locale()
Returns the preferredLocale
that the client will accept content in, based on theAccept-Language
header.locales()
Returns a list ofLocale
objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on theAccept-Language
} header.method()
Returns the HTTPRequestMethod
with which this context's request was made.void
next()
Interrupts the execution in this element, moving processing on to the next element in the before/route/after chainReturns an output stream suitable for writing binary data in the response.Retrieves the value of a parameter.Retrieves the value of a parameter and returns a default value if no parameter value is presentboolean
parameterBoolean
(String name) Retrieves the value of a parameter and converts it to a boolean.boolean
parameterBoolean
(String name, boolean defaultValue) Retrieves the value of a parameter and converts it to a boolean, using a default value if no parameter value is present.double
parameterDouble
(String name) Retrieves the value of a parameter and converts it to a double.double
parameterDouble
(String name, double defaultValue) Retrieves the value of a parameter and converts it to a double, using a default value if no parameter value is present.double[]
parameterDoubles
(String name) Retrieves the values of a parameter as an array of doubles.float
parameterFloat
(String name) Retrieves the value of a parameter and converts it to a float.float
parameterFloat
(String name, float defaultValue) Retrieves the value of a parameter and converts it to a float, using a default value if no parameter value is present.float[]
parameterFloats
(String name) Retrieves the values of a parameter as an array of floats.int
parameterInt
(String name) Retrieves the value of a parameter and converts it to an integer.int
parameterInt
(String name, int defaultValue) Retrieves the value of a parameter and converts it to an integer, using a default value if no parameter value is present.int[]
parameterInts
(String name) Retrieves the values of a parameter as an array of integers.long
parameterLong
(String name) Retrieves the value of a parameter and converts it to a long.long
parameterLong
(String name, long defaultValue) Retrieves the value of a parameter and converts it to a long, using a default value if no parameter value is present.long[]
parameterLongs
(String name) Retrieves the values of a parameter as an array of longs.Retrieves the names of all the parameters that are present.Retrieves the parameters that were sent to this context.<BeanType> BeanType
parametersBean
(Class<BeanType> beanClass) Creates an instance of a bean and populates the properties with the parameter values.<BeanType> BeanType
parametersBean
(Class<BeanType> beanClass, String prefix) Creates an instance of a bean and populates the properties with the parameter values, taking the provided prefix into account.void
parametersBean
(Object bean) Fills the properties of an existing bean with the parameter values.void
parametersBean
(Object bean, String prefix) Fills the properties of an existing bean with the parameter values that were sent, taking the provided prefix into account.String[]
parameterValues
(String name) Retrieves the values of a parameter.pathInfo()
The pathinfo that was captured or matched.final void
pause()
Pauses the execution of the element and creates a new continuation.void
Sets up the current response to prevent all caching of the response by the client.void
Prints the string representation of an object to the request text output.void
Prints a template to the response.The hierarchical properties accessible to this context.Retrieve a property from this context'sHierarchicalProperties
.Returns a collection of the names in this context'sHierarchicalProperties
.protocol()
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.void
Interrupts the execution in this element and redirects the client to another URL.void
Interrupts the execution in this element and redirects the client to another URL.Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.Returns the fully qualified name of the client or the last proxy that sent the request.Returns the login of the user making this request.void
removeAttribute
(String name) Removes an attribute from this request.void
removeCookie
(String name) Removes a cookie with path"/"
.void
removeCookie
(String path, String name) Removes a cookie with given path and name.void
removeForm
(Template template, Class beanClass) Removes a generated form, leaving the builder value tags empty again as if this form had never been generated.void
removeForm
(Template template, Class beanClass, String prefix) Removes a generated form, leaving the builder value tags empty again as if this form had never been generated.void
removeParameter
(String name) Removes a name parameter that was previously set.request()
The request of this context.void
respond()
Interrupts the execution in this element, stops processing any other element, and sends the current response directly to the client.response()
The response of this context.route()
The route of this context.router()
The router in which this context's route was defined.scheme()
Returns the name of the scheme used to make this request.boolean
secure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.selectParameter
(Template template, String name, String[] values) Sets a select box option, a radio button or a checkbox to selected or checked.Returns the host name of the server to which the request was sent.int
Returns the port number to which the request was sent.serverRootUrl
(int port) Returns the root URL of the server that is running this web applications.session()
Returns the current session associated with this request, or if the request does not have a session, creates one.session
(boolean create) Returns the currentSession
associated with this request or, if there is no current session andcreate
is true, returns a new session.void
setAttribute
(String name, Object object) Stores an attribute in this request.void
setContentLength
(int length) Sets the length of the content body in the response.void
setContentType
(String contentType) Sets the content type of the response being sent to the client.void
setDateHeader
(String name, long date) Adds a response header with the given name and date-value.void
Adds a response header with the given name and integer value.void
Sets a response header with the given name and value.void
Sets the locale of the response.void
setParameter
(String name, Object value) Sets a named parameter value for URL generation withurlFor(rife.engine.Route)
or the `route:` filtered template value tags.void
setParametersBean
(Object bean) Sets named parameters values from bean properties for URL generation withurlFor(rife.engine.Route)
or the `route:` filtered template value tags.void
setParametersBean
(Object bean, String prefix) Sets named parameters values from bean properties for URL generation withurlFor(rife.engine.Route)
or the `route:` filtered template value tags.void
setStatus
(int statusCode) Sets the status code for the response.site()
The active site this context is executing in.template()
Instantiates an HTML template with the name corresponding to the identifier of this route's element.Instantiates an HTML template with a given name.Instantiates an HTML template with a given name and encoding.Instantiates an JSON template with the name corresponding to the identifier of this route's element.templateJson
(String name) Instantiates an JSON template with a given name.templateJson
(String name, String encoding) Instantiates an JSON template with a given name and encoding.Instantiates an SVG template with the name corresponding to the identifier of this route's element.templateSvg
(String name) Instantiates an SVG template with a given name.templateSvg
(String name, String encoding) Instantiates an SVG template with a given name and encoding.Instantiates a TXT template with the name corresponding to the identifier of this route's element.templateTxt
(String name) Instantiates a TXT template with a given name.templateTxt
(String name, String encoding) Instantiates a TXT template with a given name and encoding.Instantiates an XML template with the name corresponding to the identifier of this route's element.templateXml
(String name) Instantiates an XML template with a given name.templateXml
(String name, String encoding) Instantiates an XML template with a given name and encoding.boolean
Indicates whether the response text buffer is enabled or disabled.Start building a URL towards a particular route.Returns the root URL of this web application.webappRootUrl
(int port) Returns the root URL of this web application.
-
Field Details
-
DEFAULT_BOOLEAN
public static final boolean DEFAULT_BOOLEAN- See Also:
-
DEFAULT_INTEGER
public static final int DEFAULT_INTEGER- See Also:
-
DEFAULT_LONG
public static final long DEFAULT_LONG- See Also:
-
DEFAULT_DOUBLE
public static final double DEFAULT_DOUBLE- See Also:
-
DEFAULT_FLOAT
public static final float DEFAULT_FLOAT- See Also:
-
SC_NOT_MODIFIED
public static final int SC_NOT_MODIFIEDStatus code (304) indicating that a conditional GET operation found that the resource was available and not modified.- See Also:
-
SC_INTERNAL_SERVER_ERROR
public static final int SC_INTERNAL_SERVER_ERRORStatus code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request.- See Also:
-
-
Method Details
-
site
The active site this context is executing in.- Returns:
- the currently active site
- Since:
- 1.0
-
request
The request of this context.Most request methods have direct counterparts in the context for easier and more convenient usage.
- Returns:
- this context's request
- Since:
- 1.0
-
response
The response of this context.Most response methods have direct counterparts in the context for easier and more convenient usage.
- Returns:
- this context's response
- Since:
- 1.0
-
pathInfo
The pathinfo that was captured or matched.The slash separated between the route path in the pathinfo will have been stripped already.
- Returns:
- the captured or matching pathinfo; or
null
if no pathinfo was captured or matched - Since:
- 1.0
-
route
The route of this context.- Returns:
- this context's route; or
null
if the context doesn't belong to a specific route - Since:
- 1.0
-
router
The router in which this context's route was defined.- Returns:
- this context's route's router; or
null
if the context doesn't belong to a specific route - Since:
- 1.0
-
properties
The hierarchical properties accessible to this context.- Returns:
- this context's hierarchical properties; or
null
if those properties can't be found - Since:
- 1.0
-
property
Retrieve a property from this context'sHierarchicalProperties
.- Returns:
- the requested property; or
null
if it doesn't exist - Since:
- 1.0
-
hasProperty
Checks for the existence of a property in this context'sHierarchicalProperties
.- Returns:
true
if the property exists; orfalse
otherwise- Since:
- 1.0
-
propertyNames
Returns a collection of the names in this context'sHierarchicalProperties
.- Returns:
- the requested collection of names
- Since:
- 1.0
-
pause
public final void pause()Pauses the execution of the element and creates a new continuation.The next request will resume exactly at the same location with a completely restored call stack and variable stack.
- Since:
- 1.0
-
hasContinuationId
public boolean hasContinuationId()Indicates whether a continuation identifier is available- Returns:
true
when a continuation identifier is available; orfalse
otherwise- Since:
- 1.0
-
continuationId
Returns the unique identifier of the current continuation.- Returns:
- the unique identifier of the current continuation; or
null
if no continuation is active - Since:
- 1.0
-
print
Prints the string representation of an object to the request text output. The string representation will be created through aString.valueOf(value)
call.- Parameters:
object
- the object that will be output- Throws:
EngineException
- if an error occurs during the output of the content- Since:
- 1.0
- See Also:
-
print
Prints a template to the response.If no response content type was set yet, the template's content type will be used.
Printing a template will automatically process all the filtered tags.
Printing a template instead of the string representation of its content has many advantages, the biggest one being that the out-of-container testing API will have access to this template instance, allowing you to assert of value content, instead of having to parse a response.
- Parameters:
template
- the template to print- Throws:
TemplateException
- if an error occurs while processing the templateEngineException
- if an error occurs during the output of the content- Since:
- 1.0
-
fromTemplate
Retrieves the context that was stored in a template attribute.Each template that was obtained through a context, automatically has the context store itself in the template as an attribute. This convenience method makes it easy to retrieve that context elsewhere.
- Returns:
- the current context stored in a template attribute.
- Since:
- 1.8.0
-
template
Instantiates an HTML template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the HTML template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
template
Instantiates an HTML template with a given name.- Parameters:
name
- the template name- Returns:
- the HTML template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
template
Instantiates an HTML template with a given name and encoding.- Parameters:
name
- the template nameencoding
- the template's encoding- Returns:
- the HTML template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateTxt
Instantiates a TXT template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the TXT template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateTxt
Instantiates a TXT template with a given name.- Parameters:
name
- the template name- Returns:
- the TXT template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateTxt
Instantiates a TXT template with a given name and encoding.- Parameters:
name
- the template nameencoding
- the template's encoding- Returns:
- the TXT template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateXml
Instantiates an XML template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the XML template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateXml
Instantiates an XML template with a given name.- Parameters:
name
- the template name- Returns:
- the XML template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateXml
Instantiates an XML template with a given name and encoding.- Parameters:
name
- the template nameencoding
- the template's encoding- Returns:
- the XML template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateJson
Instantiates an JSON template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the JSON template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateJson
Instantiates an JSON template with a given name.- Parameters:
name
- the template name- Returns:
- the JSON template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateJson
Instantiates an JSON template with a given name and encoding.- Parameters:
name
- the template nameencoding
- the template's encoding- Returns:
- the JSON template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateSvg
Instantiates an SVG template with the name corresponding to the identifier of this route's element.For lambda elements, this will be the path of the route and for class elements this will be the shortened uncapitalized name of the class.
- Returns:
- the SVG template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateSvg
Instantiates an SVG template with a given name.- Parameters:
name
- the template name- Returns:
- the SVG template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
templateSvg
Instantiates an SVG template with a given name and encoding.- Parameters:
name
- the template nameencoding
- the template's encoding- Returns:
- the SVG template if it was found.
- Throws:
TemplateException
- when an error occurred instantiating the template- Since:
- 1.0
- See Also:
-
gateUrl
Retrieves the URL portion that corresponds to the entrance gate of the RIFE2 web engine, this is usually equivalent with the HTTP request context path.- Returns:
- the URL of the web engine gate
- Since:
- 1.0
-
serverRootUrl
Returns the root URL of the server that is running this web applications.This includes the protocol, the server name and the server port, for example:
http://www.somehost.com:8080
.- Parameters:
port
- the server port to use, or-1
to use the sane port as the active request- Returns:
- the server's root url
- Since:
- 1.0
-
webappRootUrl
Returns the root URL of this web application.This includes the protocol, the server name and the server port, and the gate URL.
- Returns:
- this web application's root URL
- Since:
- 1.0
-
webappRootUrl
Returns the root URL of this web application.This includes the protocol, the server name and the server port, and the gate URL.
- Parameters:
port
- the server port to use, or-1
to use the sane port as the active request- Returns:
- this web application's root URL
- Since:
- 1.0
-
urlFor
Start building a URL towards a particular route.The result is a instance that can be used for further customization of the URL, if needed.
- Parameters:
route
- the target route- Returns:
- an instance of
- Since:
- 1.0
-
engineException
Retrieves the exception that was triggered during the RIFE2 web engine execution.- Returns:
- the triggered exception; or
null
if no exception was triggered - Since:
- 1.0
-
selectParameter
Sets a select box option, a radio button or a checkbox to selected or checked.This method delegates all logic to the
FormBuilder.selectParameter(Template, String, String[])
method of the provided template instance.- Parameters:
template
- the template instance where the selection should happenname
- the name of the parametervalues
- the values that should be selected or checked- Returns:
- a list with the identifiers of the template values that have
been set, this is never
null
, when no values are set an empty list is returned - Since:
- 1.0
- See Also:
-
generateForm
Generates a form that corresponds to a bean instance.- Parameters:
template
- the template instance where the generation should happenbeanInstance
- the instance of the bean that should be used to generate the form- Since:
- 1.0
- See Also:
-
generateForm
Generates a form that corresponds to a bean instance.This method delegates all logic to the
FormBuilder.generateForm(Template, Object, Map, String)
method of the provided template instance.- Parameters:
template
- the template instance where the generation should happenbeanInstance
- the instance of the bean that should be used to generate the formprefix
- the prefix that will be prepended to all bean property names- Since:
- 1.0
- See Also:
-
generateEmptyForm
Generates a form that corresponds to an empty instance of a bean class.- Parameters:
template
- the template instance where the generation should happenbeanClass
- the class of the bean that should be used to generate the form- Since:
- 1.0
- See Also:
-
generateEmptyForm
Generates a form that corresponds to an empty instance of a bean class.An 'empty' instance is an object that has been created by calling the default constructor of the bean class, without making any additional changes to it afterward.
This method delegates all logic to the
FormBuilder.generateForm(Template, Class, Map, String)
method of the provided template instance.- Parameters:
template
- the template instance where the generation should happenbeanClass
- the class of the bean that should be used to generate the formprefix
- the prefix that will be prepended to all bean property names- Since:
- 1.0
- See Also:
-
removeForm
Removes a generated form, leaving the builder value tags empty again as if this form had never been generated.- Parameters:
template
- the template instance where the form should be removed frombeanClass
- the class of the bean that should be used to remove the form- Since:
- 1.0
- See Also:
-
removeForm
Removes a generated form, leaving the builder value tags empty again as if this form had never been generated.This method delegates all logic to the
FormBuilder.removeForm(Template, Class, String)
method of the provided template instance.- Parameters:
template
- the template instance where the form should be removed frombeanClass
- the class of the bean that should be used to remove the formprefix
- the prefix that will be prepended to all bean property names- Since:
- 1.0
- See Also:
-
defer
Interrupts the execution in RIFE2 completely and defers it to the servlet container.If RIFE2 is being run as a filter, it will execute the next filter in the chain.
If RIFE2 is being run as a servlet, the status code
404: Not Found
will be sent to the client.- Throws:
DeferException
- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
redirect
Interrupts the execution in this element and redirects the client to another URL.- Parameters:
url
- the URL to which the request will be redirected,String.valueOf()
will be called with this object, so a variety of types can be used- Throws:
RedirectException
- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
redirect
Interrupts the execution in this element and redirects the client to another URL.- Parameters:
route
- the route to which the request will be redirected- Throws:
RedirectException
- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
respond
public void respond()Interrupts the execution in this element, stops processing any other element, and sends the current response directly to the client.- Throws:
RespondException
- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
next
public void next()Interrupts the execution in this element, moving processing on to the next element in the before/route/after chain- Throws:
NextException
- an exception that is used to immediately interrupt the execution, don't catch this exception- Since:
- 1.0
-
preventCaching
public void preventCaching()Sets up the current response to prevent all caching of the response by the client.- Since:
- 1.0
-
method
Returns the HTTPRequestMethod
with which this context's request was made.- Returns:
- the
RequestMethod
of this context's request - Since:
- 1.0
-
parameters
Retrieves the parameters that were sent to this context.- Returns:
- a
Map
with all the parameter names and values - Since:
- 1.0
-
hasParameterValue
Checks whether a value has been provided to a parameter.- Parameters:
name
- the name of the parameter- Returns:
true
if the parameter has a value; orfalse
otherwise- Since:
- 1.0
- See Also:
-
isParameterEmpty
Checks whether a parameter is empty.- Parameters:
name
- the name of the parameter- Returns:
true
if the parameter is empty; orfalse
otherwise- Since:
- 1.0
- See Also:
-
parameter
Retrieves the value of a parameter.- Parameters:
name
- the name of the parameter- Returns:
- the value of the parameter; or
null
if no value is present for this parameter - Since:
- 1.0
- See Also:
-
parameter
Retrieves the value of a parameter and returns a default value if no parameter value is present- Parameters:
name
- the name of the parameterdefaultValue
- the default value that will be used when no parameter value is present- Returns:
- the parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterNames
Retrieves the names of all the parameters that are present.- Returns:
- the list with the parameter names
- Since:
- 1.0
- See Also:
-
parameterValues
Retrieves the values of a parameter.- Parameters:
name
- the name of the parameter- Since:
- 1.0
- See Also:
-
parameterBoolean
Retrieves the value of a parameter and converts it to a boolean.- Parameters:
name
- the name of the parameter- Returns:
- the converted parameter value; or
false
if no parameter value is present or if the parameter value is not a valid boolean - Since:
- 1.0
- See Also:
-
parameterBoolean
Retrieves the value of a parameter and converts it to a boolean, using a default value if no parameter value is present.- Parameters:
name
- the name of the parameterdefaultValue
- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterInt
Retrieves the value of a parameter and converts it to an integer.- Parameters:
name
- the name of the parameter- Returns:
- the converted parameter value; or
0
if no parameter value is present or if the parameter value is not a valid integer - Since:
- 1.0
- See Also:
-
parameterInt
Retrieves the value of a parameter and converts it to an integer, using a default value if no parameter value is present.- Parameters:
name
- the name of the parameterdefaultValue
- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterLong
Retrieves the value of a parameter and converts it to a long.- Parameters:
name
- the name of the parameter- Returns:
- the converted parameter value; or
0L
if no parameter value is present or if the parameter value is not a valid long - Since:
- 1.0
- See Also:
-
parameterLong
Retrieves the value of a parameter and converts it to a long, using a default value if no parameter value is present.- Parameters:
name
- the name of the parameterdefaultValue
- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterDouble
Retrieves the value of a parameter and converts it to a double.- Parameters:
name
- the name of the parameter- Returns:
- the converted parameter value; or
0.0d
if no parameter value is present or if the parameter value is not a valid double - Since:
- 1.0
- See Also:
-
parameterDouble
Retrieves the value of a parameter and converts it to a double, using a default value if no parameter value is present.- Parameters:
name
- the name of the parameterdefaultValue
- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterFloat
Retrieves the value of a parameter and converts it to a float.- Parameters:
name
- the name of the parameter- Returns:
- the converted parameter value; or
0.0f
if no parameter value is present or if the parameter value is not a valid float - Since:
- 1.0
- See Also:
-
parameterFloat
Retrieves the value of a parameter and converts it to a float, using a default value if no parameter value is present.- Parameters:
name
- the name of the parameterdefaultValue
- the default value that will be used when no parameter value is present- Returns:
- the converted parameter value; or
the default value if no parameter value is present
- Since:
- 1.0
- See Also:
-
parameterInts
Retrieves the values of a parameter as an array of integers.- Parameters:
name
- the name of the parameter- Returns:
- an integer array with all the parameter values; or
null
if no parameter values are present - Since:
- 1.0
- See Also:
-
parameterLongs
Retrieves the values of a parameter as an array of longs.- Parameters:
name
- the name of the parameter- Returns:
- a long array with all the parameter values; or
null
if no parameter values are present - Since:
- 1.0
- See Also:
-
parameterFloats
Retrieves the values of a parameter as an array of floats.- Parameters:
name
- the name of the parameter- Returns:
- a float array with all the parameter values; or
null
if no parameter values are present - Since:
- 1.0
- See Also:
-
parameterDoubles
Retrieves the values of a parameter as an array of doubles.- Parameters:
name
- the name of the parameter- Returns:
- a double array with all the parameter values; or
null
if no parameter values are present - Since:
- 1.0
- See Also:
-
parametersBean
Creates an instance of a bean and populates the properties with the parameter values.This bean is not serialized or de-serialized, each property corresponds to a parameter and is individually sent by the client.
- Parameters:
beanClass
- the class of the submission bean- Returns:
- the populated bean instance
- Throws:
EngineException
- Since:
- 1.0
- See Also:
-
parametersBean
public <BeanType> BeanType parametersBean(Class<BeanType> beanClass, String prefix) throws EngineException Creates an instance of a bean and populates the properties with the parameter values, taking the provided prefix into account.This bean is not serialized or de-serialized, each property corresponds to a parameter and is individually sent by the client.
- Parameters:
beanClass
- the class of the submission beanprefix
- the prefix that will be put in front of each property name- Returns:
- the populated bean instance
- Throws:
EngineException
- Since:
- 1.0
- See Also:
-
parametersBean
Fills the properties of an existing bean with the parameter values.- Parameters:
bean
- the submission bean instance that will be filled- Throws:
EngineException
- Since:
- 1.0
- See Also:
-
parametersBean
Fills the properties of an existing bean with the parameter values that were sent, taking the provided prefix into account.- Parameters:
bean
- the submission bean instance that will be filledprefix
- the prefix that will be put in front of each property name- Throws:
EngineException
- Since:
- 1.0
- See Also:
-
body
Retrieves the body of this context's request as a string.- Returns:
- the string of the request body
- Since:
- 1.0
- See Also:
-
bodyAsBytes
public byte[] bodyAsBytes()Retrieves the body of this context's request as a byte array.- Returns:
- the byte array of the request body
- Since:
- 1.0
- See Also:
-
fileNames
Retrieves the list of uploaded file names.- Returns:
- the set of uploaded file names
- Since:
- 1.0
- See Also:
-
isFileEmpty
Checks if an uploaded file wasn't sent or if it is empty.- Parameters:
name
- the name of the file- Since:
- 1.0
- See Also:
-
files
Retrieves the files that were uploaded in this context.- Returns:
- a
Map
with all the uploaded files - Since:
- 1.0
- See Also:
-
hasFile
Checks if a particular file has been uploaded in this context.- Parameters:
name
- the name of the file- Returns:
true
if the file was uploaded; orfalse
otherwise- Since:
- 1.0
- See Also:
-
file
Retrieves an uploaded file.- Parameters:
name
- the name of the file- Returns:
- the uploaded file; or
null
if no file was uploaded - Since:
- 1.0
- See Also:
-
files
Retrieves all files that have been uploaded for a particular name.- Parameters:
name
- the name of the file- Returns:
- the uploaded files; or
null
if no files were uploaded for that name - Since:
- 1.0
- See Also:
-
hasCookie
Checks whether a cookie is present.- Parameters:
name
- the name of the cookie- Returns:
true
if the cookie was present; orfalse
otherwise- Since:
- 1.0
- See Also:
-
cookieNames
Retrieves the names of the cookies.- Returns:
- a list of strings with the cookie names
- Since:
- 1.0
- See Also:
-
cookieValue
Retrieves the value of a cookie.- Parameters:
name
- the name of the cookie- Returns:
- the value of the cookie; or
null
if no such cookie is present - Since:
- 1.0
- See Also:
-
cookieValues
Retrieves all current cookies names with their values.- Returns:
- a new map of all the current cookies names with their values
- Since:
- 1.0
- See Also:
-
cookieValue
Retrieves the value of a named cookie, using a default value as fallback.- Parameters:
name
- the name of the cookiedefaultValue
- the default value that will be used when no cookie value is present- Returns:
- the cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieBoolean
Retrieves the value of a named cookie and converts it to a boolean.- Parameters:
name
- the name of the cookie- Returns:
- the converted cookie value; or
false
if no cookie value is present or if the cookie value is not a valid boolean - Since:
- 1.0
- See Also:
-
cookieBoolean
Retrieves the value of a named cookie and converts it to a boolean, using a default value if no input value is present.- Parameters:
name
- the name of the cookiedefaultValue
- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieInt
Retrieves the value of a named cookie and converts it to an integer.- Parameters:
name
- the name of the cookie- Returns:
- the converted cookie value; or
0
if no cookie value is present or if the cookie value is not a valid integer - Since:
- 1.0
- See Also:
-
cookieInt
Retrieves the value of a named cookie and converts it to an integer, using a default value if no input value is present.- Parameters:
name
- the name of the cookiedefaultValue
- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieLong
Retrieves the value of a named cookie and converts it to a long.- Parameters:
name
- the name of the cookie- Returns:
- the converted cookie value; or
0L
if no cookie value is present or if the cookie value is not a valid long - Since:
- 1.0
- See Also:
-
cookieLong
Retrieves the value of a named cookie and converts it to a long, using a default value if no input value is present.- Parameters:
name
- the name of the cookiedefaultValue
- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieDouble
Retrieves the value of a named cookie and converts it to a double.- Parameters:
name
- the name of the cookie- Returns:
- the converted cookie value; or
0.0d
if no cookie value is present or if the cookie value is not a valid double - Since:
- 1.0
- See Also:
-
cookieDouble
Retrieves the value of a named cookie and converts it to a double, using a default value if no input value is present.- Parameters:
name
- the name of the cookiedefaultValue
- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
cookieFloat
Retrieves the value of a named cookie and converts it to a float.- Parameters:
name
- the name of the cookie- Returns:
- the converted cookie value; or
0.0
f if no cookie value is present or if the cookie value is not a valid float - Since:
- 1.0
- See Also:
-
cookieFloat
Retrieves the value of a named cookie and converts it to a float, using a default value if no input value is present.- Parameters:
name
- the name of the cookiedefaultValue
- the default value that will be used when no cookie value is present- Returns:
- the converted cookie value; or
the default value if no cookie value is present
- Since:
- 1.0
- See Also:
-
attribute
Returns the value of the named attribute.- Parameters:
name
- the name of the attribute- Returns:
- an Object containing the value of the attribute; or
null
if the attribute does not exist - Since:
- 1.0
- See Also:
-
hasAttribute
Checks if a request attribute exists.- Parameters:
name
- aString
specifying the name of the attributefalse
otherwise- Since:
- 1.0
- See Also:
-
attributeNames
Returns a list of attribute names available to this request.- Returns:
- a list of strings containing the names of the request's attributes; or
an empty list if not attributes are present
- Since:
- 1.0
- See Also:
-
removeAttribute
Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the request is being handled.- Parameters:
name
- the name of the attribute to remove- Since:
- 1.0
- See Also:
-
setAttribute
Stores an attribute in this request. Attributes are reset between requests.Attribute names should follow the same conventions as package names. If the object passed in is
null
, the effect is the same as callingremoveAttribute
.- Parameters:
name
- the name of the attribute to setobject
- the object to store- Since:
- 1.0
- See Also:
-
characterEncoding
Returns the name of the character encoding used in the body of this request.- Returns:
- a
String
containing the name of the character encoding; ornull
if the request does not specify a character encoding - Since:
- 1.0
-
contentType
Returns the MIME type of the body of the request, or null if the type is not known.- Returns:
- a
String
containing the name of the MIME type of the request; ornull
if the type is not known - Since:
- 1.0
-
header
Returns the value of the specified request header as a String.- Parameters:
name
- the case-insensitive name of the header- Returns:
- a
String
with the value of the requested header; ornull
if the request does not have a header of that name - Since:
- 1.0
- See Also:
-
headerDate
Returns the value of the specified request header as a long value that represents a date. Use this method with headers that contain dates, such as If-Modified-Since.- Parameters:
name
- the case-insensitive name of the header- Returns:
- a long value representing the date specified in the header expressed
as the number of milliseconds since January 1, 1970 GMT; or
-1
if the named header was not included with the request - Throws:
IllegalArgumentException
- if the header can't be converted to a date- Since:
- 1.0
- See Also:
-
headerInt
Returns the value of the specified request header as an int.- Parameters:
name
- the case-insensitive name of the header- Returns:
- an integer expressing the value of the request header; or
-1
if the request doesn't have a header of this name - Throws:
NumberFormatException
- if the header value can't be converted to an int- Since:
- 1.0
- See Also:
-
headerNames
Returns a list of all the header names in the request.- Returns:
- a list of all the header names sent with this request;
if the request has no headers, an empty list will be returned
- Since:
- 1.0
- See Also:
-
headers
Returns all the values of the specified request header as a list ofString
objects.Some headers, such as
Accept-Language
can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.- Parameters:
name
- the case-insensitive name of the header- Returns:
- a list containing the values of the requested header;
itf the request does not have any headers of that name an empty list will be returned
- Since:
- 1.0
- See Also:
-
locale
Returns the preferredLocale
that the client will accept content in, based on theAccept-Language
header.If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.
- Returns:
- the preferred Locale for the client
- Since:
- 1.0
-
locales
Returns a list ofLocale
objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on theAccept-Language
} header.If the client request doesn't provide an Accept-Language header, this method returns a list containing one Locale, the default locale for the server.
- Returns:
- a list of preferred Locale objects for the client
- Since:
- 1.0
-
remoteAddr
Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.- Returns:
- a String containing the IP address of the client that sent the request
- Since:
- 1.0
-
remoteUser
Returns the login of the user making this request.Whether the username is sent with each subsequent request depends on the browser and type of authentication.
- Returns:
- a String specifying the login of the user making this request; or
null
if the user login is not known - Since:
- 1.0
-
remoteHost
Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address.- Returns:
- a String containing the fully qualified name of the client
- Since:
- 1.0
-
session
Returns the current session associated with this request, or if the request does not have a session, creates one.- Returns:
- the
Session
associated with this request - Since:
- 1.0
- See Also:
-
session
Returns the currentSession
associated with this request or, if there is no current session andcreate
is true, returns a new session.If
create
isfalse
and the request has no validSession
, this method returnsnull
.- Parameters:
create
-true
to create a new session for this request if necessary;false
to returnnull
if there's no current session- Returns:
- the
Session
associated with this request ornull
ifcreate
isfalse
and the request has no valid session - Since:
- 1.0
-
serverPort
public int serverPort()Returns the port number to which the request was sent.- Returns:
- an integer specifying the port number
- Since:
- 1.0
-
protocol
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.- Returns:
- a String containing the protocol name and version number
- Since:
- 1.0
-
scheme
Returns the name of the scheme used to make this request.- Returns:
- the name of the scheme used to make this request
- Since:
- 1.0
-
serverName
Returns the host name of the server to which the request was sent.- Returns:
- the name of the server
- Since:
- 1.0
-
contextPath
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.- Returns:
- the portion of the request URI that indicates the context of the request
- Since:
- 1.0
-
secure
public boolean secure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.- Returns:
- a boolean indicating whether the request was made using a secure channel
- Since:
- 1.0
-
enableTextBuffer
public void enableTextBuffer(boolean enabled) Enables or disables the response text buffer. By default, it is enabled.Disabling an enabled text buffer, flushes the already buffered content first.
If the text buffer is disabled, text content will be sent immediately to the client, this can decrease performance. Unless you need to stream content in real time, it's best to leave the text buffer enabled. It will be flushed and sent in one go at the end of the request.
- Parameters:
enabled
-true
to enable the text buffer; orfalse
to disable it- Since:
- 1.0
- See Also:
-
textBufferEnabled
public boolean textBufferEnabled()Indicates whether the response text buffer is enabled or disabled.- Returns:
true
if the text buffer is enabled; orfalse
if it is disabled- Since:
- 1.0
- See Also:
-
clearBuffer
public void clearBuffer()Clears the text buffer is it's enabled.If the text buffer is disabled, this method does nothing.
- Since:
- 1.0
-
flush
public void flush()Forces all the streamed content to be output to the client.If the text buffer is enabled, this will flush its content to the output stream first.
- Since:
- 1.0
-
outputStream
Returns an output stream suitable for writing binary data in the response.When possible and applicable, this output stream will automatically handle gzip encoding.
- Returns:
- an
OutputStream
for binary data output - Throws:
EngineException
- Since:
- 1.0
-
setContentType
Sets the content type of the response being sent to the client.- Parameters:
contentType
- the MIME type of the content- Since:
- 1.0
-
setContentLength
public void setContentLength(int length) Sets the length of the content body in the response.- Parameters:
length
- an integer specifying the length of the content being returned to the client- Since:
- 1.0
-
setLocale
Sets the locale of the response.- Parameters:
locale
- the locale of the response- Since:
- 1.0
-
setParameter
Sets a named parameter value for URL generation withurlFor(rife.engine.Route)
or the `route:` filtered template value tags.The parameter value will be converted to a string array.
Setting parameters acts on a different collection than incoming request parameters and is used for RIFE2 state-related features like URL generation.
- Parameters:
name
- the name of the parameter to setvalue
- the value of the parameter- Since:
- 1.0
- See Also:
-
setParametersBean
Sets named parameters values from bean properties for URL generation withurlFor(rife.engine.Route)
or the `route:` filtered template value tags.- Parameters:
bean
- the bean whose properties will be set as parameters- Since:
- 1.0
- See Also:
-
setParametersBean
Sets named parameters values from bean properties for URL generation withurlFor(rife.engine.Route)
or the `route:` filtered template value tags.- Parameters:
bean
- the bean whose properties will be set as parametersprefix
- the prefix that will be added to the parameter names- Since:
- 1.0
- See Also:
-
removeParameter
Removes a name parameter that was previously set.- Parameters:
name
- the name of the parameter to remove- Since:
- 1.0
- See Also:
-
addCookie
Adds theCookie
created by aCookieBuilder
to the response. This method can be called multiple times to set more than one cookie.- Parameters:
builder
- theCookieBuilder
to use for building theCookie
- Since:
- 1.0
-
removeCookie
Removes a cookie with path"/"
.- Parameters:
name
- name of the cookie- Since:
- 1.0
-
removeCookie
Removes a cookie with given path and name.- Parameters:
path
- path of the cookiename
- name of the cookie- Since:
- 1.0
-
setHeader
Sets a response header with the given name and value.If the header had already been set, the new value overwrites the previous one.
- Parameters:
name
- the name of the headervalue
- the additional header value- Since:
- 1.0
-
addHeader
Adds a response header with the given name and value.This method allows response headers to have multiple values.
- Parameters:
name
- the name of the headervalue
- the additional header value- Since:
- 1.0
-
setDateHeader
Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch.If the header had already been set, the new value overwrites the previous one.
- Parameters:
name
- the name of the header to setdate
- the additional date value- Since:
- 1.0
-
addDateHeader
Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch.This method allows response headers to have multiple values.
- Parameters:
name
- the name of the header to setdate
- the additional date value- Since:
- 1.0
-
setHeader
Adds a response header with the given name and integer value.If the header had already been set, the new value overwrites the previous one.
- Parameters:
name
- the name of the headervalue
- the assigned integer value- Since:
- 1.0
-
addHeader
Adds a response header with the given name and integer value.This method allows response headers to have multiple values.
- Parameters:
name
- the name of the headervalue
- the assigned integer value- Since:
- 1.0
-
setStatus
public void setStatus(int statusCode) Sets the status code for the response.- Parameters:
statusCode
- the status code- Since:
- 1.0
-