Package org.apache.tapestry5.services
Class HttpStatus
java.lang.Object
org.apache.tapestry5.services.HttpStatus
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
ConstructorsConstructorDescriptionHttpStatus(int statusCode) Creates an object with a given status code and no response body.HttpStatus(int statusCode, String responseBody) Creates an object with a given status code, response body andtext/plainMIME content type.HttpStatus(int statusCode, String responseBody, String contentType) Creates an object with a given status code, response body and MIME content type. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpStatusaccepted()Creates an instance with status code202 Accepted.static HttpStatusCreates an instance with status code400 Bad Request.static HttpStatuscreated()Creates an instance with status code201 Created.static HttpStatusCreates an instance with status code403 Forbidden.Returns the MIME content type of the response body.Returns the extra HTTP headers.Returns the response body.intReturns the status code.static HttpStatusmovedPermanently(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 HttpStatusCreates an instance with status code303 See Other.static HttpStatusCreates an instance with status code303 See Also.static HttpStatustemporaryRedirect(String location) Creates an instance with status code302 Found.static HttpStatustemporaryRedirect(Link location) Creates an instance with status code302 Found.static HttpStatusCreates an instance with status code401 Unauthorized.withContentLocation(String location) Sets theContent-LocationHTTP header.withContentLocation(Link link) Sets theContent-LocationHTTP header.withHttpHeader(String name, String value) Sets an HTTP header.withLocation(String location) Sets a redirect by using theLocationHTTP header.withLocation(Link location) Sets a redirect by using theLocationHTTP header.
-
Constructor Details
-
HttpStatus
Creates an object with a given status code and no response body. -
HttpStatus
Creates an object with a given status code, response body andtext/plainMIME content type. -
HttpStatus
Creates an object with a given status code, response body and MIME content type.
-
-
Method Details
-
ok
Creates an instance with status code200 OK. -
created
Creates an instance with status code201 Created. -
accepted
Creates an instance with status code202 Accepted. -
notFound
Creates an instance with status code404 Not Found. -
forbidden
Creates an instance with status code403 Forbidden. -
badRequest
Creates an instance with status code400 Bad Request. -
unauthorized
Creates an instance with status code401 Unauthorized. -
seeOther
Creates an instance with status code303 See Other.- Parameters:
location- the value of theLocationheader.
-
seeOther
Creates an instance with status code303 See Also.- Parameters:
location- the value of theLocationheader.
-
movedPermanently
Creates an instance with status code301 Moved Permanently.- Parameters:
location- the value of theLocationheader.
-
movedPermanently
Creates an instance with status code301 Moved Permanently.- Parameters:
link- the value of theLocationheader.
-
temporaryRedirect
Creates an instance with status code302 Found.- Parameters:
location- the value of theLocationheader.
-
temporaryRedirect
Creates an instance with status code302 Found.- Parameters:
location- the value of theLocationheader.
-
withLocation
Sets a redirect by using theLocationHTTP header. -
withLocation
Sets a redirect by using theLocationHTTP header. -
withContentLocation
Sets theContent-LocationHTTP header. -
withContentLocation
Sets theContent-LocationHTTP header. -
withHttpHeader
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
Returns the status code. -
getResponseBody
Returns the response body. -
getContentType
Returns the MIME content type of the response body. -
getExtraHttpHeaders
Returns the extra HTTP headers.
-