Package org.apache.tapestry5.services

## Class HttpStatus

- java.lang.Object
- - org.apache.tapestry5.services.HttpStatus

-     public final class HttpStatus
      extends java.lang.Object

  An event handler method may return an instance of this class to send an specific HTTP status code to the client. It also supports providing a string to be used as the response body and extra HTTP headers to be set. This class also provides some utility static methods for creating instances for specific HTTP statuses and a fluent API for setting additional information on them.

  For returning binary content and/or adding a response header more than once and/or adding a response header without overwriting existing ones, implementing a `StreamResponse` is the most probable better choice.

  Since:
    5.8.0

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `HttpStatus​(int statusCode)` | Creates an object with a given status code and no response body.
    `HttpStatus​(int statusCode, java.lang.String responseBody)` | Creates an object with a given status code, response body and `text/plain` MIME content type.
    `HttpStatus​(int statusCode, java.lang.String responseBody, java.lang.String contentType)` | Creates an object with a given status code, response body and MIME content type.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static HttpStatus` | `accepted()` | Creates an instance with status code `202 Accepted`.
    `static HttpStatus` | `badRequest()` | Creates an instance with status code `400 Bad Request`.
    `static HttpStatus` | `created()` | Creates an instance with status code `201 Created`.
    `static HttpStatus` | `forbidden()` | Creates an instance with status code `403 Forbidden`.
    `java.lang.String` | `getContentType()` | Returns the MIME content type of the response body.
    `java.util.Map<java.lang.String,​java.lang.String>` | `getExtraHttpHeaders()` | Returns the extra HTTP headers.
    `java.lang.String` | `getResponseBody()` | Returns the response body.
    `int` | `getStatusCode()` | Returns the status code.
    `static HttpStatus` | `movedPermanently​(java.lang.String location)` | Creates an instance with status code `301 Moved Permanently`.
    `static HttpStatus` | `movedPermanently​(Link link)` | Creates an instance with status code `301 Moved Permanently`.
    `static HttpStatus` | `notFound()` | Creates an instance with status code `404 Not Found`.
    `static HttpStatus` | `ok()` | Creates an instance with status code `200 OK`.
    `static HttpStatus` | `seeOther​(java.lang.String location)` | Creates an instance with status code `303 See Other`.
    `static HttpStatus` | `seeOther​(Link location)` | Creates an instance with status code `303 See Also`.
    `static HttpStatus` | `temporaryRedirect​(java.lang.String location)` | Creates an instance with status code `302 Found`.
    `static HttpStatus` | `temporaryRedirect​(Link location)` | Creates an instance with status code `302 Found`.
    `static HttpStatus` | `unauthorized()` | Creates an instance with status code `401 Unauthorized`.
    `HttpStatus` | `withContentLocation​(java.lang.String location)` | Sets the `Content-Location` HTTP header.
    `HttpStatus` | `withContentLocation​(Link link)` | Sets the `Content-Location` HTTP header.
    `HttpStatus` | `withHttpHeader​(java.lang.String name, java.lang.String value)` | Sets an HTTP header.
    `HttpStatus` | `withLocation​(java.lang.String location)` | Sets a redirect by using the `Location` HTTP header.
    `HttpStatus` | `withLocation​(Link location)` | Sets a redirect by using the `Location` HTTP header.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### HttpStatus

          public HttpStatus​(int statusCode)

      Creates an object with a given status code and no response body.

    - #### HttpStatus

          public HttpStatus​(int statusCode,
                            java.lang.String responseBody)

      Creates an object with a given status code, response body and `text/plain` MIME content type.

    - #### HttpStatus

          public HttpStatus​(int statusCode,
                            java.lang.String responseBody,
                            java.lang.String contentType)

      Creates an object with a given status code, response body and MIME content type.

  - ### Method Detail

    - #### ok

          public static HttpStatus ok()

      Creates an instance with status code `200 OK`.

    - #### created

          public static HttpStatus created()

      Creates an instance with status code `201 Created`.

    - #### accepted

          public static HttpStatus accepted()

      Creates an instance with status code `202 Accepted`.

    - #### notFound

          public static HttpStatus notFound()

      Creates an instance with status code `404 Not Found`.

    - #### forbidden

          public static HttpStatus forbidden()

      Creates an instance with status code `403 Forbidden`.

    - #### badRequest

          public static HttpStatus badRequest()

      Creates an instance with status code `400 Bad Request`.

    - #### unauthorized

          public static HttpStatus unauthorized()

      Creates an instance with status code `401 Unauthorized`.

    - #### seeOther

          public static HttpStatus seeOther​(java.lang.String location)

      Creates an instance with status code `303 See Other`.
      Parameters:
        `location` - the value of the `Location` header.

    - #### seeOther

          public static HttpStatus seeOther​(Link location)

      Creates an instance with status code `303 See Also`.
      Parameters:
        `location` - the value of the `Location` header.

    - #### movedPermanently

          public static HttpStatus movedPermanently​(java.lang.String location)

      Creates an instance with status code `301 Moved Permanently`.
      Parameters:
        `location` - the value of the `Location` header.

    - #### movedPermanently

          public static HttpStatus movedPermanently​(Link link)

      Creates an instance with status code `301 Moved Permanently`.
      Parameters:
        `link` - the value of the `Location` header.

    - #### temporaryRedirect

          public static HttpStatus temporaryRedirect​(java.lang.String location)

      Creates an instance with status code `302 Found`.
      Parameters:
        `location` - the value of the `Location` header.

    - #### temporaryRedirect

          public static HttpStatus temporaryRedirect​(Link location)

      Creates an instance with status code `302 Found`.
      Parameters:
        `location` - the value of the `Location` header.

    - #### withLocation

          public HttpStatus withLocation​(Link location)

      Sets a redirect by using the `Location` HTTP header.

    - #### withLocation

          public HttpStatus withLocation​(java.lang.String location)

      Sets a redirect by using the `Location` HTTP header.

    - #### withContentLocation

          public HttpStatus withContentLocation​(java.lang.String location)

      Sets the `Content-Location` HTTP header.

    - #### withContentLocation

          public HttpStatus withContentLocation​(Link link)

      Sets the `Content-Location` HTTP header.

    - #### withHttpHeader

          public HttpStatus withHttpHeader​(java.lang.String name,
                                           java.lang.String value)

      Sets an HTTP header. If an existing value for this header already exists, it gets overwritten. If you need to set multiple headers or add them without overwriting existing ones, you need to implement `StreamResponse` instead.

    - #### getStatusCode

          public int getStatusCode()

      Returns the status code.

    - #### getResponseBody

          public java.lang.String getResponseBody()

      Returns the response body.

    - #### getContentType

          public java.lang.String getContentType()

      Returns the MIME content type of the response body.

    - #### getExtraHttpHeaders

          public java.util.Map<java.lang.String,​java.lang.String> getExtraHttpHeaders()

      Returns the extra HTTP headers.