Interface Response


  • public interface Response

    An interface describing the response of an HTTP request.

    This interface is used by ResponseProcessor objects to access the data received from the HTTP server. It provides query methods for the typical information, such as the HTTP status code, the headers, or the response body as a stream.

    Note that underlying HTTP libraries used to implement this interface typically place some restrictions on the usage of the methods provided here, especially with regards to the response body. So an implementation should expect that the body stream can be consumed only once. On the other hand, it is not necessary to explicitly release any of the resources that might be hold by a response object; this is done by the framework.

    • Method Detail

      • statusCode

        int statusCode()
        Returns the HTTP status code of this response.
        Returns:
        the HTTP status code
      • isSuccess

        boolean isSuccess()
        Returns a flag whether the request was successful. This is a shortcut for testing the statusCode() against a range of well-known HTTP status codes. For certain use cases with special requirements for the codes returned by the server, it may be necessary to do the check manually.
        Returns:
        true if the request has been successful; false otherwise
      • headerNames

        Set<String> headerNames()
        Returns a set with the names of the headers contained in the response.
        Returns:
        a set with the names of the defined headers
      • header

        String header​(String name)
        Returns the value of the header with the given name.
        Parameters:
        name - the name of the header in question
        Returns:
        the value of this header or null if it is not present
      • bodyStream

        InputStream bodyStream()
        Returns an InputStream for the body of this response; so the data received from the server can be streamed. Result is never null; if the request did not yield a response body, an empty stream is returned.
        Returns:
        an InputStream to access the response body