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)
-
-
Constructor Summary
Constructors Constructor Description GXInboundResponse(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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ErrorCodegetErrorCode()Gets theErrorCodeinside the entity.<E extends Exception>
EgetException()Gets theExceptioninside the entity.Map<String,List<String>>getHeaderFields()Returns an unmodifiable Map of the header fields.intgetHTTPCode()Gets the status code from the HTTP response message.InputStreamgetInputStream()StringgetMessage()Gets the message in the responsejakarta.ws.rs.core.ResponsegetSource()byte[]getStreamedContent()Returns the content of the response as byte array.StringgetStreamedContentAsString()Gets the streamed content as a string, if possible.booleanhasBAD_REQUESTCode()Checks if the response has a BAD_REQUEST (400) HTTP status.booleanhasCREATEDCode()Checks if the response has a CREATED (201) HTTP status.booleanhasErrorCode()Checks if there is anErrorCodein the entity.booleanhasException()Checks if there is anExceptionin the entity.booleanhasGXError()Checks if the response was generated as aGXOutboundErrorResponse.booleanhasNOT_ACCEPTABLECode()Checks if the response has a NOT_ACCEPTABLE (406) HTTP status.booleanhasOKCode()Checks if the response has a OK (200) HTTP status.booleanisErrorResponse()Checks if the response is in the range 4xx - 5xx .booleanisSuccessResponse()Checks if the response is in the range 2xx .<T> TtryConvertStreamedContentFromJson(Class<T> raw)Tries to convert the content from its Json serialization, if possible.
-
-
-
Constructor Detail
-
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
- Parameters:
connection- the connection from which to parse the information- Throws:
IOException
-
GXInboundResponse
public GXInboundResponse(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.MediaType[] expectedMediaTypes)Builds a new inbound response.- Parameters:
source- the original responseexpectedMediaTypes- the expected media type(s) in the response
-
-
Method Detail
-
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
public <E extends Exception> E getException() throws ClassNotFoundException
Gets theExceptioninside the entity.- 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
public ErrorCode getErrorCode()
Gets theErrorCodeinside 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
- Throws:
IOException
-
getStreamedContent
public byte[] getStreamedContent() throws IOExceptionReturns 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
-
getSource
public jakarta.ws.rs.core.Response getSource() throws UnsupportedOperationException- Returns:
- the source response, if available
- Throws:
UnsupportedOperationException- if not available
-
-