Package io.mangoo.routing
Class Response
java.lang.Object
io.mangoo.routing.Response
- Author:
- svenkubiak
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionandBinaryContent(byte[] content) Sends binary content to the client skipping renderingandBinaryFile(Path file) Sends a binary file to the client skipping renderingSets the body of the response.andCharset(String charset) Sets a specific charset to the responseandContent(String name, Object object) Adds a value to the template that can be accessed using ${name} in the templateandContent(Map<String, Object> content) Adds a content map to the content rendered in the template.andContentType(String contentType) Sets a specific content type to use for the response.andCookie(io.undertow.server.handlers.Cookie cookie) Adds a Cookie to the response which is passed to the clientDisables template rendering, sending an empty body in the responseTells a filter that the response ends and that the request handler should not execute further filters by sending the current response to the client.Adds a header to the request response.Adds a header to the request response.andHeaders(Map<io.undertow.util.HttpString, String> headers) Adds a header map to the response.andJsonBody(Object jsonObject) Converts a given Object to JSON and passing it to the response.andJsonBody(String json) Sets a given JSON string as body.andTemplate(String template) Sets a specific template to use for the responseandTextBody(String body) Sets the body of the response.Sets the content of a given file placed in the template folder in /templates/CONTROLLER_NAME/METHOD_NAME.body as body without rendering the file in the template enginebyte[]getBody()List<io.undertow.server.handlers.Cookie>getHeader(io.undertow.util.HttpString header) intbooleanisBinary()booleanbooleanbooleanbooleanstatic ResponseCreates a response object with HTTP status code 400static ResponseCreates a response object with HTTP status code 201static ResponseCreates a response object with HTTP status code 401static ResponseCreates a response object with HTTP status code 500static ResponseCreates a response object with HTTP status code 404static ResponsewithOk()Creates a response object with HTTP status code 200static ResponsewithRedirect(String redirectTo) Creates a response object with a given url to redirect tostatic ResponsewithStatusCode(int statusCode) Creates a response object with a given HTTP status codestatic ResponseCreates a response object with HTTP status code 403
-
Constructor Details
-
Response
public Response()
-
-
Method Details
-
getStatusCode
public int getStatusCode() -
getContentType
-
getCharset
-
getBody
-
getCookies
-
getBinaryContent
public byte[] getBinaryContent() -
getTemplate
-
getBinaryFileName
-
getContent
-
isRedirect
public boolean isRedirect() -
isBinary
public boolean isBinary() -
isRendered
public boolean isRendered() -
isEndResponse
public boolean isEndResponse() -
isUnrendered
public boolean isUnrendered() -
getRedirectTo
-
getHeaders
-
getHeader
-
withOk
Creates a response object with HTTP status code 200- Returns:
- A response object
Response
-
withCreated
Creates a response object with HTTP status code 201- Returns:
- A response object
Response
-
withNotFound
Creates a response object with HTTP status code 404- Returns:
- A response object
Response
-
withForbidden
Creates a response object with HTTP status code 401- Returns:
- A response object
Response
-
withUnauthorized
Creates a response object with HTTP status code 403- Returns:
- A response object
Response
-
withBadRequest
Creates a response object with HTTP status code 400- Returns:
- A response object
Response
-
withInternalServerError
Creates a response object with HTTP status code 500- Returns:
- A response object
Response
-
withStatusCode
Creates a response object with a given HTTP status code- Parameters:
statusCode- The status code to set- Returns:
- A response object
Response
-
withRedirect
Creates a response object with a given url to redirect to- Parameters:
redirectTo- The URL to redirect to- Returns:
- A response object
Response
-
andTemplate
Sets a specific template to use for the response- Parameters:
template- The path to the template (e.g. /mytemplate/template.ftl)- Returns:
- A response object
Response
-
andContentType
Sets a specific content type to use for the response. Default is "text/html"- Parameters:
contentType- The content type to use- Returns:
- A response object
Response
-
andCharset
Sets a specific charset to the response- Parameters:
charset- The charset to use- Returns:
- A response object
Response
-
andContent
Adds a value to the template that can be accessed using ${name} in the template- Parameters:
name- The name of the valueobject- The actual value- Returns:
- A response object
Response
-
andBody
Sets the body of the response. If a body is added, no template rendering will be performed. The default content type "text/html" will be used.- Parameters:
body- The body for the response- Returns:
- A response object
Response
-
andUnrenderedBody
Sets the content of a given file placed in the template folder in /templates/CONTROLLER_NAME/METHOD_NAME.body as body without rendering the file in the template engine- Returns:
- A response object
Response
-
andCookie
Adds a Cookie to the response which is passed to the client- Parameters:
cookie- The cookie to add- Returns:
- A response object
Response
-
andJsonBody
Converts a given Object to JSON and passing it to the response. If an object is given, no template rendering will be performed and the content type for the response will be set to "application/json"- Parameters:
jsonObject- The object to convert to JSON- Returns:
- A response object
Response
-
andJsonBody
Sets a given JSON string as body. If a String is given, no template rendering will be performed and the content type for the response will be set to "application/json"- Parameters:
json- The String to set as JSON- Returns:
- A response object
Response
-
andBinaryFile
Sends a binary file to the client skipping rendering- Parameters:
file- The file to send- Returns:
- A response object
Response
-
andBinaryContent
Sends binary content to the client skipping rendering- Parameters:
content- The content to send- Returns:
- A response object
Response
-
andTextBody
Sets the body of the response. If a body is added, no template rendering will be performed. The content type "text/plain" will be used.- Parameters:
body- The text for the response- Returns:
- A response object
Response
-
andEmptyBody
Disables template rendering, sending an empty body in the response- Returns:
- A response object
Response
-
andHeader
Adds a header to the request response. If a header key already exists, it will be overwritten with the latest value.- Parameters:
key- The header constant from Headers class (e.g. Header.CONTENT_TYPE.toString())value- The header value- Returns:
- A response object
Response
-
andHeader
Adds a header to the request response. If a header key already exists, it will be overwritten with the latest value.- Parameters:
key- The header keyvalue- The header value- Returns:
- A response object
Response
-
andContent
Adds a content map to the content rendered in the template. Already existing values with the same key are overwritten.- Parameters:
content- The content map to add- Returns:
- A response object
Response
-
andHeaders
Adds a header map to the response. Already existing values with the same key are overwritten.- Parameters:
headers- The headers map to add- Returns:
- A response object
Response
-
andEndResponse
Tells a filter that the response ends and that the request handler should not execute further filters by sending the current response to the client. This is only used within a filter.- Returns:
- A response object
Response
-