Class RestApiResponseBuilder
- java.lang.Object
-
- org.bonitasoft.web.extension.rest.RestApiResponseBuilder
-
public class RestApiResponseBuilder extends java.lang.ObjectBuild a RestApiResponse specifying response body, status and other HTTP attributes.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<javax.servlet.http.Cookie>additionalCookiesprotected java.util.Map<java.lang.String,java.lang.String>additionalHeadersprotected java.lang.StringcharacterSetprotected inthttpStatusprotected java.lang.StringmediaTypeprotected java.io.Serializableresponse
-
Constructor Summary
Constructors Constructor Description RestApiResponseBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RestApiResponsebuild()RestApiResponseBuilderwithAdditionalCookie(javax.servlet.http.Cookie cookie)Adds a cookie to the HTTP responseRestApiResponseBuilderwithAdditionalHeader(java.lang.String name, java.lang.String value)Adds a header in the HTTP responseRestApiResponseBuilderwithCharacterSet(java.lang.String characterSet)Set the character set of the HTTP response.RestApiResponseBuilderwithContentRange(int pageIndex, int pageSize)When returning a paged result, sets the start index and the page size.RestApiResponseBuilderwithContentRange(int pageIndex, int pageSize, long totalSize)When returning a paged result, sets the start index, the page size and the total size.RestApiResponseBuilderwithMediaType(java.lang.String mediaType)Set the media type of the HTTP response body.RestApiResponseBuilderwithResponse(java.io.Serializable response)Set the body of the responseRestApiResponseBuilderwithResponseStatus(int httpStatus)Set the HTTP status of the response.
-
-
-
Field Detail
-
response
protected java.io.Serializable response
-
httpStatus
protected int httpStatus
-
additionalHeaders
protected final java.util.Map<java.lang.String,java.lang.String> additionalHeaders
-
additionalCookies
protected final java.util.List<javax.servlet.http.Cookie> additionalCookies
-
characterSet
protected java.lang.String characterSet
-
mediaType
protected java.lang.String mediaType
-
-
Method Detail
-
withResponse
public RestApiResponseBuilder withResponse(java.io.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(java.lang.String name, java.lang.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- theCookieto add to the response
-
withCharacterSet
public RestApiResponseBuilder withCharacterSet(java.lang.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:
Charset
-
withMediaType
public RestApiResponseBuilder withMediaType(java.lang.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:
- Registered media types
-
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
-
-