public final class ResponseHelper extends Object
Modifier and Type | Field and Description |
---|---|
static org.codehaus.jackson.map.ObjectMapper |
MAPPER |
Constructor and Description |
---|
ResponseHelper() |
Modifier and Type | Method and Description |
---|---|
static javax.ws.rs.core.Response |
buildErrorResponse(ApiResult<Object> apiResult,
javax.ws.rs.core.Response.ResponseBuilder responseBuilder,
javax.servlet.http.HttpServletRequest httpServletRequest)
Build the error response.
|
static javax.ws.rs.core.Response |
buildErrorResponse(Status status,
javax.ws.rs.core.Request request)
Build an error response from the error describing status object and the current request
|
static <T> javax.ws.rs.core.Response |
buildResponse(T result,
String message,
javax.ws.rs.core.Request request,
ApiResult.ResultStatus status,
Reason... errors)
Get the success response from resource
|
static <T> javax.ws.rs.core.Response |
buildResponse(T result,
String message,
javax.ws.rs.core.Request request,
ApiResult.ResultStatus status,
javax.ws.rs.core.Response.Status responseStatus)
Get the success response from resource
|
static <T> javax.ws.rs.core.Response |
buildSuccessResponse(List<T> result,
javax.ws.rs.core.Request request)
Get the success response from resource list
|
static <T> javax.ws.rs.core.Response |
buildSuccessResponse(List<T> result,
javax.ws.rs.core.Request request,
Map<String,Object> metaData)
Get the success response from resource list with specific meta data
|
static <T> javax.ws.rs.core.Response |
buildSuccessResponse(T result,
javax.ws.rs.core.Request request)
Get the success response from resource
|
static <T> javax.ws.rs.core.Response |
buildSuccessResponse(T result,
javax.ws.rs.core.Request request,
String messageKey,
Object... arguments)
Get the success response from resource
|
static <T> javax.ws.rs.core.Response |
buildSuccessResponse(T result,
String message,
javax.ws.rs.core.Request request)
Get the success response from resource
|
protected javax.ws.rs.core.Response |
buildValidationErrorResult(List<ApiResultError> errors,
javax.ws.rs.core.Request request)
returns response with the 400 (bad request) status code, caused by validation errors
|
static int |
getHttpCodeFromErrorCode(String errorCode)
Convert one of the
ErrorCodes constants to a matching HTTP status code. |
protected static <T> String |
getText(javax.ws.rs.core.Request request,
String messageKey,
Object... arguments)
Get text of message key with consideration of locale and replace arguments
|
public static javax.ws.rs.core.Response buildErrorResponse(ApiResult<Object> apiResult, javax.ws.rs.core.Response.ResponseBuilder responseBuilder, javax.servlet.http.HttpServletRequest httpServletRequest) throws ResponseBuildException, ExtensionNotSupportedException
apiResult
- ApiResult
responseBuilder
- Response.ResponseBuilder
httpServletRequest
- HttpServletRequest
Response
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedpublic static javax.ws.rs.core.Response buildErrorResponse(Status status, javax.ws.rs.core.Request request) throws ResponseBuildException, ExtensionNotSupportedException
status
- the status object holding the details about the occurred errorrequest
- the current requestResponseBuildException
- in case of an error while building the responseExtensionNotSupportedException
- in case the extension describing the response content-type is not supportedpublic static <T> javax.ws.rs.core.Response buildResponse(T result, String message, javax.ws.rs.core.Request request, ApiResult.ResultStatus status, Reason... errors) throws ResponseBuildException, ExtensionNotSupportedException
T
- type of resourceresult
- resourcemessage
- message setted in the requestrequest
- Request
status
- The status to set.errors
- Optional errors, which should be send back.Response
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedpublic static <T> javax.ws.rs.core.Response buildResponse(T result, String message, javax.ws.rs.core.Request request, ApiResult.ResultStatus status, javax.ws.rs.core.Response.Status responseStatus) throws ResponseBuildException, ExtensionNotSupportedException
T
- type of resourceresult
- resourcemessage
- message setted in the requestrequest
- Request
status
- The status to set.responseStatus
- Status of the response who is required for the status code.Response
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedpublic static <T> javax.ws.rs.core.Response buildSuccessResponse(List<T> result, javax.ws.rs.core.Request request) throws ResponseBuildException, ExtensionNotSupportedException
T
- type of resourceresult
- list of resourcesrequest
- Request
Response
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedpublic static <T> javax.ws.rs.core.Response buildSuccessResponse(List<T> result, javax.ws.rs.core.Request request, Map<String,Object> metaData) throws ResponseBuildException, ExtensionNotSupportedException
T
- type of resourceresult
- list of resourcesrequest
- Request
metaData
- map with meta data to extend the resultResponse
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedpublic static <T> javax.ws.rs.core.Response buildSuccessResponse(T result, javax.ws.rs.core.Request request) throws ResponseBuildException, ExtensionNotSupportedException
T
- type of resourceresult
- resourcerequest
- Request
Response
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedpublic static <T> javax.ws.rs.core.Response buildSuccessResponse(T result, javax.ws.rs.core.Request request, String messageKey, Object... arguments) throws ResponseBuildException, ExtensionNotSupportedException
T
- type of resourceresult
- resourcemessageKey
- key of messagerequest
- Request
arguments
- elements witch should replace in message textResponse
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedpublic static <T> javax.ws.rs.core.Response buildSuccessResponse(T result, String message, javax.ws.rs.core.Request request) throws ResponseBuildException, ExtensionNotSupportedException
T
- type of resourceresult
- resourcemessage
- message setted in the requestrequest
- Request
Response
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedpublic static final int getHttpCodeFromErrorCode(String errorCode)
ErrorCodes
constants to a matching HTTP status code. In case there
is no match 500 will be returned.errorCode
- the code to convertprotected static <T> String getText(javax.ws.rs.core.Request request, String messageKey, Object... arguments)
T
- type of resourcerequest
- Request
messageKey
- key of messagearguments
- elements witch should replace in message textprotected javax.ws.rs.core.Response buildValidationErrorResult(List<ApiResultError> errors, javax.ws.rs.core.Request request) throws ResponseBuildException, ExtensionNotSupportedException
errors
- list of the validation errorsrequest
- Request
ResponseBuildException
- exception while building the responseExtensionNotSupportedException
- extension is not supportedCopyright © 2019 Communote team. All rights reserved.