Class RestApiResponseBuilder
java.lang.Object
org.bonitasoft.web.extension.rest.RestApiResponseBuilder
Build a RestApiResponse specifying response body, status and other HTTP attributes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<javax.servlet.http.Cookie>protected Stringprotected intprotected Stringprotected Serializable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()withAdditionalCookie(javax.servlet.http.Cookie cookie) Adds a cookie to the HTTP responsewithAdditionalHeader(String name, String value) Adds a header in the HTTP responsewithCharacterSet(String characterSet) Set the character set of the HTTP response.withContentRange(int pageIndex, int pageSize) When returning a paged result, sets the start index and the page size.withContentRange(int pageIndex, int pageSize, long totalSize) When returning a paged result, sets the start index, the page size and the total size.withMediaType(String mediaType) Set the media type of the HTTP response body.withResponse(Serializable response) Set the body of the responsewithResponseStatus(int httpStatus) Set the HTTP status of the response.
-
Field Details
-
response
-
httpStatus
protected int httpStatus -
additionalHeaders
-
additionalCookies
-
characterSet
-
mediaType
-
-
Constructor Details
-
RestApiResponseBuilder
public RestApiResponseBuilder()
-
-
Method Details
-
withResponse
Set the body of the response- Parameters:
response- the response body
-
withResponseStatus
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
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
Adds a cookie to the HTTP response- Parameters:
cookie- theCookieto add to the response
-
withCharacterSet
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
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
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
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
- Returns:
- the RestApiResponse response
-