T - Type of converted content from responsepublic interface ResponseHandler<T>
The instance which contains converted response content and provide a lot of methods to manipulation and checking.
| Modifier and Type | Method and Description |
|---|---|
FilterSupport<T> |
filter(Predicate<ResponseHandler<T>> predicate) |
T |
get()
Strongly recommend call get method after check content is present.
|
org.apache.http.entity.ContentType |
getContentType() |
String |
getErrorText() |
<X extends Throwable> |
getOrThrow(Supplier<X> exceptionSupplier) |
<X extends Throwable> |
getOrThrow(T defaultValue,
Supplier<X> exceptionSupplier) |
int |
getStatusCode() |
org.apache.http.StatusLine |
getStatusLine()
Obtains the status line of this response.
|
URI |
getURI() |
boolean |
hasContent() |
default boolean |
hasNotContent() |
void |
ifHasContent(Consumer<? super T> consumer)
If has a content, invoke the specified consumer with the content, otherwise do nothing.
|
void |
ifNotSuccess(Consumer<ResponseHandler<T>> consumer)
If status code is not success , invoke the specified consumer with the responseHandler.
|
OtherwiseSupport<T> |
ifSuccess(Consumer<ResponseHandler<T>> consumer)
If status code is success , invoke the specified consumer with the responseHandler and returns
OtherwiseSupport with ignore else OtherwiseSupport with not ignore. |
default boolean |
isNonSuccess() |
boolean |
isSuccess() |
T |
orElse(T defaultValue) |
T |
orElseThrow() |
T |
orElseThrow(T defaultValue) |
<X extends Throwable> |
orThrow(Function<ResponseHandler<? super T>,X> exceptionFunction) |
<X extends Throwable> |
orThrow(T defaultValue,
Function<ResponseHandler<? super T>,X> exceptionFunction) |
boolean hasContent()
true If content is present else falsedefault boolean hasNotContent()
true If hasn't content else falseint getStatusCode()
T orElse(T defaultValue)
defaultValue - value to return if content isn't presentUnsupportedOperationException - if generic type is a VoidT orElseThrow(T defaultValue)
defaultValue - value to return if status code is success and hasn't bodyUnexpectedStatusCodeException - If status code is not successUnsupportedOperationException - if generic type is a Void<X extends Throwable> T orThrow(Function<ResponseHandler<? super T>,X> exceptionFunction) throws X extends Throwable
X - Type of the exception to be thrownexceptionFunction - Instance of type Function by parameter this which returns exception to throw if status code isn't success.null.X - If status code isn't success.X extends Throwable<X extends Throwable> T orThrow(T defaultValue, Function<ResponseHandler<? super T>,X> exceptionFunction) throws X extends Throwable
X - Type of the exception to be throwndefaultValue - Value to return if content is nullexceptionFunction - Instance of type Function by parameter this which returns exception to throw if status code isn't success.defaultValue.X - If status code isn't success.X extends Throwable<X extends Throwable> T getOrThrow(Supplier<X> exceptionSupplier) throws X extends Throwable
X - Type of the exception to be thrownexceptionSupplier - Instance of type Supplier which returns exception to throw if status code isn't success.null.X - If status code isn't success.X extends Throwable<X extends Throwable> T getOrThrow(T defaultValue, Supplier<X> exceptionSupplier) throws X extends Throwable
X - Type of the exception to be throwndefaultValue - Value to return if content is nullexceptionSupplier - Instance of type Supplier which returns exception to throw if status code isn't success.defaultValue.X - If status code isn't success.X extends ThrowableT orElseThrow()
UnexpectedStatusCodeException - If response code is not successUnsupportedOperationException - if generic type is a VoidT get()
if(responseHandler.hasContent()){
responseHandler.get()
}
NoSuchContentException - If content is not presentUnsupportedOperationException - if generic type is a VoidorElse(Object),
ifHasContent(Consumer)String getErrorText()
NoSuchElementException - If error text is not presentUnsupportedOperationException - if generic type is a VoidURI getURI()
org.apache.http.StatusLine getStatusLine()
org.apache.http.entity.ContentType getContentType()
boolean isSuccess()
default boolean isNonSuccess()
void ifHasContent(Consumer<? super T> consumer)
consumer - block to be executed if has a contentIllegalArgumentException - if consumer is nullOtherwiseSupport<T> ifSuccess(Consumer<ResponseHandler<T>> consumer)
OtherwiseSupport with ignore else OtherwiseSupport with not ignore.consumer - block to be executed if status code is success.OtherwiseSupport.otherwise(Consumer)void ifNotSuccess(Consumer<ResponseHandler<T>> consumer)
consumer - block to be executed if status code is not success.FilterSupport<T> filter(Predicate<ResponseHandler<T>> predicate)
Copyright © 2021. All rights reserved.