Class GXInboundResponse

java.lang.Object
org.gcube.common.gxrest.response.inbound.GXInboundResponse

public class GXInboundResponse extends Object
The response returned from the web application.
Author:
Manuele Simi (ISTI CNR), Luca Frosini (ISTI-CNR)
  • Constructor Details

    • GXInboundResponse

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

      public GXInboundResponse(HttpURLConnection connection) throws IOException
      Builds a new inbound response.
      Parameters:
      connection - the connection from which to parse the information
      Throws:
      IOException - if an I/O error occurs
    • GXInboundResponse

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

    • 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.
    • getException

      public <E extends Exception> E getException() throws ClassNotFoundException
      Gets the Exception inside the entity.
      Type Parameters:
      E - the type of the exception
      Returns:
      the exception or null
      Throws:
      ClassNotFoundException - if the exception's class is not available on the classpath
    • 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
    • getInputStream

      public InputStream getInputStream() throws IOException
      Gets the input stream of the response.
      Returns:
      the input stream
      Throws:
      IOException - if an I/O error occurs
    • 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
      Parameters:
      raw - the class 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
    • getSource

      public jakarta.ws.rs.core.Response getSource() throws UnsupportedOperationException
      Returns:
      the source response, if available
      Throws:
      UnsupportedOperationException - if not available