public class Result extends Object
Constructor and Description |
---|
Result(int statusCode)
A result.
|
Modifier and Type | Method and Description |
---|---|
Result |
addCookie(Cookie cookie) |
Result |
addHeader(String headerName,
String headerContent) |
Result |
charset(String charset) |
Result |
contentType(String contentType)
Sets the content type.
|
Result |
doNotCacheContent()
This function sets
Cache-Control: no-cache, no-store
Date: (current date)
Expires: 1970
=> it therefore effectively forces the browser and every proxy in between
not to cache content.
|
Optional<String> |
fallbackContentType() |
Result |
fallbackContentType(String fallbackContentType) |
String |
getCharset() |
String |
getContentType() |
Cookie |
getCookie(String cookieName)
Returns cookie with that name or null.
|
List<Cookie> |
getCookies() |
Map<String,String> |
getHeaders() |
Class<?> |
getJsonView() |
Object |
getRenderable() |
int |
getStatusCode() |
String |
getTemplate() |
Result |
html()
Set the content type of this result to
TEXT_HTML . |
Result |
json()
Set the content type of this result to
APPLICATION_JSON . |
Result |
jsonp()
Set the content type of this result to
APPLICATION_JSONP . |
Result |
jsonView(Class<?> jsonView)
Set the Jackson JSON View.
|
Result |
redirect(String url)
A redirect that uses 303 see other.
|
Result |
redirectTemporary(String url)
A redirect that uses 307 see other.
|
Result |
render(Map.Entry<String,Object> entry)
Handles following cases:
1) If this.renderable is null: a new HashMap is generated and this entry being added
to the map.
|
Result |
render(Map<String,Object> mapToRender)
Replaces the object being passed by this result to the rendering engine
with this map.
|
Result |
render(Object object)
This method handles two principal cases:
1) If the this.renderable of this result is null, the object passed is simply set as renderable
for this Result
2) If the this.renderable of this result is not null an new map is generated as
object to render and both the former renderable and the new object added to the map.
|
Result |
render(Renderable renderable)
Sets this renderable as object to render.
|
Result |
render(String key,
Object value)
Implicitly generates a hashmap as object being rendered and adds
this key, value pair.
|
Result |
renderRaw(byte[] bytes)
This method directly renders the byte array to the output.
|
Result |
renderRaw(String string)
Deprecated.
=> use text().render(string), html().render(string),
json().render(string), xml().render(string), or
contentType(type).render(string).
|
Result |
setContentType(String contentType)
Deprecated.
|
Result |
status(int statusCode)
Set the status of this result.
|
Result |
supportedContentType(String contentTypeSupportedByThisResult)
Will add a content type to the list of supported content types.
|
List<String> |
supportedContentTypes()
Returns immutable list of supported content types by this request.
|
Result |
supportedContentTypes(String... contentTypesSupportedByThisResult)
Will add the content types to the list of supported content types.
|
Result |
template(String template)
Set the template to render.
|
Result |
text()
Set the content type of this result to
TEXT_PLAIN . |
Result |
unsetCookie(String name) |
Result |
xml()
Set the content type of this result to
Result#APPLICATON_XML . |
public static final int SC_101_SWITCHING_PROTOCOLS
public static final int SC_200_OK
public static final int SC_201_CREATED
public static final int SC_204_NO_CONTENT
public static final int SC_300_MULTIPLE_CHOICES
public static final int SC_301_MOVED_PERMANENTLY
public static final int SC_302_FOUND
public static final int SC_303_SEE_OTHER
public static final int SC_304_NOT_MODIFIED
public static final int SC_307_TEMPORARY_REDIRECT
public static final int SC_400_BAD_REQUEST
public static final int SC_401_UNAUTHORIZED
public static final int SC_403_FORBIDDEN
public static final int SC_404_NOT_FOUND
public static final int SC_500_INTERNAL_SERVER_ERROR
public static final int SC_501_NOT_IMPLEMENTED
public static final String TEXT_HTML
public static final String TEXT_PLAIN
public static final String APPLICATION_JSON
@Deprecated public static final String APPLICATON_JSON
public static final String APPLICATION_JSONP
@Deprecated public static final String APPLICATON_JSONP
public static final String APPLICATION_XML
public static final String APPLICATION_OCTET_STREAM
public static final NoHttpBody NO_HTTP_BODY
public static final String LOCATION
public static final String CACHE_CONTROL
public static final String CACHE_CONTROL_DEFAULT_NOCACHE_VALUE
public static final String DATE
public static final String EXPIRES
public static final String WWW_AUTHENTICATE
public Result(int statusCode)
SC_200_OK
, SC_204_NO_CONTENT
and so on
for some short cuts to predefined results.statusCode
- The status code to set for the result.
Shortcuts to the code at: SC_200_OK
public Object getRenderable()
public Result render(Object object)
IllegalArgumentException
is being thrown.object
- The object to add (either an arbitrary class or Renderable).public Result render(Map<String,Object> mapToRender)
mapToRender
- The map being passed to the templating engine.public Result render(Map.Entry<String,Object> entry)
IllegalArgumentException
is thrown.
If the entry key already exists in the map of this.renderable an IllegalArgumentException
is thrown.entry
- The entry to add.public Result render(Renderable renderable)
renderable
- The renderable that will handle everything after returing the result.public Result render(String key, Object value)
key
- The key to use.value
- The value to use.@Deprecated public Result renderRaw(String string)
public Result controllerMethod() {
String customJson = "{\"user\" : \"john@woo.com\"}";
return Results.json().renderRaw(customJson);
}
string
- The string to render.public Result renderRaw(byte[] bytes)
bytes
- The bytes to render.public String getContentType()
public String getCharset()
public Result charset(String charset)
charset
- Set the charset of the result. Is "utf-8" by default.@Deprecated public Result setContentType(String contentType)
contentType
- public Result contentType(String contentType)
charset(String)
;contentType
- (without encoding) something like "text/html" or
"application/json"public Result supportedContentType(String contentTypeSupportedByThisResult)
contentTypeSupportedByThisResult
- The content type to add. Eg. "application/xml"public Result supportedContentTypes(String... contentTypesSupportedByThisResult)
contentTypesSupportedByThisResult
- The content type to add. Eg.
"application/xml", "applcation/json"public List<String> supportedContentTypes()
public Optional<String> fallbackContentType()
public Result fallbackContentType(String fallbackContentType)
fallbackContentType
- The content type to use as fallback when
neither contentType set and supportedContentTypes
do not match request.public Cookie getCookie(String cookieName)
cookieName
- Name of the cookiepublic int getStatusCode()
public Result status(int statusCode)
SC_200_OK
, SC_204_NO_CONTENT
and so on
for some short cuts to predefined results.statusCode
- The status code. Result (SC_200_OK
) provides some helpers.public String getTemplate()
public Result template(String template)
template
- The view to render. Eg. views/AnotherController/anotherview.ftl.htmlpublic Class<?> getJsonView()
public Result jsonView(Class<?> jsonView)
jsonView
- JSON serialization view class to use when renderingpublic Result redirect(String url)
url
- The url used as redirect target.public Result redirectTemporary(String url)
url
- The url used as redirect target.public Result html()
TEXT_HTML
.TEXT_HTML
.public Result json()
APPLICATION_JSON
.APPLICATION_JSON
.public Result jsonp()
APPLICATION_JSONP
.APPLICATION_JSONP
.public Result text()
TEXT_PLAIN
.TEXT_PLAIN
.public Result xml()
Result#APPLICATON_XML
.Result#APPLICATON_XML
.public Result doNotCacheContent()
Copyright © 2019 ninjaframework. All rights reserved.