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/plain
MIME 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 HttpStatus
accepted()
Creates an instance with status code202 Accepted
.static HttpStatus
Creates an instance with status code400 Bad Request
.static HttpStatus
created()
Creates an instance with status code201 Created
.static HttpStatus
Creates an instance with status code403 Forbidden
.Returns the MIME content type of the response body.Returns the extra HTTP headers.Returns the response body.int
Returns the status code.static HttpStatus
movedPermanently
(String location) Creates an instance with status code301 Moved Permanently
.static HttpStatus
movedPermanently
(Link link) Creates an instance with status code301 Moved Permanently
.static HttpStatus
notFound()
Creates an instance with status code404 Not Found
.static HttpStatus
ok()
Creates an instance with status code200 OK
.static HttpStatus
Creates an instance with status code303 See Other
.static HttpStatus
Creates an instance with status code303 See Also
.static HttpStatus
temporaryRedirect
(String location) Creates an instance with status code302 Found
.static HttpStatus
temporaryRedirect
(Link location) Creates an instance with status code302 Found
.static HttpStatus
Creates an instance with status code401 Unauthorized
.withContentLocation
(String location) Sets theContent-Location
HTTP header.withContentLocation
(Link link) Sets theContent-Location
HTTP header.withHttpHeader
(String name, String value) Sets an HTTP header.withLocation
(String location) Sets a redirect by using theLocation
HTTP header.withLocation
(Link location) Sets a redirect by using theLocation
HTTP 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/plain
MIME 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 theLocation
header.
-
seeOther
Creates an instance with status code303 See Also
.- Parameters:
location
- the value of theLocation
header.
-
movedPermanently
Creates an instance with status code301 Moved Permanently
.- Parameters:
location
- the value of theLocation
header.
-
movedPermanently
Creates an instance with status code301 Moved Permanently
.- Parameters:
link
- the value of theLocation
header.
-
temporaryRedirect
Creates an instance with status code302 Found
.- Parameters:
location
- the value of theLocation
header.
-
temporaryRedirect
Creates an instance with status code302 Found
.- Parameters:
location
- the value of theLocation
header.
-
withLocation
Sets a redirect by using theLocation
HTTP header. -
withLocation
Sets a redirect by using theLocation
HTTP header. -
withContentLocation
Sets theContent-Location
HTTP header. -
withContentLocation
Sets theContent-Location
HTTP 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 implementStreamResponse
instead. -
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.
-