Package com.atlassian.jira.rest.util
Interface ResponseFactory
- All Known Implementing Classes:
ResponseFactoryImpl
public interface ResponseFactory
A component for building commonly used types of REST responses
- Since:
- v6.1
-
Method Summary
Modifier and TypeMethodDescriptionjakarta.ws.rs.core.ResponsebadRequest(String i18nKey, String... args) Constructs a "bad request" (400) HTTP reposne without caching.jakarta.ws.rs.core.ResponseConstructs CREATED response with cache control set to neverjakarta.ws.rs.core.ResponseerrorResponse(ErrorCollection errorCollection) Creates an appropriate REST error response out of error collection.jakarta.ws.rs.core.ResponseConstructs "forbidden" (403) HTTP response without caching.jakarta.ws.rs.core.ResponsegenerateErrorResponse(ErrorCollection errors) Given a list of errors generate a http responsejakarta.ws.rs.core.ResponseGiven a list of errors generate a http responsejakarta.ws.rs.core.ResponseConstructs "no content" (204) HTTP response with cache control set to neverjakarta.ws.rs.core.ResponseConstructs "not found" (404) HTTP response without caching.jakarta.ws.rs.core.ResponseCreates a response that tells the user they can't use a feature when they are not logged injakarta.ws.rs.core.ResponseConstructs OK response with cache control set to neverjakarta.ws.rs.core.ResponseserviceResultToNoContentResponse(ServiceResult serviceResult) Transforms a service result to "no content" (204) HTTP response with cache control set to never if the result is valid, or error response is invalid.<T> io.atlassian.fugue.Either<jakarta.ws.rs.core.Response, T> toResponse(io.atlassian.fugue.Either<ErrorCollection, T> either) MapsErrorCollectionin anEitherto aResponse.<T> io.atlassian.fugue.Either<jakarta.ws.rs.core.Response, T> validateOutcome(ServiceOutcome<T> outcome) Returns a proper error response if the outcome is invalid, or the outcome value otherwise.
-
Method Details
-
notLoggedInResponse
jakarta.ws.rs.core.Response notLoggedInResponse()Creates a response that tells the user they can't use a feature when they are not logged in- Returns:
- 401 HTTP response with appropriate message.
-
errorResponse
Creates an appropriate REST error response out of error collection.- Parameters:
errorCollection- errors that will be sent back to the user and from which the HTTP response status will be figured out- Returns:
- REST response with JSON-ized error collection and appropriate status
-
okNoCache
Constructs OK response with cache control set to never- Parameters:
entity- object that will be sent in the response- Returns:
- OK response holding the
entity
-
created
Constructs CREATED response with cache control set to never- Parameters:
self- URI to the newly created entityentity- object that will be sent in the response- Returns:
- CREATED response holding the
entity
-
noContent
jakarta.ws.rs.core.Response noContent()Constructs "no content" (204) HTTP response with cache control set to never- Returns:
- no content HTTP response
-
badRequest
Constructs a "bad request" (400) HTTP reposne without caching.- Parameters:
i18nKey- key of the i18n message which is included in the response.args- arguments to be added to the internationalised message.- Returns:
- bad request HTTP response with translated message.
-
notFound
Constructs "not found" (404) HTTP response without caching.- Parameters:
i18nKey- key of the i18n message which is included in the response.- Returns:
- not found HTTP response.
-
forbidden
Constructs "forbidden" (403) HTTP response without caching.- Parameters:
i18nKey- key of the i18n message which is included in the response.- Returns:
- forbidden HTTP response.
-
generateFieldErrorResponse
Given a list of errors generate a http response- Parameters:
errors- generated- Returns:
- http response for the worst error
-
generateErrorResponse
Given a list of errors generate a http response- Parameters:
errors- generated- Returns:
- http response for the worst error
-
validateOutcome
<T> io.atlassian.fugue.Either<jakarta.ws.rs.core.Response,T> validateOutcome(ServiceOutcome<T> outcome) Returns a proper error response if the outcome is invalid, or the outcome value otherwise.- Type Parameters:
T- service outcome value type- Parameters:
outcome- service outcome- Returns:
- either error response or the service outcome value
-
serviceResultToNoContentResponse
Transforms a service result to "no content" (204) HTTP response with cache control set to never if the result is valid, or error response is invalid.- Parameters:
serviceResult- service result to validate- Returns:
- either an error response corresponding the the service result error, or 204.
-
toResponse
<T> io.atlassian.fugue.Either<jakarta.ws.rs.core.Response,T> toResponse(io.atlassian.fugue.Either<ErrorCollection, T> either) MapsErrorCollectionin anEitherto aResponse.- Type Parameters:
T- type of right value- Parameters:
either- either to map the left value in- Returns:
- mapped either
-