Class GXInboundResponse


  • public class GXInboundResponse
    extends Object
    The response returned from the web application.
    Author:
    Manuele Simi (ISTI CNR)
    • Constructor Detail

      • GXInboundResponse

        public GXInboundResponse​(jakarta.ws.rs.core.Response source)
        Builds a new inbound response.
        Parameters:
        source - the original response
      • GXInboundResponse

        public GXInboundResponse​(jakarta.ws.rs.core.Response response,
                                 jakarta.ws.rs.core.MediaType[] expectedMediaTypes)
        Builds a new inbound response.
        Parameters:
        source - the original response
        expectedMediaTypes - the expected media type(s) in the response
    • Method Detail

      • hasException

        public boolean hasException()
        Checks if there is an Exception in the entity.
        Returns:
        true if the entity holds an exception, false otherwise
      • isErrorResponse

        public boolean isErrorResponse()
        Checks if the response is in the range 4xx - 5xx .
        Returns:
        true if it is an error response.
      • isSuccessResponse

        public boolean isSuccessResponse()
        Checks if the response is in the range 2xx .
        Returns:
        true if it is a success response.
      • hasGXError

        public boolean hasGXError()
        Checks if the response was generated as a GXOutboundErrorResponse .
        Returns:
        true if it is an error response generated with GXRest.
      • hasErrorCode

        public boolean hasErrorCode()
        Checks if there is an ErrorCode in the entity.
        Returns:
        true if the entity holds an errorcode, false otherwise
      • getErrorCode

        public ErrorCode getErrorCode()
        Gets the ErrorCode inside the entity.
        Returns:
        the error code or null
      • getMessage

        public String getMessage()
        Gets the message in the response
        Returns:
        the message
      • getStreamedContentAsString

        public String getStreamedContentAsString()
                                          throws IOException
        Gets the streamed content as a string, if possible.
        Returns:
        the content
        Throws:
        IOException - if unable to read the content
      • getStreamedContent

        public byte[] getStreamedContent()
                                  throws IOException
        Returns the content of the response as byte array.
        Returns:
        the streamedContent
        Throws:
        IOException - if unable to read the content
      • tryConvertStreamedContentFromJson

        public <T> T tryConvertStreamedContentFromJson​(Class<T> raw)
                                                throws Exception
        Tries to convert the content from its Json serialization, if possible.
        Type Parameters:
        T - the type of the desired object
        Returns:
        an object of type T from the content
        Throws:
        Exception - if the deserialization fails
      • getHTTPCode

        public int getHTTPCode()
        Gets the status code from the HTTP response message.
        Returns:
        the HTTP code
      • hasCREATEDCode

        public boolean hasCREATEDCode()
        Checks if the response has a CREATED (201) HTTP status.
        Returns:
        true if CREATED, false otherwise
      • hasOKCode

        public boolean hasOKCode()
        Checks if the response has a OK (200) HTTP status.
        Returns:
        true if OK, false otherwise
      • hasNOT_ACCEPTABLECode

        public boolean hasNOT_ACCEPTABLECode()
        Checks if the response has a NOT_ACCEPTABLE (406) HTTP status.
        Returns:
        true if NOT_ACCEPTABLE, false otherwise
      • hasBAD_REQUESTCode

        public boolean hasBAD_REQUESTCode()
        Checks if the response has a BAD_REQUEST (400) HTTP status.
        Returns:
        true if BAD_REQUEST, false otherwise
      • getHeaderFields

        public Map<String,​List<String>> getHeaderFields()
        Returns an unmodifiable Map of the header fields. The Map keys are Strings that represent the response-header field names. Each Map value is an unmodifiable List of Strings that represents the corresponding field values.
        Returns:
        a Map of header fields