Class 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.

    • Constructor Summary

      Constructors 
      Constructor Description
      ResponseHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method 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.
    • Constructor Detail

      • ResponseHelper

        public ResponseHelper()
    • 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 response
        entityType - 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 response
        entityType - 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 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.

        Parameters:
        response - the response to close
      • closeResponseSilentlyIfNotBuffered

        public 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).
        Parameters:
        response - the response to close
      • shouldAutoCloseResponseInputStream

        @Deprecated
        public static void shouldAutoCloseResponseInputStream​(boolean shouldAutoClose)
        Deprecated.
        use Options.shouldAutoCloseResponseInputStream instead
        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