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:
-
ContentResponseJsonTemplate
-
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.org.eclipse.jetty.client.api.ContentResponseReturns the content response.intReturns the HTTP status code.booleanhasError()Return true if the status is notHttpStatus.OKvoidSets the data object.voidsetEnvelope(ResponseEnvelope<T> envelope) Sets the response envelope.voidsetException(Exception exception) Sets the exception.voidsetStatus(int status) Sets the HTTP status code.booleansuccess()Return true if the request succeeded.voidThrows aRequestExceptionif the status of the response isn'tHttpStatus.OK.voidthrowRequestExceptionOnError(int errStatus, String errMsg) Throws aRequestExceptionif 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
public org.eclipse.jetty.client.api.ContentResponse 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 aRequestExceptionif the status of the response isn'tHttpStatus.OK. It uses the status and error message from the response in the exception. -
throwRequestExceptionOnError
Throws aRequestExceptionif 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;nulluses 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.
-