Class Response

java.lang.Object
io.mangoo.routing.Response

public class Response extends Object
Author:
svenkubiak
  • Constructor Details

    • Response

      public Response()
  • Method Details

    • getStatusCode

      public int getStatusCode()
    • getContentType

      public String getContentType()
    • getCharset

      public String getCharset()
    • getBody

      public String getBody()
    • getCookies

      public List<io.undertow.server.handlers.Cookie> getCookies()
    • getBinaryContent

      public byte[] getBinaryContent()
    • getTemplate

      public String getTemplate()
    • getBinaryFileName

      public String getBinaryFileName()
    • getContent

      public Map<String,Object> getContent()
    • isRedirect

      public boolean isRedirect()
    • isBinary

      public boolean isBinary()
    • isRendered

      public boolean isRendered()
    • isEndResponse

      public boolean isEndResponse()
    • isUnrendered

      public boolean isUnrendered()
    • getRedirectTo

      public String getRedirectTo()
    • getHeaders

      public Map<io.undertow.util.HttpString,String> getHeaders()
    • getHeader

      public String getHeader(io.undertow.util.HttpString header)
    • withOk

      public static Response withOk()
      Creates a response object with HTTP status code 200
      Returns:
      A response object Response
    • withCreated

      public static Response withCreated()
      Creates a response object with HTTP status code 201
      Returns:
      A response object Response
    • withNotFound

      public static Response withNotFound()
      Creates a response object with HTTP status code 404
      Returns:
      A response object Response
    • withForbidden

      public static Response withForbidden()
      Creates a response object with HTTP status code 401
      Returns:
      A response object Response
    • withUnauthorized

      public static Response withUnauthorized()
      Creates a response object with HTTP status code 403
      Returns:
      A response object Response
    • withBadRequest

      public static Response withBadRequest()
      Creates a response object with HTTP status code 400
      Returns:
      A response object Response
    • withInternalServerError

      public static Response withInternalServerError()
      Creates a response object with HTTP status code 500
      Returns:
      A response object Response
    • withStatusCode

      public static Response withStatusCode(int statusCode)
      Creates a response object with a given HTTP status code
      Parameters:
      statusCode - The status code to set
      Returns:
      A response object Response
    • withRedirect

      public static Response withRedirect(String redirectTo)
      Creates a response object with a given url to redirect to
      Parameters:
      redirectTo - The URL to redirect to
      Returns:
      A response object Response
    • andTemplate

      public Response andTemplate(String template)
      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

      public Response andContentType(String contentType)
      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

      public Response andCharset(String charset)
      Sets a specific charset to the response
      Parameters:
      charset - The charset to use
      Returns:
      A response object Response
    • andContent

      public Response andContent(String name, Object object)
      Adds a value to the template that can be accessed using ${name} in the template
      Parameters:
      name - The name of the value
      object - The actual value
      Returns:
      A response object Response
    • andBody

      public Response andBody(String body)
      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

      public 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

      public Response andCookie(io.undertow.server.handlers.Cookie cookie)
      Adds a Cookie to the response which is passed to the client
      Parameters:
      cookie - The cookie to add
      Returns:
      A response object Response
    • andJsonBody

      public Response andJsonBody(Object jsonObject)
      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

      public Response andJsonBody(String json)
      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

      public Response andBinaryFile(Path file)
      Sends a binary file to the client skipping rendering
      Parameters:
      file - The file to send
      Returns:
      A response object Response
    • andBinaryContent

      public Response andBinaryContent(byte[] content)
      Sends binary content to the client skipping rendering
      Parameters:
      content - The content to send
      Returns:
      A response object Response
    • andTextBody

      public Response andTextBody(String body)
      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

      public Response andEmptyBody()
      Disables template rendering, sending an empty body in the response
      Returns:
      A response object Response
    • andHeader

      public Response andHeader(io.undertow.util.HttpString key, String value)
      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

      public Response andHeader(String key, String value)
      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 key
      value - The header value
      Returns:
      A response object Response
    • andContent

      public Response andContent(Map<String,Object> content)
      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

      public Response andHeaders(Map<io.undertow.util.HttpString,String> headers)
      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

      public 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