Class ResponseFactoryImpl

java.lang.Object
com.atlassian.jira.rest.util.ResponseFactoryImpl
All Implemented Interfaces:
ResponseFactory

@Component public class ResponseFactoryImpl extends Object implements ResponseFactory
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ResponseFactoryImpl

      @Autowired public ResponseFactoryImpl(I18nHelper i18nBean)
  • Method Details

    • notLoggedInResponse

      public javax.ws.rs.core.Response notLoggedInResponse()
      Description copied from interface: ResponseFactory
      Creates a response that tells the user they can't use a feature when they are not logged in
      Specified by:
      notLoggedInResponse in interface ResponseFactory
      Returns:
      401 HTTP response with appropriate message.
    • errorResponse

      public javax.ws.rs.core.Response errorResponse(ErrorCollection errorCollection)
      Description copied from interface: ResponseFactory
      Creates an appropriate REST error response out of error collection.
      Specified by:
      errorResponse in interface ResponseFactory
      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

      public javax.ws.rs.core.Response okNoCache(Object entity)
      Description copied from interface: ResponseFactory
      Constructs OK response with cache control set to never
      Specified by:
      okNoCache in interface ResponseFactory
      Parameters:
      entity - object that will be sent in the response
      Returns:
      OK response holding the entity
    • created

      public javax.ws.rs.core.Response created(URI self, Object entity)
      Description copied from interface: ResponseFactory
      Constructs CREATED response with cache control set to never
      Specified by:
      created in interface ResponseFactory
      Parameters:
      self - URI to the newly created entity
      entity - object that will be sent in the response
      Returns:
      CREATED response holding the entity
    • noContent

      public javax.ws.rs.core.Response noContent()
      Description copied from interface: ResponseFactory
      Constructs "no content" (204) HTTP response with cache control set to never
      Specified by:
      noContent in interface ResponseFactory
      Returns:
      no content HTTP response
    • badRequest

      public javax.ws.rs.core.Response badRequest(String i18nKey, String... args)
      Description copied from interface: ResponseFactory
      Constructs a "bad request" (400) HTTP reposne without caching.
      Specified by:
      badRequest in interface ResponseFactory
      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.
    • forbidden

      public javax.ws.rs.core.Response forbidden(String i18nKey, String... args)
      Description copied from interface: ResponseFactory
      Constructs "forbidden" (403) HTTP response without caching.
      Specified by:
      forbidden in interface ResponseFactory
      Parameters:
      i18nKey - key of the i18n message which is included in the response.
      Returns:
      forbidden HTTP response.
    • notFound

      public javax.ws.rs.core.Response notFound(String i18nKey, String... args)
      Description copied from interface: ResponseFactory
      Constructs "not found" (404) HTTP response without caching.
      Specified by:
      notFound in interface ResponseFactory
      Parameters:
      i18nKey - key of the i18n message which is included in the response.
      Returns:
      not found HTTP response.
    • generateFieldErrorResponse

      public javax.ws.rs.core.Response generateFieldErrorResponse(ErrorCollection errors)
      Given a list of errors generate a http response
      Specified by:
      generateFieldErrorResponse in interface ResponseFactory
      Parameters:
      errors - generated
      Returns:
      http response for the worst error
    • generateErrorResponse

      public javax.ws.rs.core.Response generateErrorResponse(ErrorCollection errors)
      Description copied from interface: ResponseFactory
      Given a list of errors generate a http response
      Specified by:
      generateErrorResponse in interface ResponseFactory
      Parameters:
      errors - generated
      Returns:
      http response for the worst error
    • validateOutcome

      public <T> io.atlassian.fugue.Either<javax.ws.rs.core.Response,T> validateOutcome(ServiceOutcome<T> outcome)
      Description copied from interface: ResponseFactory
      Returns a proper error response if the outcome is invalid, or the outcome value otherwise.
      Specified by:
      validateOutcome in interface ResponseFactory
      Type Parameters:
      T - service outcome value type
      Parameters:
      outcome - service outcome
      Returns:
      either error response or the service outcome value
    • serviceResultToNoContentResponse

      public javax.ws.rs.core.Response serviceResultToNoContentResponse(ServiceResult serviceResult)
      Description copied from interface: ResponseFactory
      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.
      Specified by:
      serviceResultToNoContentResponse in interface ResponseFactory
      Parameters:
      serviceResult - service result to validate
      Returns:
      either an error response corresponding the the service result error, or 204.
    • toResponse

      public <T> io.atlassian.fugue.Either<javax.ws.rs.core.Response,T> toResponse(io.atlassian.fugue.Either<ErrorCollection,T> either)
      Description copied from interface: ResponseFactory
      Maps ErrorCollection in an Either to a Response.
      Specified by:
      toResponse in interface ResponseFactory
      Type Parameters:
      T - type of right value
      Parameters:
      either - either to map the left value in
      Returns:
      mapped either