Class JsonResp<T>

java.lang.Object
com.tccc.commons.httpclient.JsonResp<T>

public class JsonResp<T> extends Object
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 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 ContentResponse getResponse()
      Returns the content response.
      Returns:
      ContentResponse .
    • getEnvelope

      public ResponseEnvelope<T> getEnvelope()
      Returns the response envelope.
      Returns:
      ResponseEnvelope
    • setEnvelope

      public void setEnvelope(ResponseEnvelope<T> envelope)
      Sets the response envelope.
      Parameters:
      envelope - the response envelope
    • getData

      public T getData()
      Returns the payload message object.
      Returns:
      T
    • setData

      public void setData(T data)
      Sets the data object.
      Parameters:
      data - the data object
    • hasError

      public boolean hasError()
      Return true if the status is not HttpStatus.OK
    • getException

      public Exception getException()
      Returns the exception.
      Returns:
      exception if an error occurred, otherwise null
    • setException

      public void setException(Exception exception)
      Sets the exception.
      Parameters:
      exception - the exception that stopped the processing
    • throwRequestExceptionOnError

      public void throwRequestExceptionOnError()
      Throws a RequestException if the status of the response isn't HttpStatus.OK . It uses the status and error message from the response in the exception.
    • throwRequestExceptionOnError

      public void throwRequestExceptionOnError(int errStatus, String errMsg)
      Throws a RequestException if the status of the response isn't HttpStatus.OK .
      Parameters:
      errStatus - the status to use in exception; 0 uses response status
      errMsg - the message to use in exception; null uses response error
    • getErrorMsg

      public String 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.