Class RestApiResponseBuilder

java.lang.Object
org.bonitasoft.web.extension.rest.RestApiResponseBuilder

public class RestApiResponseBuilder extends Object
Build a RestApiResponse specifying response body, status and other HTTP attributes.
  • Field Details

    • response

      protected Serializable response
    • httpStatus

      protected int httpStatus
    • additionalHeaders

      protected final Map<String,String> additionalHeaders
    • additionalCookies

      protected final List<javax.servlet.http.Cookie> additionalCookies
    • characterSet

      protected String characterSet
    • mediaType

      protected String mediaType
  • Constructor Details

    • RestApiResponseBuilder

      public RestApiResponseBuilder()
  • Method Details

    • withResponse

      public RestApiResponseBuilder withResponse(Serializable response)
      Set the body of the response
      Parameters:
      response - the response body
    • withResponseStatus

      public RestApiResponseBuilder withResponseStatus(int httpStatus)
      Set the HTTP status of the response. By default, OK status (200) is set.
      Parameters:
      httpStatus - the HTTP status of the response
      See Also:
      • HttpServletResponse
    • withAdditionalHeader

      public RestApiResponseBuilder withAdditionalHeader(String name, String value)
      Adds a header in the HTTP response
      Parameters:
      name - the name of the header to add in the response.
      value - the value for this header
      See Also:
      • HttpHeaders
    • withAdditionalCookie

      public RestApiResponseBuilder withAdditionalCookie(javax.servlet.http.Cookie cookie)
      Adds a cookie to the HTTP response
      Parameters:
      cookie - the Cookie to add to the response
    • withCharacterSet

      public RestApiResponseBuilder withCharacterSet(String characterSet)
      Set the character set of the HTTP response. By default UTF-8 is set.
      Parameters:
      characterSet - the name of the character set
      See Also:
    • withMediaType

      public RestApiResponseBuilder withMediaType(String mediaType)
      Set the media type of the HTTP response body. By default "application/json" is set.
      Parameters:
      mediaType - the media type to set.
      See Also:
    • withContentRange

      public RestApiResponseBuilder withContentRange(int pageIndex, int pageSize)
      When returning a paged result, sets the start index and the page size. Setting content range overrides the Content-Range header of the response.
      Parameters:
      pageIndex - the start index of the returned page.
      pageSize - the size of the returned page.
      Returns:
      the RestApiResponseBuilder
    • withContentRange

      public RestApiResponseBuilder withContentRange(int pageIndex, int pageSize, long totalSize)
      When returning a paged result, sets the start index, the page size and the total size. Setting content range overrides the Content-Range header of the response.
      Parameters:
      pageIndex - the start index of the returned page.
      pageSize - the size of the returned page.
      totalSize - the total size of the requested entity.
      Returns:
      the RestApiResponseBuilder
    • build

      public RestApiResponse build()
      Returns:
      the RestApiResponse response