Class HttpResponses

java.lang.Object
org.apache.juneau.http.HttpResponses

public final class HttpResponses extends Object
Static factory methods for creating pre-defined HTTP response and exception objects.

Import statically for clean DSL-style usage in REST server code:

import static HttpResponses.*; @RestGet("/users/{id}") public User getUser(@Path String id) { User user = userService.find(id); if (user == null) throw notFound("User not found: " + id); return user; }

See Also:
Since:
9.2.1
  • Method Details

    • continueResponse

      public static Continue continueResponse()
      Returns:
      A new 100 Continue response.
    • switchingProtocols

      Returns:
      A new 101 Switching Protocols response.
    • ok

      public static Ok ok()
      Returns:
      A new 200 OK response.
    • ok

      public static Ok ok(String body)
      Parameters:
      body - The response body. Can be null for no response body. @return A new 200 OK response.
    • created

      public static Created created()
      Returns:
      A new 201 Created response.
    • created

      public static Created created(String body)
      Parameters:
      body - The response body. Can be null for no response body. @return A new 201 Created response.
    • accepted

      public static Accepted accepted()
      Returns:
      A new 202 Accepted response.
    • noContent

      public static NoContent noContent()
      Returns:
      A new 204 No Content response.
    • partialContent

      public static PartialContent partialContent()
      Returns:
      A new 206 Partial Content response.
    • movedPermanently

      public static MovedPermanently movedPermanently(String location)
      Parameters:
      location - The redirect location. Can be null to omit the Location header. @return A new 301 Moved Permanently response.
    • found

      public static Found found(String location)
      Parameters:
      location - The redirect location. Can be null to omit the Location header. @return A new 302 Found response.
    • seeOther

      public static SeeOther seeOther(String location)
      Parameters:
      location - The redirect location. Can be null to omit the Location header. @return A new 303 See Other response.
    • notModified

      public static NotModified notModified()
      Returns:
      A new 304 Not Modified response.
    • temporaryRedirect

      public static TemporaryRedirect temporaryRedirect(String location)
      Parameters:
      location - The redirect location. Can be null to omit the Location header. @return A new 307 Temporary Redirect response.
    • permanentRedirect

      public static PermanentRedirect permanentRedirect(String location)
      Parameters:
      location - The redirect location. Can be null to omit the Location header. @return A new 308 Permanent Redirect response.
    • badRequest

      public static BadRequest badRequest()
      Returns:
      A new 400 Bad Request exception.
    • badRequest

      public static BadRequest badRequest(String message)
      Parameters:
      message - The error message. Can be null for no message body. @return A new 400 Bad Request exception.
    • unauthorized

      public static Unauthorized unauthorized()
      Returns:
      A new 401 Unauthorized exception.
    • unauthorized

      public static Unauthorized unauthorized(String message)
      Parameters:
      message - The error message. Can be null for no message body. @return A new 401 Unauthorized exception.
    • forbidden

      public static Forbidden forbidden()
      Returns:
      A new 403 Forbidden exception.
    • forbidden

      public static Forbidden forbidden(String message)
      Parameters:
      message - The error message. Can be null for no message body. @return A new 403 Forbidden exception.
    • notFound

      public static NotFound notFound()
      Returns:
      A new 404 Not Found exception.
    • notFound

      public static NotFound notFound(String message)
      Parameters:
      message - The error message. Can be null for no message body. @return A new 404 Not Found exception.
    • methodNotAllowed

      Returns:
      A new 405 Method Not Allowed exception.
    • conflict

      public static Conflict conflict()
      Returns:
      A new 409 Conflict exception.
    • conflict

      public static Conflict conflict(String message)
      Parameters:
      message - The error message. Can be null for no message body. @return A new 409 Conflict exception.
    • gone

      public static Gone gone()
      Returns:
      A new 410 Gone exception.
    • preconditionFailed

      Returns:
      A new 412 Precondition Failed exception.
    • unsupportedMediaType

      Returns:
      A new 415 Unsupported Media Type exception.
    • unsupportedMediaType

      Parameters:
      message - The error message. Can be null for no message body. @return A new 415 Unsupported Media Type exception.
    • unprocessableEntity

      Returns:
      A new 422 Unprocessable Entity exception.
    • unprocessableEntity

      Parameters:
      message - The error message. Can be null for no message body. @return A new 422 Unprocessable Entity exception.
    • tooManyRequests

      Returns:
      A new 429 Too Many Requests exception.
    • internalServerError

      Returns:
      A new 500 Internal Server Error exception.
    • internalServerError

      Parameters:
      message - The error message. Can be null for no message body. @return A new 500 Internal Server Error exception.
    • internalServerError

      Parameters:
      cause - The cause. Can be null (no cause is chained). @return A new 500 Internal Server Error exception.
    • notImplemented

      public static NotImplemented notImplemented()
      Returns:
      A new 501 Not Implemented exception.
    • serviceUnavailable

      Returns:
      A new 503 Service Unavailable exception.
    • serviceUnavailable

      public static ServiceUnavailable serviceUnavailable(String message)
      Parameters:
      message - The error message. Can be null for no message body. @return A new 503 Service Unavailable exception.