public interface

ResponseFactory

com.atlassian.jira.rest.util.ResponseFactory
Known Indirect Subclasses

Class Overview

A component for building commonly used types of REST responses

Summary

Public Methods
Response badRequest(String i18nKey, String... args)
Constructs a "bad request" (400) HTTP reposne without caching.
Response created(URI self, Object entity)
Constructs CREATED response with cache control set to never
Response errorResponse(ErrorCollection errorCollection)
Creates an appropriate REST error response out of error collection.
Response forbidden(String i18nKey, String... args)
Constructs "forbidden" (403) HTTP response without caching.
Response generateErrorResponse(ErrorCollection errors)
Given a list of errors generate a http response
Response generateFieldErrorResponse(ErrorCollection errors)
Given a list of errors generate a http response
Response noContent()
Constructs "no content" (204) HTTP response with cache control set to never
Response notFound(String i18nKey, String... args)
Constructs "not found" (404) HTTP response without caching.
Response notLoggedInResponse()
Creates a response that tells the user they can't use a feature when they are not logged in
Response okNoCache(Object entity)
Constructs OK response with cache control set to never
Response serviceResultToNoContentResponse(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> Either<Response, T> toResponse(Either<ErrorCollection, T> either)
Maps ErrorCollection in an Either to a Response.
<T> Either<Response, T> validateOutcome(ServiceOutcome<T> outcome)
Returns a proper error response if the outcome is invalid, or the outcome value otherwise.

Public Methods

public Response badRequest (String i18nKey, String... args)

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.

public Response created (URI self, Object entity)

Constructs CREATED response with cache control set to never

Parameters
self URI to the newly created entity
entity object that will be sent in the response
Returns
  • CREATED response holding the entity

public Response errorResponse (ErrorCollection errorCollection)

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

public Response forbidden (String i18nKey, String... args)

Constructs "forbidden" (403) HTTP response without caching.

Parameters
i18nKey key of the i18n message which is included in the response.
Returns
  • forbidden HTTP response.

public Response generateErrorResponse (ErrorCollection errors)

Given a list of errors generate a http response

Parameters
errors generated
Returns
  • http response for the worst error

public Response generateFieldErrorResponse (ErrorCollection errors)

Given a list of errors generate a http response

Parameters
errors generated
Returns
  • http response for the worst error

public Response noContent ()

Constructs "no content" (204) HTTP response with cache control set to never

Returns
  • no content HTTP response

public Response notFound (String i18nKey, String... args)

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.

public 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.

public Response okNoCache (Object entity)

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

public Response serviceResultToNoContentResponse (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.

Parameters
serviceResult service result to validate
Returns
  • either an error response corresponding the the service result error, or 204.

public Either<Response, T> toResponse (Either<ErrorCollection, T> either)

Maps ErrorCollection in an Either to a Response.

Parameters
either either to map the left value in
Returns
  • mapped either

public Either<Response, T> validateOutcome (ServiceOutcome<T> outcome)

Returns a proper error response if the outcome is invalid, or the outcome value otherwise.

Parameters
outcome service outcome
Returns
  • either error response or the service outcome value