Class RequestResponse<T>

  • Direct Known Subclasses:
    RequestResponseOK, VitamError

    public abstract class RequestResponse<T>
    extends java.lang.Object
    Abstract RequestResponse for all request response in Vitam
    • Constructor Detail

      • RequestResponse

        public RequestResponse()
    • Method Detail

      • getHttpCode

        public int getHttpCode()
        Returns:
        the httpCode
      • setHttpCode

        public RequestResponse<T> setHttpCode​(int httpCode)
        Parameters:
        httpCode - the httpCode to set
        Returns:
        this
      • getStatus

        public int getStatus()
      • isOk

        public boolean isOk()
        Returns:
        True if this RequestResponse is an Ok response
      • addHeader

        public RequestResponse<T> addHeader​(java.lang.String key,
                                            java.lang.String value)
      • getHeaderString

        public java.lang.String getHeaderString​(java.lang.String key)
      • getVitamHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getVitamHeaders()
      • unSetVitamHeaders

        public void unSetVitamHeaders()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toJsonNode

        public com.fasterxml.jackson.databind.JsonNode toJsonNode()
        Returns:
        the Json representation
        Throws:
        java.lang.IllegalStateException - if JsonNode parse exception occurred
      • parseHeadersFromResponse

        public RequestResponse<T> parseHeadersFromResponse​(javax.ws.rs.core.Response response)
      • parseFromResponse

        public static RequestResponse<com.fasterxml.jackson.databind.JsonNode> parseFromResponse​(javax.ws.rs.core.Response response)
                                                                                          throws java.lang.IllegalStateException
        Parser the response for a RequestResponse object.

        Might return an empty VitamError in case response is empty with only the HttpCode set and the Code set to empty String.
        Parameters:
        response - to parse in RequestResponse
        Returns:
        The associate RequestResponseOk or VitamError
        Throws:
        java.lang.IllegalStateException - if the response cannot be parsed to one of the two model
      • parseFromResponse

        public static <T> RequestResponse<T> parseFromResponse​(javax.ws.rs.core.Response response,
                                                               java.lang.Class<T> clazz)
                                                        throws java.lang.IllegalStateException
        Parser the response for a RequestResponse object.

        Might return an empty VitamError in case response is empty with only the HttpCode set and the Code set to empty String.
        Parameters:
        response - to parse in RequestResponse
        Returns:
        The associate RequestResponseOk or VitamError
        Throws:
        java.lang.IllegalStateException - if the response cannot be parsed to one of the two model
      • isRequestResponseOk

        public static boolean isRequestResponseOk​(com.fasterxml.jackson.databind.JsonNode requestResponseAsJsonNode)
                                           throws java.lang.IllegalStateException
        Check if the JsonNode is a RequestResponse and OK
        Parameters:
        requestResponseAsJsonNode - as request response as a JsonNode
        Returns:
        true if JsonNode contains httpCode as 2xx or 3xx, false if httpCode as 4xx or 5xx
        Throws:
        java.lang.IllegalStateException - if JsonNode is not a valid instance of requestResponse
      • toResponse

        public abstract javax.ws.rs.core.Response toResponse()
        transform a RequestResponse to a standard response
        Returns:
        Response