Class RESTAllocate.CloseableClientResponse

java.lang.Object
ecmwf.ecpds.mover.service.RESTAllocate.CloseableClientResponse
All Implemented Interfaces:
Closeable, AutoCloseable
Enclosing class:
RESTAllocate

public class RESTAllocate.CloseableClientResponse extends Object implements Closeable
A wrapper around ClientResponse that implements Closeable.

This allows the use of try-with-resources to automatically release underlying HTTP/SSL connections by calling ClientResponse.consumeContent() when done.

  • Constructor Details

    • CloseableClientResponse

      public CloseableClientResponse(org.apache.wink.client.ClientResponse response)
      Constructs a new CloseableClientResponse wrapping the given ClientResponse.
      Parameters:
      response - the ClientResponse to wrap; must not be null
  • Method Details

    • getStatusCode

      public int getStatusCode()
      Returns the HTTP status code of the response.
      Returns:
      the HTTP status code
    • getMessage

      public String getMessage()
      Returns the HTTP status message of the response.
      Returns:
      the status message
    • getEntity

      public <T> T getEntity(Class<T> t)
      Reads and returns the entity from the response.

      Note that calling this method will fully read the entity into memory.

      Type Parameters:
      T - the type of the entity
      Parameters:
      t - the class of the entity
      Returns:
      the entity deserialized as the given class
    • close

      public void close()
      Closes the response by consuming its content.

      This ensures that the underlying HTTP/SSL connection is released and prevents potential connection leaks.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs while consuming the content