Class Response

java.lang.Object
com.groiss.http.Response
All Implemented Interfaces:
SilentCloseable, AutoCloseable

public class Response extends Object implements SilentCloseable
This class implements the response of a request executed via one of the request methods of Client.
  • Method Details

    • close

      public void close()
      Closes the response and therefore releases all resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SilentCloseable
    • getStatusCode

      public int getStatusCode()
      Returns the HTTP status code of the response (e.g. 200 for SUCCESS)
      Returns:
      the HTTP status code of the response
    • getStatusMessage

      public String getStatusMessage()
      Returns the HTTP status message of the response
      Returns:
      the HTTP status message of the response
    • getStringResult

      public String getStringResult()
      Returns the result of the request as string object
      Returns:
      the result of the response
    • getJSONObjectResult

      public JSONObject getJSONObjectResult()
      Returns the result of the request as JSONObject
      Returns:
      the result of the response
    • getJSONArrayResult

      public JSONArray getJSONArrayResult()
      Returns the result of the request as JSONArray
      Returns:
      the result of the response
    • getResult

      public InputStream getResult()
      Returns the result of the request as InputStream (e.g. needed if the result is a file)
      Returns:
      the result of the response
    • getHeaders

      @Deprecated(forRemoval=true, since="ep 10.0 (rev. 36486)") public Map<String,String> getHeaders()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since ep 10.0 (rev. 36486) as it cannot handle the case of multiple headers with the same name (case-sensitive) - this method will only return the last value for such headers. Use getAllHeaders() or getHeaderValues(String) instead.
      Returns the headers of the response
      Returns:
      the headers of the response
    • getAllHeaders

      public Map<String,List<String>> getAllHeaders()
      Returns the headers of the response. If the response contains multiple headers with the same name (case-sensitive) each value will be present in the list of the map entry with the header's name. The lists are ordered by the sequence of the corresponding header in the response. Note: for retrieval of header values by case-insensitive header names, method getHeaderValues(String) can be used.
      Returns:
      the headers and their values. If the response has no such headers, an empty map is returned.
    • getHeaderValues

      public List<String> getHeaderValues(String headerName)
      Returns the values of the header with the given name (case-insensitive) of the response.
      Parameters:
      headerName - the name of the header which values shall be returned (name comparison is done case-insensitive)
      Returns:
      all values of the specified header in the order of the sequence of the headers in the response. If the response has no such headers, an empty list is returned.
    • getRequestString

      public String getRequestString()
      get the request details this Response originated from
      Returns:
      the request method + URL + protocol used when requesting this Response