Class HttpResponseParser
- java.lang.Object
-
- co.arago.hiro.client.util.httpclient.ContentHeaderHandler
-
- co.arago.hiro.client.util.httpclient.HttpResponseParser
-
public class HttpResponseParser extends ContentHeaderHandler
Contains the httpResult and decodes the headers Content-Type and Content-Length for further information about that stream.
-
-
Field Summary
-
Fields inherited from class co.arago.hiro.client.util.httpclient.ContentHeaderHandler
boundary, charset, contentLength, mediaType
-
-
Constructor Summary
Constructors Constructor Description HttpResponseParser(java.net.http.HttpResponse<java.io.InputStream> httpResponse, HttpLogger httpLogger)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringconsumeResponseAsString()Read the inputStream and return it as String in UTF-8 or the charset provided .<T extends HiroMessage>
TcreateResponseObject(java.lang.Class<T> clazz)Convert the response into an object.java.net.http.HttpHeadersgetHeaders()java.io.InputStreamgetInputStream()Access the inputStream and apply the loggerjava.net.http.HttpRequestgetRequest()java.util.Optional<javax.net.ssl.SSLSession>getSSLSession()intgetStatusCode()java.net.URIgetURI()-
Methods inherited from class co.arago.hiro.client.util.httpclient.ContentHeaderHandler
contentIsJson, getBoundary, getCharset, getContentLength, getContentType, getMediaType, hasContentType, setBoundary, setCharset, setContentLength, setContentType, setMediaType
-
-
-
-
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.IOExceptionRead the inputStream and return it as String in UTF-8 or the charset provided .- Returns:
- The String constructed from the
httpResponseor null if thehttpResponseis null. - Throws:
java.io.IOException- If thehttpResponsecannot 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.
-
-