Package com.oracle.bmc.http.internal
Class ResponseHelper
- java.lang.Object
-
- com.oracle.bmc.http.internal.ResponseHelper
-
public class ResponseHelper extends Object
A BmcException exception is thrown in response to failures from a REST endpoint.It contains the status code of the HTTP response as well as an application code and message describing the problem.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResponseHelper.ErrorCodeAndMessage
-
Constructor Summary
Constructors Constructor Description ResponseHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcloseResponseSilently(javax.ws.rs.core.Response response)Closes a givenResponseand ignores any thrown exceptions.static voidcloseResponseSilentlyIfNotBuffered(javax.ws.rs.core.Response response)Closes aResponsesilently if aResponseis not buffered or is not backed by an unconsumed stream (e.g., for responses with no body).static <T> TreadEntity(javax.ws.rs.core.Response response, Class<T> entityType)Reads an entity out of the given response if its status code is 2xx or 304.static <T> TreadEntity(javax.ws.rs.core.Response response, javax.ws.rs.core.GenericType<T> entityType)Reads an entity out of the given response if its status code is 2xx or 304.static voidreadWithoutEntity(javax.ws.rs.core.Response response)Simple response handler that just cleans up the response, assuming no entity needs to be read out.static voidshouldAutoCloseResponseInputStream(boolean shouldAutoClose)Deprecated.use Options.shouldAutoCloseResponseInputStream insteadstatic voidthrowIfNotSuccessful(javax.ws.rs.core.Response response)Throws BmcException if the response status is not in the family Family.SUCCESSFUL, or is not Status.NOT_MODIFIED.static voidthrowIfNotSuccessful(javax.ws.rs.core.Response response, ServiceDetails serviceDetails)Throws BmcException if the response status is not in the family Family.SUCCESSFUL, or is not Status.NOT_MODIFIED.
-
-
-
Method Detail
-
throwIfNotSuccessful
public static void throwIfNotSuccessful(@Nonnull javax.ws.rs.core.Response response)
Throws BmcException if the response status is not in the family Family.SUCCESSFUL, or is not Status.NOT_MODIFIED.- Parameters:
response- The response received
-
throwIfNotSuccessful
public static void throwIfNotSuccessful(@Nonnull javax.ws.rs.core.Response response, @Nonnull ServiceDetails serviceDetails)
Throws BmcException if the response status is not in the family Family.SUCCESSFUL, or is not Status.NOT_MODIFIED.- Parameters:
response- The response received.serviceDetails- The service details of the response
-
readWithoutEntity
public static void readWithoutEntity(@Nonnull javax.ws.rs.core.Response response)
Simple response handler that just cleans up the response, assuming no entity needs to be read out.- Parameters:
response- the response
-
readEntity
public static <T> T readEntity(@Nonnull javax.ws.rs.core.Response response, javax.ws.rs.core.GenericType<T> entityType)
Reads an entity out of the given response if its status code is 2xx or 304.Must call
throwIfNotSuccessful(Response)first.- Parameters:
response- the responseentityType- the type of the entity to read- Returns:
- the entity (if the response’s status code was 2xx)
-
readEntity
public static <T> T readEntity(@Nonnull javax.ws.rs.core.Response response, Class<T> entityType) throws BmcException
Reads an entity out of the given response if its status code is 2xx or 304.Must call
throwIfNotSuccessful(Response)first.- Parameters:
response- the responseentityType- the type of the entity to read- Returns:
- the entity (if the response’s status code was 2xx), or null if 304
- Throws:
BmcException
-
closeResponseSilently
public static void closeResponseSilently(javax.ws.rs.core.Response response)
Closes a givenResponseand ignores any thrown exceptions.Closing a response is idempotent, so there is no harm in closing a
Responseonce the response has been fully processed to ensure that the client connection is not left in use.- Parameters:
response- the response to close
-
closeResponseSilentlyIfNotBuffered
public static void closeResponseSilentlyIfNotBuffered(@Nonnull javax.ws.rs.core.Response response)
Closes aResponsesilently if aResponseis not buffered or is not backed by an unconsumed stream (e.g., for responses with no body).- Parameters:
response- the response to close
-
shouldAutoCloseResponseInputStream
@Deprecated public static void shouldAutoCloseResponseInputStream(boolean shouldAutoClose)
Deprecated.use Options.shouldAutoCloseResponseInputStream insteadSets the boolean value to indicate if the SDK should auto-close the InputStream stream returned from the response once the stream has been read until the content-length of the stream Note : This has been added to automatically release connections from the connection pool when using the Apache Connector since the Apache Connector uses connection pooling by default
-
-