Class HttpResponseWrapper

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class HttpResponseWrapper
    extends Object
    implements Closeable
    Wrapper for a CloseableHttpResponse which provides a couple of convenient methods for the work with the response
    Since:
    7.0.0
    Author:
    XIMA MEDIA GmbH
    • Constructor Detail

      • HttpResponseWrapper

        public HttpResponseWrapper​(@NotNull
                                   @NotNull org.apache.http.client.methods.CloseableHttpResponse originResponse,
                                   Charset outputCharset)
        The one and only constructor for this wrapper!
        Parameters:
        originResponse - the CloseableHttpResponse that should be wrapped
        outputCharset - to used charset for response content. If null, 'UTF-8' is used as default.
    • Method Detail

      • isRedirect

        public boolean isRedirect()
        Returns:
        true if an HTTP status code is 3xx otherwise false
      • getContent

        public String getContent()
                          throws IOException
        Returns:
        the content from the body of the underlying HTTP entity
        Throws:
        org.apache.http.client.HttpResponseException - signals a non 2xx HTTP response
        IOException - in case of a problem or the connection was aborted
      • getEncoding

        public String getEncoding()
        Returns:
        the Content-Encoding header of the underlying HTTP entity, or null if the content encoding is unknown
      • getResponseCode

        public int getResponseCode()
        Returns:
        the HTTP status code of the underlying HTTP entity.
      • getResponseMessage

        public String getResponseMessage()
        Returns:
        response message of HTTP with status code or null
      • getReasonPhrase

        public String getReasonPhrase()
        Returns:
        The reason phrase of the status line returned by the HTTP response, when available, or null otherwise.
      • getContentType

        public String getContentType()
        Returns:
        the Content-Type header of the underlying HTTP entity, or null if the content type is unknown
      • updateContent

        public void updateContent​(String content,
                                  org.apache.http.entity.ContentType contentType)
                           throws IOException
        Updates the content of the underlying response.
        Parameters:
        content - the content to update
        contentType - the content type of the update content
        Throws:
        IOException - if an error occurs while reading the input stream on the specified entity.
      • getOriginResponse

        public org.apache.http.client.methods.CloseableHttpResponse getOriginResponse()
        Returns:
        the original CloseableHttpResponse object from the wrapper