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.
| Modifier and Type | Class and Description |
|---|---|
static class |
ResponseHelper.ErrorCodeAndMessage |
| Constructor and Description |
|---|
ResponseHelper() |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeResponseSilently(javax.ws.rs.core.Response response)
Closes a given
Response and ignores any thrown exceptions. |
static void |
closeResponseSilentlyIfNotBuffered(javax.ws.rs.core.Response response)
Closes a
Response silently if a Response is not buffered or is not backed by an unconsumed stream
(e.g., for responses with no body). |
static <T> T |
readEntity(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> T |
readEntity(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 void |
readWithoutEntity(javax.ws.rs.core.Response response)
Simple response handler that just cleans up the response, assuming
no entity needs to be read out.
|
static void |
shouldAutoCloseResponseInputStream(boolean shouldAutoClose)
Deprecated.
use Options.shouldAutoCloseResponseInputStream instead
|
static void |
throwIfNotSuccessful(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 void |
throwIfNotSuccessful(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.
|
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.
response - The response receivedpublic 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.
response - The response received.serviceDetails - The service details of the responsepublic 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.
response - the responsepublic 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.
response - the responseentityType - the type of the entity to readpublic 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.
response - the responseentityType - the type of the entity to readBmcExceptionpublic static void closeResponseSilently(javax.ws.rs.core.Response response)
Closes a given Response and ignores any thrown exceptions. Closing a response is idempotent, so there
is no harm in closing a Response once the response has been fully processed to ensure that the client
connection is not left in use.
response - the response to closepublic static void closeResponseSilentlyIfNotBuffered(@Nonnull javax.ws.rs.core.Response response)
Closes a Response silently if a Response is not buffered or is not backed by an unconsumed stream
(e.g., for responses with no body).
response - the response to close@Deprecated public static void shouldAutoCloseResponseInputStream(boolean shouldAutoClose)
Sets 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
Copyright © 2016–2022. All rights reserved.