Class HttpResponseParser


  • public class HttpResponseParser
    extends ContentHeaderHandler
    Contains the httpResult and decodes the headers Content-Type and Content-Length for further information about that stream.
    • Constructor Detail

      • HttpResponseParser

        public HttpResponseParser​(java.net.http.HttpResponse<java.io.InputStream> httpResponse,
                                  HttpLogger httpLogger)
        Constructor. Creates this object with all its data from the incoming httpResponse.
        Parameters:
        httpResponse - The httpResponse to decode.
        httpLogger - The logger to log the response.
    • Method Detail

      • getStatusCode

        public int getStatusCode()
      • getRequest

        public java.net.http.HttpRequest getRequest()
      • getURI

        public java.net.URI getURI()
      • getSSLSession

        public java.util.Optional<javax.net.ssl.SSLSession> getSSLSession()
      • getHeaders

        public java.net.http.HttpHeaders getHeaders()
      • getInputStream

        public java.io.InputStream getInputStream()
        Access the inputStream and apply the logger
        Returns:
        The inputStream of the httpResponse.
      • consumeResponseAsString

        public java.lang.String consumeResponseAsString()
                                                 throws java.io.IOException
        Read the inputStream and return it as String in UTF-8 or the charset provided .
        Returns:
        The String constructed from the httpResponse or null if the httpResponse is null.
        Throws:
        java.io.IOException - If the httpResponse cannot be read.
      • createResponseObject

        public <T extends HiroMessage> T createResponseObject​(java.lang.Class<T> clazz)
                                                       throws java.io.IOException,
                                                              HiroException
        Convert the response into an object.
        Type Parameters:
        T - Type of the desired object.
        Parameters:
        clazz - Class of the desired object.
        Returns:
        The new object created from the JSON or null if no body is available.
        Throws:
        HiroException - When the incoming data is not of type "application/json".
        java.io.IOException - When the creation of the object fails.