Response.Formatter, Response.Forwarding
Constructor and Description |
---|
Forwarding(Response response)
Creates a new
Response.Forwarding response. |
Modifier and Type | Method and Description |
---|---|
Charset |
charset()
If charset is not set this method returns charset defined in the request body.
|
Response |
charset(Charset charset)
Set the
Charset to use and set the Content-Type header with the current
charset. |
Response |
clearCookie(String name)
Discard a cookie from response.
|
boolean |
committed()
Returns a boolean indicating if the response has been committed.
|
Response |
cookie(Cookie.Definition cookie)
Adds the specified cookie to the response.
|
Response |
cookie(Cookie cookie)
Adds the specified cookie to the response.
|
Response |
cookie(String name,
String value)
Adds the specified cookie to the response.
|
void |
download(File file)
Transfer the file at path as an "attachment".
|
void |
download(String filename)
Transfer the file at path as an "attachment".
|
void |
download(String filename,
File file)
Transfer the file at path as an "attachment".
|
void |
download(String filename,
InputStream stream)
Transfer the file at path as an "attachment".
|
void |
download(String filename,
Reader reader)
Transfer the file at path as an "attachment".
|
void |
download(String filename,
String location)
Transfer the file at path as an "attachment".
|
Response.Formatter |
format()
Performs content-negotiation on the Accept HTTP header on the request object.
|
Mutant |
header(String name)
Get a header with the given name.
|
Response |
header(String name,
byte value)
Sets a response header with the given name and value.
|
Response |
header(String name,
char value)
Sets a response header with the given name and value.
|
Response |
header(String name,
CharSequence value)
Sets a response header with the given name and value.
|
Response |
header(String name,
Date value)
Sets a response header with the given name and value.
|
Response |
header(String name,
double value)
Sets a response header with the given name and value.
|
Response |
header(String name,
float value)
Sets a response header with the given name and value.
|
Response |
header(String name,
int value)
Sets a response header with the given name and value.
|
Response |
header(String name,
long value)
Sets a response header with the given name and value.
|
Response |
header(String name,
short value)
Sets a response header with the given name and value.
|
Response |
length(int length)
Set the length of the response and set the
Content-Length header. |
<T> T |
local(String name)
Get a local variable by it's name.
|
Response |
local(String name,
Object value)
Put a local using a var's name.
|
Map<String,Object> |
locals()
Response local variables are scoped to the request, and therefore only available to the view(s)
rendered during that request / response cycle.
|
void |
redirect(Status status,
String location)
Redirect to the given url with status code defaulting to
Status.FOUND . |
void |
redirect(String location)
Redirect to the given url with status code defaulting to
Status.FOUND . |
void |
send(Body body)
Responsible of writing the given body into the HTTP response.
|
void |
send(Object body)
Responsible of writing the given body into the HTTP response.
|
Optional<Status> |
status() |
Response |
status(int status)
Set the HTTP response status.
|
Response |
status(Status status)
Set the HTTP response status.
|
String |
toString() |
Optional<MediaType> |
type() |
Response |
type(MediaType type)
Set the response media type and set the
Content-Type header. |
Response |
type(String type)
Set the response media type and set the
Content-Type header. |
static Response |
unwrap(Response rsp)
Unwrap a response in order to find out the target instance.
|
public Forwarding(Response response)
Response.Forwarding
response.response
- A response object.public void download(String filename, InputStream stream) throws Exception
Response
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename.public void download(String filename, Reader reader) throws Exception
Response
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename.public void download(File file) throws Exception
Response
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename by default.public void download(String filename, File file) throws Exception
Response
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename.public void download(String filename) throws Exception
Response
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename by default.public void download(String filename, String location) throws Exception
Response
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename by default.public Response cookie(String name, String value)
Response
public Response cookie(Cookie cookie)
Response
public Response cookie(Cookie.Definition cookie)
Response
public Response clearCookie(String name)
Response
clearCookie
in interface Response
name
- Cookie's name.public Mutant header(String name)
Response
public Response header(String name, byte value)
Response
public Response header(String name, char value)
Response
public Response header(String name, Date value)
Response
public Response header(String name, double value)
Response
public Response header(String name, float value)
Response
public Response header(String name, int value)
Response
public Response header(String name, long value)
Response
public Response header(String name, short value)
Response
public Response header(String name, CharSequence value)
Response
public Charset charset()
Response
application.charset
.public Response charset(Charset charset)
Response
Charset
to use and set the Content-Type
header with the current
charset.public Response length(int length)
Response
Content-Length
header.public <T> T local(String name)
Response
public Response local(String name, Object value)
Response
public Map<String,Object> locals()
Response
public Response type(MediaType type)
Response
Content-Type
header.public Response type(String type)
Response
Content-Type
header.public void send(Object body) throws Exception
Response
Body.Formatter
that
best matches the Accept
header will be selected for writing the response.public void send(Body body) throws Exception
Response
Body.Formatter
that
best matches the Accept
header will be selected for writing the response.public Response.Formatter format()
Response
** / *
.
get("/jsonOrHtml", (req, rsp) -> rsp.format() .when("text/html", () -> Viewable.of("view", model)) .when("application/json", () -> model) .when("*", () -> Status.NOT_ACCEPTABLE) .send() );
public void redirect(String location) throws Exception
Response
Status.FOUND
.
rsp.redirect("/foo/bar"); rsp.redirect("http://example.com"); rsp.redirect("http://example.com"); rsp.redirect("../login");Redirects can be a fully qualified URI for redirecting to a different site:
rsp.redirect("http://google.com");Redirects can be relative to the root of the host name. For example, if you were on
http://example.com/admin/post/new
, the following redirect to /admin would
land you at http://example.com/admin
:
rsp.redirect("/admin");Redirects can be relative to the current URL. A redirection of post/new, from
http://example.com/blog/admin/
(notice the trailing slash), would give you
http://example.com/blog/admin/post/new.
rsp.redirect("post/new");Redirecting to post/new from
http://example.com/blog/admin
(no trailing slash),
will take you to http://example.com/blog/post/new
.
If you found the above behavior confusing, think of path segments as directories (have trailing slashes) and files, it will start to make sense.
Pathname relative redirects are also possible. If you were onhttp://example.com/admin/post/new
, the following redirect would land you at
http//example.com/admin
:
rsp.redirect("..");A back redirection will redirect the request back to the
Referer
, defaulting to
/
when missing.
rsp.redirect("back");
public void redirect(Status status, String location) throws Exception
Response
Status.FOUND
.
rsp.redirect("/foo/bar"); rsp.redirect("http://example.com"); rsp.redirect("http://example.com"); rsp.redirect("../login");Redirects can be a fully qualified URI for redirecting to a different site:
rsp.redirect("http://google.com");Redirects can be relative to the root of the host name. For example, if you were on
http://example.com/admin/post/new
, the following redirect to /admin would
land you at http://example.com/admin
:
rsp.redirect("/admin");Redirects can be relative to the current URL. A redirection of post/new, from
http://example.com/blog/admin/
(notice the trailing slash), would give you
http://example.com/blog/admin/post/new.
rsp.redirect("post/new");Redirecting to post/new from
http://example.com/blog/admin
(no trailing slash),
will take you to http://example.com/blog/post/new
.
If you found the above behavior confusing, think of path segments as directories (have trailing slashes) and files, it will start to make sense.
Pathname relative redirects are also possible. If you were onhttp://example.com/admin/post/new
, the following redirect would land you at
http//example.com/admin
:
rsp.redirect("..");A back redirection will redirect the request back to the
Referer
, defaulting to
/
when missing.
rsp.redirect("back");
public Response status(Status status)
Response
public Response status(int status)
Response
public boolean committed()
Response
public static Response unwrap(@Nonnull Response rsp)
rsp
- A response.Response.Forwarding
).Copyright © 2014. All rights reserved.