Package com.tccc.commons.httpclient
Class JsonResp<T>
java.lang.Object
com.tccc.commons.httpclient.JsonResp<T>
Data class that encapsulates information related to the return values
associated with JsonTemplate calls. It combines a
ContentResponse
with the parsed <T>
object.
Data Fields
private int status; // the HTTP status
private ContentResponse response; //
private ResponseEnvelope<T> envelope; //
private T data; //
private Exception exception; // holds the exception when an error occurs
- Since:
- 1.0
- Version:
- 2022-08-30
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetData()
Returns the payload message object.Returns the response envelope.Returns the error string of the envelope.Returns the exception.Returns the content response.int
Returns the HTTP status code.boolean
hasError()
Return true if the status is notHttpStatus.OK
void
Sets the data object.void
setEnvelope
(ResponseEnvelope<T> envelope) Sets the response envelope.void
setException
(Exception exception) Sets the exception.void
setStatus
(int status) Sets the HTTP status code.boolean
success()
Return true if the request succeeded.void
Throws aRequestException
if the status of the response isn'tHttpStatus.OK
.void
throwRequestExceptionOnError
(int errStatus, String errMsg) Throws aRequestException
if the status of the response isn'tHttpStatus.OK
.
-
Constructor Details
-
JsonResp
public JsonResp()
-
-
Method Details
-
getStatus
public int getStatus()Returns the HTTP status code.- Returns:
HttpStatus
-
setStatus
public void setStatus(int status) Sets the HTTP status code.- Parameters:
status
- the HTTP status
-
getResponse
Returns the content response.- Returns:
ContentResponse
.
-
getEnvelope
Returns the response envelope.- Returns:
ResponseEnvelope
-
setEnvelope
Sets the response envelope.- Parameters:
envelope
- the response envelope
-
getData
Returns the payload message object.- Returns:
T
-
setData
Sets the data object.- Parameters:
data
- the data object
-
hasError
public boolean hasError()Return true if the status is notHttpStatus.OK
-
getException
Returns the exception.- Returns:
- exception if an error occurred, otherwise
null
-
setException
Sets the exception.- Parameters:
exception
- the exception that stopped the processing
-
throwRequestExceptionOnError
public void throwRequestExceptionOnError()Throws aRequestException
if the status of the response isn'tHttpStatus.OK
. It uses the status and error message from the response in the exception. -
throwRequestExceptionOnError
Throws aRequestException
if the status of the response isn'tHttpStatus.OK
.- Parameters:
errStatus
- the status to use in exception; 0 uses response statuserrMsg
- the message to use in exception;null
uses response error
-
getErrorMsg
Returns the error string of the envelope.- Returns:
- error string from the envelope if it exists, otherwise
null
-
success
public boolean success()Return true if the request succeeded. This is true if the status is 200 AND if there is no envelope error.
-