Package play.mvc
Class Result
- Object
-
- play.mvc.Result
-
- Direct Known Subclasses:
StatusHeader
public class Result extends Object
Any action result.
-
-
Constructor Summary
Constructors Constructor Description Result(int status)
Create a result with no entity.Result(int status, String reasonPhrase, Map<String,String> headers, 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, 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.Result(ResponseHeader header, HttpEntity body, Http.Session session, Http.Flash flash, List<Http.Cookie> cookies, TypedMap attrs)
Create a result from a Scala ResponseHeader and a body.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <A> Result
addAttr(TypedKey<A> key, A value)
Create a new versions of this object with the given attribute attached to it.Result
addAttrs(List<TypedEntry<?>> entries)
Create a new versions of this object with the given attributes attached to it.Result
addAttrs(TypedEntry<?> e1)
Create a new versions of this object with the given attribute attached to it.Result
addAttrs(TypedEntry<?>... entries)
Create a new versions of this object with the given attributes attached to it.Result
addAttrs(TypedEntry<?> e1, TypedEntry<?> e2)
Create a new versions of this object with the given attributes attached to it.Result
addAttrs(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3)
Create a new versions of this object with the given attributes attached to it.Result
addingToSession(Http.Request request, String key, String value)
Adds the given key and value to the session.Result
addingToSession(Http.Request request, Map<String,String> values)
Adds values 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.TypedMap
attrs()
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 valueHttp.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 resultResult
discardingCookie(String name, String path, String domain, boolean secure, Http.Cookie.SameSite sameSite)
Discard a cookie in this resultHttp.Flash
flash()
Extracts the Flash values of this Result value.Result
flashing(String key, String value)
Adds the given key and value to the flash.Result
flashing(Map<String,String> values)
Adds values to the flash.Optional<Http.Cookie>
getCookie(String name)
Deprecated.Deprecated as of 2.8.0.protected ResponseHeader
getHeader()
Get the response headerOptional<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
removeAttr(TypedKey<?> key)
Create a new versions of this object with the given attribute removed.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
withAttrs(TypedMap newAttrs)
Create a new version of this object with the given attributes attached to it.Result
withCookies(Http.Cookie... newCookies)
Returns a copy of this result with the given cookies.Result
withFlash(Map<String,String> flash)
Sets a new flash for this result, discarding the existing flash.Result
withFlash(Http.Flash 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(Locale locale, MessagesApi messagesApi)
Returns a new result with the given lang set in a cookie.Result
withLang(Lang lang, 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(Map<String,String> session)
Sets a new session for this result, discarding the existing session.Result
withSession(Http.Session session)
Sets a new session for this result, discarding the existing session.
-
-
-
Constructor Detail
-
Result
public Result(ResponseHeader header, HttpEntity body, Http.Session session, Http.Flash flash, List<Http.Cookie> cookies, TypedMap attrs)
Create a result from a Scala ResponseHeader and a body.- Parameters:
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.attrs
- the typed attributes set on the response.
-
Result
public 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.- Parameters:
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.
-
Result
public Result(ResponseHeader header, HttpEntity body)
Create a result from a Scala ResponseHeader and a body.- Parameters:
header
- the response headerbody
- the response body.
-
Result
public Result(int status, String reasonPhrase, Map<String,String> headers, HttpEntity body)
Create a result.- Parameters:
status
- The status.reasonPhrase
- The reason phrase, if a non default reason phrase is required.headers
- The headers.body
- The body.
-
Result
public Result(int status, Map<String,String> headers, HttpEntity body)
Create a result.- Parameters:
status
- The status.headers
- The headers.body
- The body.
-
Result
public Result(int status, Map<String,String> headers)
Create a result with no body.- Parameters:
status
- The status.headers
- The headers.
-
Result
public Result(int status, HttpEntity body)
Create a result.- Parameters:
status
- The status.body
- The entity.
-
Result
public Result(int status)
Create a result with no entity.- Parameters:
status
- The status.
-
-
Method Detail
-
status
public int status()
Get the status.- Returns:
- the status
-
reasonPhrase
public Optional<String> reasonPhrase()
Get the reason phrase, if it was set.- Returns:
- the reason phrase (e.g. "NOT FOUND")
-
getHeader
protected ResponseHeader getHeader()
Get the response header- Returns:
- the header
-
body
public HttpEntity body()
Get the body of this result.- Returns:
- the body
-
redirectLocation
public Optional<String> redirectLocation()
Extracts the Location header of this Result value if this Result is a Redirect.- Returns:
- the location (if it was set)
-
header
public Optional<String> header(String header)
Extracts an Header value of this Result value.- Parameters:
header
- the header name.- Returns:
- the header (if it was set)
-
headers
public Map<String,String> headers()
Extracts all Headers of this Result value.The returned map is not modifiable.
- Returns:
- the immutable map of headers
-
contentType
public Optional<String> contentType()
Extracts the Content-Type of this Result value.- Returns:
- the content type (if it was set)
-
charset
public Optional<String> charset()
Extracts the Charset of this Result value.- Returns:
- the charset (if it was set)
-
flash
public Http.Flash flash()
Extracts the Flash values of this Result value.- Returns:
- the flash (if it was set)
-
withFlash
public Result withFlash(Http.Flash flash)
Sets a new flash for this result, discarding the existing flash.- Parameters:
flash
- the flash to set with this result- Returns:
- the new result
-
withFlash
public Result withFlash(Map<String,String> flash)
Sets a new flash for this result, discarding the existing flash.- Parameters:
flash
- the flash to set with this result- Returns:
- the new result
-
withNewFlash
public Result withNewFlash()
Discards the existing flash for this result.- Returns:
- the new result
-
flashing
public Result flashing(Map<String,String> values)
Adds values to the flash.- Parameters:
values
- A map with values to add to this result's flash- Returns:
- A copy of this result with values added to its flash scope.
-
flashing
public Result flashing(String key, String value)
Adds the given key and value to the flash.- Parameters:
key
- The key to add to this result's flashvalue
- The value to add to this result's flash- Returns:
- A copy of this result with the key and value added to its flash scope.
-
removingFromFlash
public Result removingFromFlash(String... keys)
Removes values from the flash.- Parameters:
keys
- Keys to remove from flash- Returns:
- A copy of this result with keys removed from its flash scope.
-
session
public Http.Session session()
Extracts the Session of this Result value.- Returns:
- the session (if it was set)
-
session
public Http.Session session(Http.Request request)
- Parameters:
request
- Current request- Returns:
- The session carried by this result. Reads the given request's session if this result does not has a session.
-
withSession
public Result withSession(Http.Session session)
Sets a new session for this result, discarding the existing session.- Parameters:
session
- the session to set with this result- Returns:
- the new result
-
withSession
public Result withSession(Map<String,String> session)
Sets a new session for this result, discarding the existing session.- Parameters:
session
- the session to set with this result- Returns:
- the new result
-
withNewSession
public Result withNewSession()
Discards the existing session for this result.- Returns:
- the new result
-
addingToSession
public Result addingToSession(Http.Request request, Map<String,String> values)
Adds values to the session.- Parameters:
values
- A map with values to add to this result's session- Returns:
- A copy of this result with values added to its session scope.
-
addingToSession
public Result addingToSession(Http.Request request, String key, String value)
Adds the given key and value to the session.- Parameters:
key
- The key to add to this result's sessionvalue
- The value to add to this result's session- Returns:
- A copy of this result with the key and value added to its session scope.
-
removingFromSession
public Result removingFromSession(Http.Request request, String... keys)
Removes values from the session.- Parameters:
keys
- Keys to remove from session- Returns:
- A copy of this result with keys removed from its session scope.
-
cookie
public Optional<Http.Cookie> cookie(String name)
Extracts a Cookie value from this Result value- Parameters:
name
- the cookie's name.- Returns:
- the optional cookie
-
getCookie
@Deprecated public Optional<Http.Cookie> getCookie(String name)
Deprecated.Deprecated as of 2.8.0. Renamed tocookie(String)
Extracts a Cookie value from this Result value- Parameters:
name
- the cookie's name.- Returns:
- the optional cookie
-
cookies
public Http.Cookies cookies()
Extracts the Cookies (an iterator) from this result value.- Returns:
- the cookies (if they were set)
-
withCookies
public Result withCookies(Http.Cookie... newCookies)
Returns a copy of this result with the given cookies.- Parameters:
newCookies
- the cookies to add to the result.- Returns:
- the transformed copy.
-
discardingCookie
public Result discardingCookie(String name)
Discard a cookie on the default path ("/") with no domain and that's not secure.- Parameters:
name
- The name of the cookie to discard, must not be null
-
discardingCookie
public Result discardingCookie(String name, String path)
Discard a cookie on the given path with no domain and not that's secure.- Parameters:
name
- The name of the cookie to discard, must not be nullpath
- The path of the cookie to discard, may be null
-
discardingCookie
public Result discardingCookie(String name, String path, String domain)
Discard a cookie on the given path and domain that's not secure.- Parameters:
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 null
-
discardingCookie
public Result discardingCookie(String name, String path, String domain, boolean secure)
Discard a cookie in this result- Parameters:
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 secure
-
discardingCookie
public Result discardingCookie(String name, String path, String domain, boolean secure, Http.Cookie.SameSite sameSite)
Discard a cookie in this result- Parameters:
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 securesameSite
- The SameSite attribute of the cookie to discard, may be null
-
withHeader
public Result withHeader(String name, String value)
Return a copy of this result with the given header.- Parameters:
name
- the header namevalue
- the header value- Returns:
- the transformed copy
-
withHeaders
public Result withHeaders(String... nameValues)
Return a copy of this result with the given headers.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.
- Parameters:
nameValues
- the array of names and values.- Returns:
- the transformed copy
-
withoutHeader
public Result withoutHeader(String name)
Discard a HTTP header in this result.- Parameters:
name
- the header name- Returns:
- the transformed copy
-
as
public Result as(String contentType)
Return a copy of the result with a different Content-Type header.- Parameters:
contentType
- the content type to set- Returns:
- the transformed copy
-
withLang
public Result withLang(Lang lang, MessagesApi messagesApi)
Returns a new result with the given lang set in a cookie. For example:
Wherepublic Result action() { ok("Hello").withLang(Lang.forCode("es"), messagesApi); }
messagesApi
were injected.- Parameters:
lang
- the new langmessagesApi
- the messages api implementation- Returns:
- a new result with the given lang.
- See Also:
MessagesApi.setLang(Result, Lang)
-
withLang
public Result withLang(Locale locale, MessagesApi messagesApi)
Returns a new result with the given lang set in a cookie. For example:
Wherepublic Result action() { ok("Hello").withLang(new Locale("es"), messagesApi); }
messagesApi
were injected.- Parameters:
locale
- the new langmessagesApi
- the messages api implementation- Returns:
- a new result with the given lang.
- See Also:
MessagesApi.setLang(Result, Lang)
-
withoutLang
public Result withoutLang(MessagesApi messagesApi)
Clears the lang cookie from this result. For example:
Wherepublic Result action() { ok("Hello").withoutLang(messagesApi); }
messagesApi
were injected.- Parameters:
messagesApi
- the messages api implementation- Returns:
- a new result without the lang
- See Also:
MessagesApi.clearLang(Result)
-
attrs
public TypedMap attrs()
- Returns:
- a map of typed attributes associated with the result.
-
withAttrs
public Result withAttrs(TypedMap newAttrs)
Create a new version of this object with the given attributes attached to it.- Parameters:
newAttrs
- The new attributes to add.- Returns:
- The new version of this object with the attributes attached.
-
addAttr
public <A> Result addAttr(TypedKey<A> key, A value)
Create a new versions of this object with the given attribute attached to it.- Type Parameters:
A
- the attribute type- Parameters:
key
- The new attribute key.value
- The attribute value.- Returns:
- The new version of this object with the new attribute.
-
addAttrs
public Result addAttrs(TypedEntry<?> e1)
Create a new versions of this object with the given attribute attached to it.- Parameters:
e1
- The new attribute.- Returns:
- The new version of this object with the new attribute.
-
addAttrs
public Result addAttrs(TypedEntry<?> e1, TypedEntry<?> e2)
Create a new versions of this object with the given attributes attached to it.- Parameters:
e1
- The first new attribute.e2
- The second new attribute.- Returns:
- The new version of this object with the new attributes.
-
addAttrs
public Result addAttrs(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3)
Create a new versions of this object with the given attributes attached to it.- Parameters:
e1
- The first new attribute.e2
- The second new attribute.e3
- The third new attribute.- Returns:
- The new version of this object with the new attributes.
-
addAttrs
public Result addAttrs(TypedEntry<?>... entries)
Create a new versions of this object with the given attributes attached to it.- Parameters:
entries
- The new attributes.- Returns:
- The new version of this object with the new attributes.
-
addAttrs
public Result addAttrs(List<TypedEntry<?>> entries)
Create a new versions of this object with the given attributes attached to it.- Parameters:
entries
- The new attributes.- Returns:
- The new version of this object with the new attributes.
-
removeAttr
public Result removeAttr(TypedKey<?> key)
Create a new versions of this object with the given attribute removed.- Parameters:
key
- The key of the attribute to remove.- Returns:
- The new version of this object with the attribute removed.
-
asScala
public play.api.mvc.Result asScala()
Convert this result to a Scala result.- Returns:
- the Scala result.
-
-