Package sonia.scm.net.ahc
Class AdvancedHttpResponse
java.lang.Object
sonia.scm.net.ahc.AdvancedHttpResponse
Http response. The response of a
AdvancedHttpRequest
or
AdvancedHttpRequestWithBody
.- Since:
- 1.46
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
content()
Returns the content of the response as byte array.abstract com.google.common.io.ByteSource
Returns the response content as byte source.Returns a reader for the content of the response.Returns response content as stream.Returns the response content as string.<T> T
contentFromJson
(Class<T> type) Transforms the response content from json to the given type.<T> T
contentFromXml
(Class<T> type) Transforms the response content from xml to the given type.<T> T
contentTransformed
(Class<T> type) Transforms the response content to the given type.<T> T
contentTransformed
(Class<T> type, String contentType) Transforms the response content to the given type.protected abstract ContentTransformer
createTransformer
(Class<?> type, String contentType) Creates aContentTransformer
for the given Content-Type.getFirstHeader
(String name) Returns the first header value for the given header name ornull
.Returns the response headers.abstract int
Returns the status code of the response.abstract String
Returns the status text of the response.boolean
Returnstrue
if the response was successful.
-
Constructor Details
-
AdvancedHttpResponse
public AdvancedHttpResponse()
-
-
Method Details
-
contentAsByteSource
Returns the response content as byte source.- Throws:
IOException
-
getHeaders
Returns the response headers. -
getStatus
public abstract int getStatus()Returns the status code of the response. -
getStatusText
Returns the status text of the response. -
createTransformer
Creates aContentTransformer
for the given Content-Type.- Parameters:
type
- object typecontentType
- content-type- Returns:
ContentTransformer
- Throws:
ContentTransformerNotFoundException
- if noContentTransformer
could be found for the content-type
-
content
Returns the content of the response as byte array.- Throws:
IOException
-
contentAsReader
Returns a reader for the content of the response.- Throws:
IOException
-
contentAsStream
Returns response content as stream.- Throws:
IOException
-
contentAsString
Returns the response content as string.- Throws:
IOException
-
contentFromJson
Transforms the response content from json to the given type.- Type Parameters:
T
- object type- Parameters:
type
- object type- Returns:
- transformed object
- Throws:
ContentTransformerNotFoundException
- if noContentTransformer
could be found for the json content-typeIOException
-
contentFromXml
Transforms the response content from xml to the given type.- Type Parameters:
T
- object type- Parameters:
type
- object type- Returns:
- transformed object
- Throws:
ContentTransformerNotFoundException
- if noContentTransformer
could be found for the xml content-typeIOException
-
contentTransformed
Transforms the response content to the given type. The method uses the content-type header to pick the rightContentTransformer
.- Type Parameters:
T
- object type- Parameters:
type
- object type- Returns:
- transformed object
- Throws:
ContentTransformerNotFoundException
- if noContentTransformer
could be found for the content-typeIOException
-
contentTransformed
Transforms the response content to the given type. The method will use theContentTransformer
which is responsible for the given content type.- Type Parameters:
T
- object type- Parameters:
type
- object typecontentType
- type to pickContentTransformer
- Returns:
- transformed object
- Throws:
ContentTransformerNotFoundException
- if noContentTransformer
could be found for the content-typeIOException
-
getFirstHeader
Returns the first header value for the given header name ornull
. -
isSuccessful
public boolean isSuccessful()Returnstrue
if the response was successful. A response is successful, if the status code is greater than 199 and lower than 400.
-