Request.Flash, Request.Forwarding
Constructor and Description |
---|
Forwarding(Request request)
Creates a new
Request.Forwarding request. |
Modifier and Type | Method and Description |
---|---|
List<MediaType> |
accept() |
Optional<MediaType> |
accepts(List<MediaType> types)
Check if the given types are acceptable, returning the best match when true, or else
Optional.empty.
|
Optional<MediaType> |
accepts(MediaType... types)
Check if the given types are acceptable, returning the best match when true, or else
Optional.empty.
|
Optional<MediaType> |
accepts(String... types)
Check if the given types are acceptable, returning the best match when true, or else
Optional.empty.
|
Map<String,Object> |
attributes()
A read only version of the current locals.
|
Mutant |
body()
HTTP body.
|
<T> T |
body(Class<T> type)
Short version of
body().to(type) . |
Charset |
charset()
The charset defined in the request body.
|
String |
contextPath()
Application path (a.k.a context path).
|
Mutant |
cookie(String name)
Get a cookie with the given name (if present).
|
List<Cookie> |
cookies() |
Upload |
file(String name)
Get a file
Upload with the given name. |
List<Upload> |
files(String name)
Get a list of file
Upload with the given name. |
Request.Flash |
flash()
Give you access to flash scope.
|
String |
flash(String name)
Get a flash attribute value or throws
BAD_REQUEST error if missing. |
Request |
flash(String name,
Object value)
Set a flash attribute.
|
<T> T |
get(String name)
Get a request local attribute.
|
<T> T |
get(String name,
T def)
Get a request local attribute.
|
Mutant |
header(String name)
Get a HTTP header.
|
Mutant |
header(String name,
String... xss)
Get a HTTP header and apply the XSS escapers.
|
Map<String,Mutant> |
headers() |
String |
hostname()
The fully qualified name of the resource being requested, as obtained from the Host HTTP
header.
|
Optional<String> |
ifFlash(String name)
Get an optional for the given flash attribute's name.
|
<T> Optional<T> |
ifGet(String name)
Get a request local attribute.
|
Optional<Session> |
ifSession() |
String |
ip() |
boolean |
is(List<MediaType> types)
True, if request accept any of the given types.
|
boolean |
is(MediaType... types)
True, if request accept any of the given types.
|
boolean |
is(String... types)
True, if request accept any of the given types.
|
boolean |
isSet(String name) |
long |
length() |
Locale |
locale()
Get a locale that best matches the current request or the default locale as specified
in
application.lang . |
Locale |
locale(BiFunction<List<Locale.LanguageRange>,List<Locale>,Locale> filter)
Get a locale that best matches the current request.
|
List<Locale> |
locales()
Get a list of locale that best matches the current request as per
Locale.filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>, java.util.Locale.FilteringMode) . |
List<Locale> |
locales(BiFunction<List<Locale.LanguageRange>,List<Locale>,List<Locale>> filter)
Get a list of locale that best matches the current request.
|
boolean |
matches(String pattern)
Test if the given request path matches the pattern.
|
String |
method() |
Mutant |
param(String name)
Get a HTTP request parameter under the given name.
|
Mutant |
param(String name,
String... xss)
Get a HTTP request parameter under the given name.
|
Mutant |
params()
Get all the available parameters.
|
<T> T |
params(Class<T> type)
Short version of
params().to(type) . |
<T> T |
params(Class<T> type,
String... xss)
Short version of
params(xss).to(type) . |
Mutant |
params(String... xss)
Get all the available parameters.
|
String |
path()
Given:
|
String |
path(boolean escape)
Escape the path using
UrlEscapers.urlFragmentEscaper() . |
int |
port() |
String |
protocol() |
Request |
push(String path)
Send a push promise frame to the client and push the resource identified by the given path.
|
Request |
push(String path,
Map<String,Object> headers)
Send a push promise frame to the client and push the resource identified by the given path.
|
Optional<String> |
queryString()
The query string, without the leading
? . |
String |
rawPath()
Raw path, like
Request.path() but without decoding. |
<T> T |
require(Class<T> type)
Request a service of the given type.
|
<T> T |
require(com.google.inject.Key<T> key)
Request a service of the given key.
|
<T> T |
require(com.google.inject.TypeLiteral<T> type)
Request a service of the given type.
|
Route |
route() |
boolean |
secure() |
Session |
session() |
Request |
set(Class<?> type,
Object value)
Seed a
RequestScoped object. |
Request |
set(com.google.inject.Key<?> key,
Object value)
Seed a
RequestScoped object. |
Request |
set(String name,
Object value)
Set local attribute.
|
Request |
set(com.google.inject.TypeLiteral<?> type,
Object value)
Seed a
RequestScoped object. |
long |
timestamp()
Request timestamp.
|
String |
toString() |
MediaType |
type() |
<T> Optional<T> |
unset(String name)
Remove a request local attribute.
|
static Request |
unwrap(Request req)
Unwrap a request in order to find out the target instance.
|
boolean |
xhr() |
public Forwarding(Request request)
Request.Forwarding
request.request
- A target request.public String path()
Request
http://domain.com/some/path.html -> /some/path.html http://domain.com/a.html -> /a.html
public String rawPath()
Request
Request.path()
but without decoding.rawPath
in interface Request
Request.path()
but without decoding.public Optional<String> queryString()
Request
?
.queryString
in interface Request
?
.public String path(boolean escape)
Request
UrlEscapers.urlFragmentEscaper()
.
Given:
http://domain.com/404<h1>X</h1> {@literal ->} /404%3Ch1%3EX%3C/h1%3E
public boolean matches(String pattern)
Request
public String contextPath()
Request
application.path
. Default is: /
contextPath
in interface Request
public MediaType type()
public Optional<MediaType> accepts(List<MediaType> types)
Request
// Accept: text/html req.accepts("text/html"); // => "text/html" // Accept: text/*, application/json req.accepts("text/html"); // => "text/html" req.accepts("text/html"); // => "text/html" req.accepts("application/json" "text/plain"); // => "application/json" req.accepts("application/json"); // => "application/json" // Accept: text/*, application/json req.accepts("image/png"); // => Optional.empty // Accept: text/*;q=.5, application/json req.accepts("text/html", "application/json"); // => "application/json"
public Optional<MediaType> accepts(MediaType... types)
Request
// Accept: text/html req.accepts("text/html"); // => "text/html" // Accept: text/*, application/json req.accepts("text/html"); // => "text/html" req.accepts("text/html"); // => "text/html" req.accepts("application/json" "text/plain"); // => "application/json" req.accepts("application/json"); // => "application/json" // Accept: text/*, application/json req.accepts("image/png"); // => Optional.empty // Accept: text/*;q=.5, application/json req.accepts("text/html", "application/json"); // => "application/json"
public Optional<MediaType> accepts(String... types)
Request
// Accept: text/html req.accepts("text/html"); // => "text/html" // Accept: text/*, application/json req.accepts("text/html"); // => "text/html" req.accepts("text/html"); // => "text/html" req.accepts("application/json" "text/plain"); // => "application/json" req.accepts("application/json"); // => "application/json" // Accept: text/*, application/json req.accepts("image/png"); // => Optional.empty // Accept: text/*;q=.5, application/json req.accepts("text/html", "application/json"); // => "application/json"
public boolean is(List<MediaType> types)
Request
public boolean is(MediaType... types)
Request
public boolean is(String... types)
Request
public boolean isSet(String name)
public Mutant params()
Request
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
public Mutant params(String... xss)
Request
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
public <T> T params(Class<T> type)
Request
params().to(type)
.public <T> T params(Class<T> type, String... xss)
Request
params(xss).to(type)
.public Mutant param(String name)
Request
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
path
, query
and body
. For
example a pattern like: GET /path/:name
for /path/jooby?name=rocks
produces:
assertEquals("jooby", req.param(name).value()); assertEquals("jooby", req.param(name).toList().get(0)); assertEquals("rocks", req.param(name).toList().get(1));Uploads can be retrieved too when
Content-Type
is multipart/form-data
see Upload
for more information.public Mutant param(String name, String... xss)
Request
/path/:name
or /path/{name}
?name=jooby
Content-Type
is
application/x-www-form-urlencoded
or multipart/form-data
path
, query
and body
. For
example a pattern like: GET /path/:name
for /path/jooby?name=rocks
produces:
assertEquals("jooby", req.param(name).value()); assertEquals("jooby", req.param(name).toList().get(0)); assertEquals("rocks", req.param(name).toList().get(1));Uploads can be retrieved too when
Content-Type
is multipart/form-data
see Upload
for more information.public Upload file(String name) throws IOException
Request
Upload
with the given name. The request must be a POST with
multipart/form-data
content-type.file
in interface Request
name
- File's name.Upload
.IOException
public List<Upload> files(String name) throws IOException
Request
Upload
with the given name. The request must be a POST with
multipart/form-data
content-type.files
in interface Request
name
- File's name.Upload
.IOException
public Mutant header(String name)
Request
public Mutant header(String name, String... xss)
Request
public Mutant cookie(String name)
Request
public Mutant body() throws Exception
Request
raw
data or a data like json, xml, etc...public <T> T body(Class<T> type) throws Exception
Request
body().to(type)
.
HTTP body. Please don't use this method for form submits. This method is used for getting
raw
or a parsed data like json, xml, etc...public <T> T require(Class<T> type)
Registry
public <T> T require(com.google.inject.TypeLiteral<T> type)
Registry
public <T> T require(com.google.inject.Key<T> key)
Registry
public Charset charset()
Request
application.charset
.public long length()
public Locale locale()
Request
application.lang
.public Locale locale(BiFunction<List<Locale.LanguageRange>,List<Locale>,Locale> filter)
Request
Accept-Language
as
Locale.LanguageRange
and filter while the second argument is a list of supported
locales defined by the application.lang
property.
The next example returns a Locale
instance for the best-matching language
tag using the lookup mechanism defined in RFC 4647.
req.locale(Locale::lookup)
public List<Locale> locales(BiFunction<List<Locale.LanguageRange>,List<Locale>,List<Locale>> filter)
Request
Accept-Language
as
Locale.LanguageRange
and filter while the second argument is a list of supported
locales defined by the application.lang
property.
The next example returns a list of matching Locale
instances using the filtering
mechanism defined in RFC 4647:
req.locales(Locale::filter)
public List<Locale> locales()
Request
Locale.filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>, java.util.Locale.FilteringMode)
.public String ip()
public int port()
public Route route()
public Session session()
public String hostname()
Request
public String protocol()
public boolean secure()
public boolean xhr()
public Map<String,Object> attributes()
Request
attributes
in interface Request
public <T> Optional<T> ifGet(String name)
Request
public <T> T get(String name)
Request
public <T> T get(String name, T def)
Request
public Request set(String name, Object value)
Request
public Request set(com.google.inject.Key<?> key, Object value)
Request
RequestScoped
object.public Request set(Class<?> type, Object value)
Request
RequestScoped
object.public Request set(com.google.inject.TypeLiteral<?> type, Object value)
Request
RequestScoped
object.public <T> Optional<T> unset(String name)
Request
public Request.Flash flash() throws NoSuchElementException
Request
{
use(new FlashScope());
get("/", req -> {
Map<String, String> flash = req.flash();
return flash;
});
}
As you can see in the example above, the FlashScope
needs to be install it by calling
Jooby.use(org.jooby.Jooby.Module)
otherwise a call to this method ends in
BAD_REQUEST
.flash
in interface Request
FlashScope
.NoSuchElementException
public String flash(String name) throws NoSuchElementException
Request
BAD_REQUEST error
if missing.flash
in interface Request
name
- Attribute's name.NoSuchElementException
public Request flash(String name, Object value)
Request
flash.
. For example a call to
flash("success", "OK")
is accessible from template engines using
flash.success
public Optional<String> ifFlash(String name)
Request
public Request push(String path)
Request
public Request push(String path, Map<String,Object> headers)
Request
public long timestamp()
Request
public static Request unwrap(Request req)
req
- A request.Request.Forwarding
).Copyright © 2017. All rights reserved.