public class Result extends Object
Constructor and Description |
---|
Result(int status)
Create a result with no entity.
|
Result(int status,
HttpEntity body)
Create a result.
|
Result(int status,
Map<String,String> headers)
Create a result with no body.
|
Result(int status,
Map<String,String> headers,
HttpEntity body)
Create a result.
|
Result(int status,
String reasonPhrase,
Map<String,String> headers,
HttpEntity body)
Create a result.
|
Result(ResponseHeader header,
HttpEntity body)
Create a result from a Scala ResponseHeader and a body.
|
Result(ResponseHeader header,
HttpEntity body,
Http.Session session,
Http.Flash flash,
List<Http.Cookie> cookies)
Create a result from a Scala ResponseHeader and a body.
|
Modifier and Type | Method and Description |
---|---|
Result |
addingToSession(Http.Request request,
Map<String,String> values)
Adds values to the session.
|
Result |
addingToSession(Http.Request request,
String key,
String value)
Adds the given key and value to the session.
|
Result |
as(String contentType)
Return a copy of the result with a different Content-Type header.
|
play.api.mvc.Result |
asScala()
Convert this result to a Scala result.
|
HttpEntity |
body()
Get the body of this result.
|
Optional<String> |
charset()
Extracts the Charset of this Result value.
|
Optional<String> |
contentType()
Extracts the Content-Type of this Result value.
|
Optional<Http.Cookie> |
cookie(String name)
Extracts a Cookie value from this Result value
|
Http.Cookies |
cookies()
Extracts the Cookies (an iterator) from this result value.
|
Result |
discardingCookie(String name)
Discard a cookie on the default path ("/") with no domain and that's not secure.
|
Result |
discardingCookie(String name,
String path)
Discard a cookie on the given path with no domain and not that's secure.
|
Result |
discardingCookie(String name,
String path,
String domain)
Discard a cookie on the given path and domain that's not secure.
|
Result |
discardingCookie(String name,
String path,
String domain,
boolean secure)
Discard a cookie in this result
|
Http.Flash |
flash()
Extracts the Flash values of this Result value.
|
Result |
flashing(Map<String,String> values)
Adds values to the flash.
|
Result |
flashing(String key,
String value)
Adds the given key and value to the flash.
|
Optional<Http.Cookie> |
getCookie(String name)
Deprecated.
Deprecated as of 2.8.0. Renamed to
cookie(String) |
protected ResponseHeader |
getHeader()
Get the response header
|
Optional<String> |
header(String header)
Extracts an Header value of this Result value.
|
Map<String,String> |
headers()
Extracts all Headers of this Result value.
|
Optional<String> |
reasonPhrase()
Get the reason phrase, if it was set.
|
Optional<String> |
redirectLocation()
Extracts the Location header of this Result value if this Result is a Redirect.
|
Result |
removingFromFlash(String... keys)
Removes values from the flash.
|
Result |
removingFromSession(Http.Request request,
String... keys)
Removes values from the session.
|
Http.Session |
session()
Extracts the Session of this Result value.
|
Http.Session |
session(Http.Request request) |
int |
status()
Get the status.
|
Result |
withCookies(Http.Cookie... newCookies)
Returns a copy of this result with the given cookies.
|
Result |
withFlash(Http.Flash flash)
Sets a new flash for this result, discarding the existing flash.
|
Result |
withFlash(Map<String,String> flash)
Sets a new flash for this result, discarding the existing flash.
|
Result |
withHeader(String name,
String value)
Return a copy of this result with the given header.
|
Result |
withHeaders(String... nameValues)
Return a copy of this result with the given headers.
|
Result |
withLang(Lang lang,
MessagesApi messagesApi)
Returns a new result with the given lang set in a cookie.
|
Result |
withLang(Locale locale,
MessagesApi messagesApi)
Returns a new result with the given lang set in a cookie.
|
Result |
withNewFlash()
Discards the existing flash for this result.
|
Result |
withNewSession()
Discards the existing session for this result.
|
Result |
withoutHeader(String name)
Discard a HTTP header in this result.
|
Result |
withoutLang(MessagesApi messagesApi)
Clears the lang cookie from this result.
|
Result |
withSession(Http.Session session)
Sets a new session for this result, discarding the existing session.
|
Result |
withSession(Map<String,String> session)
Sets a new session for this result, discarding the existing session.
|
public Result(ResponseHeader header, HttpEntity body, Http.Session session, Http.Flash flash, List<Http.Cookie> cookies)
header
- the response headerbody
- the response body.session
- the session set on the response.flash
- the flash object on the response.cookies
- the cookies set on the response.public Result(ResponseHeader header, HttpEntity body)
header
- the response headerbody
- the response body.public Result(int status, String reasonPhrase, Map<String,String> headers, HttpEntity body)
status
- The status.reasonPhrase
- The reason phrase, if a non default reason phrase is required.headers
- The headers.body
- The body.public Result(int status, Map<String,String> headers, HttpEntity body)
status
- The status.headers
- The headers.body
- The body.public Result(int status, Map<String,String> headers)
status
- The status.headers
- The headers.public Result(int status, HttpEntity body)
status
- The status.body
- The entity.public Result(int status)
status
- The status.public int status()
public Optional<String> reasonPhrase()
protected ResponseHeader getHeader()
public HttpEntity body()
public Optional<String> redirectLocation()
public Optional<String> header(String header)
header
- the header name.public Map<String,String> headers()
The returned map is not modifiable.
public Optional<String> contentType()
public Optional<String> charset()
public Http.Flash flash()
public Result withFlash(Http.Flash flash)
flash
- the flash to set with this resultpublic Result withFlash(Map<String,String> flash)
flash
- the flash to set with this resultpublic Result withNewFlash()
public Result flashing(Map<String,String> values)
values
- A map with values to add to this result's flashpublic Result flashing(String key, String value)
key
- The key to add to this result's flashvalue
- The value to add to this result's flashpublic Result removingFromFlash(String... keys)
keys
- Keys to remove from flashpublic Http.Session session()
public Http.Session session(Http.Request request)
request
- Current requestpublic Result withSession(Http.Session session)
session
- the session to set with this resultpublic Result withSession(Map<String,String> session)
session
- the session to set with this resultpublic Result withNewSession()
public Result addingToSession(Http.Request request, Map<String,String> values)
values
- A map with values to add to this result's sessionpublic Result addingToSession(Http.Request request, String key, String value)
key
- The key to add to this result's sessionvalue
- The value to add to this result's sessionpublic Result removingFromSession(Http.Request request, String... keys)
keys
- Keys to remove from sessionpublic Optional<Http.Cookie> cookie(String name)
name
- the cookie's name.@Deprecated public Optional<Http.Cookie> getCookie(String name)
cookie(String)
name
- the cookie's name.public Http.Cookies cookies()
public Result withCookies(Http.Cookie... newCookies)
newCookies
- the cookies to add to the result.public Result discardingCookie(String name)
name
- The name of the cookie to discard, must not be nullpublic Result discardingCookie(String name, String path)
name
- The name of the cookie to discard, must not be nullpath
- The path of the cookie to discard, may be nullpublic Result discardingCookie(String name, String path, String domain)
name
- The name of the cookie to discard, must not be nullpath
- The path of the cookie te discard, may be nulldomain
- The domain of the cookie to discard, may be nullpublic Result discardingCookie(String name, String path, String domain, boolean secure)
name
- The name of the cookie to discard, must not be nullpath
- The path of the cookie te discard, may be nulldomain
- The domain of the cookie to discard, may be nullsecure
- Whether the cookie to discard is securepublic Result withHeader(String name, String value)
name
- the header namevalue
- the header valuepublic Result withHeaders(String... nameValues)
The headers are processed in pairs, so nameValues(0) is the first header's name, and nameValues(1) is the first header's value, nameValues(2) is second header's name, and so on.
nameValues
- the array of names and values.public Result withoutHeader(String name)
name
- the header namepublic Result as(String contentType)
contentType
- the content type to setpublic Result withLang(Lang lang, MessagesApi messagesApi)
public Result action() {
ok("Hello").withLang(Lang.forCode("es"), messagesApi);
}
Where messagesApi
were injected.lang
- the new langmessagesApi
- the messages api implementationMessagesApi.setLang(Result, Lang)
public Result withLang(Locale locale, MessagesApi messagesApi)
public Result action() {
ok("Hello").withLang(new Locale("es"), messagesApi);
}
Where messagesApi
were injected.locale
- the new langmessagesApi
- the messages api implementationMessagesApi.setLang(Result, Lang)
public Result withoutLang(MessagesApi messagesApi)
public Result action() {
ok("Hello").withoutLang(messagesApi);
}
Where messagesApi
were injected.messagesApi
- the messages api implementationMessagesApi.clearLang(Result)
public play.api.mvc.Result asScala()