Package org.chenile.base.response
Class GenericResponse<T>
java.lang.Object
org.chenile.base.response.GenericResponse<T>
- Type Parameters:
T
- - the actual payload type returned by the service
- All Implemented Interfaces:
WarningAware
A generic response that would be returned for all the services. It includes the payload
returned by the service along with other information such as Http Status code, warnings and errors.
This allows a comprehensive and consistent way of communicating with the rest of the world.
This can be used across protocols though it uses the Http status code
This can be used across protocols though it uses the Http status code
-
Field Summary
Modifier and TypeFieldDescriptionprivate T
private List<ResponseMessage>
private ResponseMessage
private boolean
Fields inherited from interface org.chenile.base.response.WarningAware
WARNING_MESSAGES_KEY
-
Constructor Summary
ConstructorDescriptionGenericResponse
(ResponseMessage message) GenericResponse
(T data) Construct a response with the given payload.
Setsuccess
to true
By default, callsetCode(int)
to HTTP status OK. -
Method Summary
Modifier and TypeMethodDescriptionvoid
int
getCode()
getData()
int
boolean
void
void
setCode
(int errorCode) void
void
setDescription
(String message) void
setSeverity
(ErrorType severity) void
setSubErrorCode
(int subErrorCode) void
setSuccess
(boolean success)
-
Field Details
-
success
private boolean success -
errors
-
responseMessage
-
data
-
-
Constructor Details
-
GenericResponse
public GenericResponse() -
GenericResponse
-
GenericResponse
Construct a response with the given payload.
Setsuccess
to true
By default, callsetCode(int)
to HTTP status OK. It will be over-ridden later if required from the success and warning error codes that are set in OperationDefinition- Parameters:
data
- the payload of the response
-
-
Method Details
-
isSuccess
public boolean isSuccess() -
setSuccess
public void setSuccess(boolean success) -
getCode
public int getCode() -
setCode
public void setCode(int errorCode) -
getSeverity
-
setSeverity
-
getDescription
-
setDescription
-
getData
-
setData
-
getSubErrorCode
public int getSubErrorCode() -
setSubErrorCode
public void setSubErrorCode(int subErrorCode) -
getErrors
-
addWarningMessage
- Specified by:
addWarningMessage
in interfaceWarningAware
-
getWarningMessages
- Specified by:
getWarningMessages
in interfaceWarningAware
-
removeAllWarnings
public void removeAllWarnings()- Specified by:
removeAllWarnings
in interfaceWarningAware
-