Package de.xima.fc.http.result
Class HttpResponseWrapper
- java.lang.Object
-
- de.xima.fc.http.result.HttpResponseWrapper
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class HttpResponseWrapper extends Object implements Closeable
Wrapper for aCloseableHttpResponse
which provides a couple of convenient methods for the work with the response- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Constructor Summary
Constructors Constructor Description HttpResponseWrapper(@NotNull org.apache.http.client.methods.CloseableHttpResponse originResponse, Charset outputCharset)
The one and only constructor for this wrapper!
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
String
getContent()
String
getContentType()
String
getEncoding()
String
getLastHeaderValue(String headerName)
org.apache.http.client.methods.CloseableHttpResponse
getOriginResponse()
String
getReasonPhrase()
int
getResponseCode()
String
getResponseMessage()
boolean
isRedirect()
void
updateContent(String content, org.apache.http.entity.ContentType contentType)
Updates the content of the underlying response.
-
-
-
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
- theCloseableHttpResponse
that should be wrappedoutputCharset
- to used charset for response content. Ifnull
, 'UTF-8' is used as default.
-
-
Method Detail
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
isRedirect
public boolean isRedirect()
- Returns:
true
if an HTTP status code is 3xx otherwisefalse
-
getLastHeaderValue
public String getLastHeaderValue(String headerName)
- Parameters:
headerName
- Name of the header- Returns:
- the value of the last response header if it was provided otherwise empty string
-
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 responseIOException
- 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 updatecontentType
- 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
-
-