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
StreamResponseis 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 andtext/plainMIME 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 HttpStatusaccepted()Creates an instance with status code202 Accepted.static HttpStatusbadRequest()Creates an instance with status code400 Bad Request.static HttpStatuscreated()Creates an instance with status code201 Created.static HttpStatusforbidden()Creates an instance with status code403 Forbidden.java.lang.StringgetContentType()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.StringgetResponseBody()Returns the response body.intgetStatusCode()Returns the status code.static HttpStatusmovedPermanently(java.lang.String location)Creates an instance with status code301 Moved Permanently.static HttpStatusmovedPermanently(Link link)Creates an instance with status code301 Moved Permanently.static HttpStatusnotFound()Creates an instance with status code404 Not Found.static HttpStatusok()Creates an instance with status code200 OK.static HttpStatusseeOther(java.lang.String location)Creates an instance with status code303 See Other.static HttpStatusseeOther(Link location)Creates an instance with status code303 See Also.static HttpStatustemporaryRedirect(java.lang.String location)Creates an instance with status code302 Found.static HttpStatustemporaryRedirect(Link location)Creates an instance with status code302 Found.static HttpStatusunauthorized()Creates an instance with status code401 Unauthorized.HttpStatuswithContentLocation(java.lang.String location)Sets theContent-LocationHTTP header.HttpStatuswithContentLocation(Link link)Sets theContent-LocationHTTP header.HttpStatuswithHttpHeader(java.lang.String name, java.lang.String value)Sets an HTTP header.HttpStatuswithLocation(java.lang.String location)Sets a redirect by using theLocationHTTP header.HttpStatuswithLocation(Link location)Sets a redirect by using theLocationHTTP header.
-
-
-
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 andtext/plainMIME 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 code200 OK.
-
created
public static HttpStatus created()
Creates an instance with status code201 Created.
-
accepted
public static HttpStatus accepted()
Creates an instance with status code202 Accepted.
-
notFound
public static HttpStatus notFound()
Creates an instance with status code404 Not Found.
-
forbidden
public static HttpStatus forbidden()
Creates an instance with status code403 Forbidden.
-
badRequest
public static HttpStatus badRequest()
Creates an instance with status code400 Bad Request.
-
unauthorized
public static HttpStatus unauthorized()
Creates an instance with status code401 Unauthorized.
-
seeOther
public static HttpStatus seeOther(java.lang.String location)
Creates an instance with status code303 See Other.- Parameters:
location- the value of theLocationheader.
-
seeOther
public static HttpStatus seeOther(Link location)
Creates an instance with status code303 See Also.- Parameters:
location- the value of theLocationheader.
-
movedPermanently
public static HttpStatus movedPermanently(java.lang.String location)
Creates an instance with status code301 Moved Permanently.- Parameters:
location- the value of theLocationheader.
-
movedPermanently
public static HttpStatus movedPermanently(Link link)
Creates an instance with status code301 Moved Permanently.- Parameters:
link- the value of theLocationheader.
-
temporaryRedirect
public static HttpStatus temporaryRedirect(java.lang.String location)
Creates an instance with status code302 Found.- Parameters:
location- the value of theLocationheader.
-
temporaryRedirect
public static HttpStatus temporaryRedirect(Link location)
Creates an instance with status code302 Found.- Parameters:
location- the value of theLocationheader.
-
withLocation
public HttpStatus withLocation(Link location)
Sets a redirect by using theLocationHTTP header.
-
withLocation
public HttpStatus withLocation(java.lang.String location)
Sets a redirect by using theLocationHTTP header.
-
withContentLocation
public HttpStatus withContentLocation(java.lang.String location)
Sets theContent-LocationHTTP header.
-
withContentLocation
public HttpStatus withContentLocation(Link link)
Sets theContent-LocationHTTP 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 implementStreamResponseinstead.
-
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.
-
-