Class GXInboundResponse
java.lang.Object
org.gcube.common.gxrest.response.inbound.GXInboundResponse
The response returned from the web application.
- Author:
- Manuele Simi (ISTI CNR), Luca Frosini (ISTI-CNR)
-
Constructor Summary
ConstructorsConstructorDescriptionGXInboundResponse(jakarta.ws.rs.core.Response source) Builds a new inbound response.GXInboundResponse(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.MediaType[] expectedMediaTypes) Builds a new inbound response.GXInboundResponse(HttpURLConnection connection) Builds a new inbound response. -
Method Summary
Modifier and TypeMethodDescriptionGets theErrorCodeinside the entity.<E extends Exception>
EGets theExceptioninside the entity.Returns an unmodifiable Map of the header fields.intGets the status code from the HTTP response message.Gets the input stream of the response.Gets the message in the responsejakarta.ws.rs.core.Responsebyte[]Returns the content of the response as byte array.Gets the streamed content as a string, if possible.booleanChecks if the response has a BAD_REQUEST (400) HTTP status.booleanChecks if the response has a CREATED (201) HTTP status.booleanChecks if there is anErrorCodein the entity.booleanChecks if there is anExceptionin the entity.booleanChecks if the response was generated as aGXOutboundErrorResponse.booleanChecks if the response has a NOT_ACCEPTABLE (406) HTTP status.booleanChecks if the response has a OK (200) HTTP status.booleanChecks if the response is in the range 4xx - 5xx .booleanChecks if the response is in the range 2xx .<T> TTries to convert the content from its Json serialization, if possible.
-
Constructor Details
-
GXInboundResponse
public GXInboundResponse(jakarta.ws.rs.core.Response source) Builds a new inbound response.- Parameters:
source- the original response
-
GXInboundResponse
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 responseexpectedMediaTypes- the expected media type(s) in the response
-
-
Method Details
-
hasException
public boolean hasException()Checks if there is anExceptionin 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 aGXOutboundErrorResponse.- Returns:
- true if it is an error response generated with GXRest.
-
getException
Gets theExceptioninside 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 anErrorCodein the entity.- Returns:
- true if the entity holds an errorcode, false otherwise
-
getErrorCode
Gets theErrorCodeinside the entity.- Returns:
- the error code or null
-
getMessage
Gets the message in the response- Returns:
- the message
-
getStreamedContentAsString
Gets the streamed content as a string, if possible.- Returns:
- the content
- Throws:
IOException- if unable to read the content
-
getInputStream
Gets the input stream of the response.- Returns:
- the input stream
- Throws:
IOException- if an I/O error occurs
-
getStreamedContent
Returns the content of the response as byte array.- Returns:
- the streamedContent
- Throws:
IOException- if unable to read the content
-
tryConvertStreamedContentFromJson
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
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
- Returns:
- the source response, if available
- Throws:
UnsupportedOperationException- if not available
-