Class KiwiResponses
These utilities are intended mainly to be used in classes that make HTTP requests and need to evaluate and/or take action with the HTTP responses.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaccept(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> responseConsumer) Given aResponse, perform some action using the supplied consumer.static voidaccept(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> responseConsumer, Consumer<RuntimeException> exceptionConsumer) Given aResponseSupplier, perform some action using one of the supplied consumers.static <T> TGiven aResponse, perform an action tha returns a result using the given function.static <T> Tapply(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> fun, Function<RuntimeException, T> exceptionFun) Given aResponseSupplier, perform an action tha returns a result using one of the given functions.static booleanclientError(jakarta.ws.rs.core.Response response) Check if the given response is in the CLIENT_ERROR (4xx codes) family.static voidcloseQuietly(jakarta.ws.rs.core.Response response) Closes the givenResponse, which can benull, swallowing any exceptions and logging them at INFO level.static booleancreated(jakarta.ws.rs.core.Response response) Check if the given response has status 201 Created.static booleanhasFamily(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.Response.Status.Family family) Check if the given response has the expected family.static booleanhasStatus(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.Response.Status status) Check if the given response has the expected status.static booleaninformational(jakarta.ws.rs.core.Response response) Check if the given response is in the INFORMATIONAL (1xx codes) family.static booleaninternalServerError(jakarta.ws.rs.core.Response response) Check if the given response has status 500 Internal Server Error.mediaType(jakarta.ws.rs.core.Response response) Return a media type suitable for use as the value of a corresponding HTTP header.static booleannotFound(jakarta.ws.rs.core.Response response) Check if the given response has status 404 Not Found.static booleannotSuccessful(int statusCode) Check if the given status code is not inResponse.Status.Family.SUCCESSFUL.static booleannotSuccessful(jakarta.ws.rs.core.Response response) Check if the given response has a status code that is not inResponse.Status.Family.SUCCESSFUL.static booleannotSuccessful(jakarta.ws.rs.core.Response.Status status) Check if the given status code is not inResponse.Status.Family.SUCCESSFUL.static booleannotSuccessful(jakarta.ws.rs.core.Response.Status.Family family) Check if the given response family is notResponse.Status.Family.SUCCESSFUL.static booleannotSuccessful(jakarta.ws.rs.core.Response.StatusType status) Check if the given status type is not inResponse.Status.Family.SUCCESSFUL.static booleannotSuccessfulAlwaysClosing(jakarta.ws.rs.core.Response response) Check if the given response has a status code that is not inResponse.Status.Family.SUCCESSFUL, then close the response.static booleanok(jakarta.ws.rs.core.Response response) Check if the given response has status 200 OK.static voidonFailure(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> failureConsumer) Given aResponse, perform an action only if it was not successful (failureConsumer).static voidonFailure(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> failureConsumer, Consumer<RuntimeException> exceptionConsumer) Given aResponseSupplier, perform an action only if it was not successful (failureConsumer), or if the Supplier threw an exception (exceptionConsumer).static voidonFailureThrow(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) static voidonFailureThrow(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponseSupplier, throw a (subclass of)RuntimeExceptionfor failed responses usingthrowingFun.static voidonSuccess(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> successConsumer) Given aResponse, perform an action only if it was successful (successConsumer.static voidonSuccess(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> successConsumer) Given aResponseSupplier, perform an action only if it was successful (successConsumer.static voidonSuccessOrFailure(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> successConsumer, Consumer<jakarta.ws.rs.core.Response> failureConsumer) Given aResponse, perform an action depending on whether it was successful (successConsumer) or failed (failureConsumer).static voidonSuccessOrFailure(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> successConsumer, Consumer<jakarta.ws.rs.core.Response> failureConsumer, Consumer<RuntimeException> exceptionConsumer) Given aResponseSupplier, perform an action depending on whether it was successful (successConsumer), failed (failureConsumer), or if the Supplier threw an exception (exceptionConsumer).static voidonSuccessOrFailureThrow(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> successConsumer, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponse, perform an action if it was successful (successConsumeror throw an exception supplied bythrowingFun.static voidonSuccessOrFailureThrow(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> successConsumer, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponseSupplier, perform an action if it was successful (successConsumer.static <T> TonSuccessOrFailureWithResult(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> successFun, Function<jakarta.ws.rs.core.Response, T> failedFun) Given aResponse, perform an action that returns a result if the response was successful (successFun) or if not successful (failedFun).static <T> TonSuccessOrFailureWithResult(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> successFun, Function<jakarta.ws.rs.core.Response, T> failedFun, Function<RuntimeException, T> exceptionFun) Given aResponseSupplier, perform an action that returns a result if the response was successful (successFun.static <T> Optional<T>onSuccessWithResult(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> successFun) Given aResponse, perform an action that returns a result only if it was successful (successFun).static <T> Optional<T>onSuccessWithResult(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> successFun) Given aResponseSupplier, perform an action that returns a result only if it was successful (successFun).static <T> Optional<T>onSuccessWithResultOrFailure(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> successFun, Consumer<jakarta.ws.rs.core.Response> failureConsumer) Given aResponse, perform an action that returns a result if the response was successful (successFun) or perform an action if the response was unsuccessful (failureConsumer.static <T> Optional<T>onSuccessWithResultOrFailure(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> successFun, Consumer<jakarta.ws.rs.core.Response> failureConsumer, Consumer<RuntimeException> exceptionConsumer) Given aResponseSupplier, perform an action that returns a result if the response was successful (successFun).static <T> TonSuccessWithResultOrFailureThrow(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> successFun, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponse, perform an action that returns a result if it was successful (successFunor throw a (subclass of)RuntimeExceptionif it failed (throwingFun).static <T> TonSuccessWithResultOrFailureThrow(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> successFun, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponseSupplier, perform an action that returns a result if it was successful (successFunor throw a (subclass of)RuntimeExceptionif it failed (throwingFun).static booleanotherFamily(jakarta.ws.rs.core.Response response) Check if the given response is in the OTHER (unrecognized status codes) family.static booleanredirection(jakarta.ws.rs.core.Response response) Check if the given response is in the REDIRECTION (3xx codes) family.static booleanserverError(jakarta.ws.rs.core.Response response) Check if the given response is in the SERVER_ERROR (5xx codes) family.static booleansuccessful(int statusCode) Check if the given status code is inResponse.Status.Family.SUCCESSFUL.static booleansuccessful(jakarta.ws.rs.core.Response response) Check if the given response has a status code inResponse.Status.Family.SUCCESSFUL.static booleansuccessful(jakarta.ws.rs.core.Response.Status status) Check if the given status code is inResponse.Status.Family.SUCCESSFUL.static booleansuccessful(jakarta.ws.rs.core.Response.Status.Family family) Check if the given response family isResponse.Status.Family.SUCCESSFUL.static booleansuccessful(jakarta.ws.rs.core.Response.StatusType status) Check if the given status type is inResponse.Status.Family.SUCCESSFUL.static booleansuccessfulAlwaysClosing(jakarta.ws.rs.core.Response response) Check if the given response has a status code inResponse.Status.Family.SUCCESSFUL, then close the response.
-
Method Details
-
mediaType
Return a media type suitable for use as the value of a corresponding HTTP header. This will consist of the primary type and subtype, e.g.application/json.- Parameters:
response- the response object- Returns:
- Optional that may or may not contain a media type
- See Also:
-
MediaType.toString()MediaType.getType()MediaType.getSubtype()
-
successful
public static boolean successful(jakarta.ws.rs.core.Response response) Check if the given response has a status code inResponse.Status.Family.SUCCESSFUL.NOTE: This does not close the
Responseor read the response entity.- Parameters:
response- the response object- Returns:
- true if the response is successful, false otherwise
- See Also:
-
Response.Status.Family.SUCCESSFUL
-
notSuccessful
public static boolean notSuccessful(jakarta.ws.rs.core.Response response) Check if the given response has a status code that is not inResponse.Status.Family.SUCCESSFUL.NOTE: This does not close the
Responseor read the response entity.- Parameters:
response- the response object- Returns:
- true if the response is not successful, false otherwise
-
successful
public static boolean successful(jakarta.ws.rs.core.Response.Status status) Check if the given status code is inResponse.Status.Family.SUCCESSFUL.- Parameters:
status- the response Status object- Returns:
- true if the status indicates success, false otherwise
-
notSuccessful
public static boolean notSuccessful(jakarta.ws.rs.core.Response.Status status) Check if the given status code is not inResponse.Status.Family.SUCCESSFUL.- Parameters:
status- the response Status object- Returns:
- true if the status does not indicate success, false otherwise
-
successful
public static boolean successful(jakarta.ws.rs.core.Response.StatusType status) Check if the given status type is inResponse.Status.Family.SUCCESSFUL.- Parameters:
status- the response StatusType object- Returns:
- true if the status indicates success, false otherwise
-
notSuccessful
public static boolean notSuccessful(jakarta.ws.rs.core.Response.StatusType status) Check if the given status type is not inResponse.Status.Family.SUCCESSFUL.- Parameters:
status- the response StatusType object- Returns:
- true if the status does not indicate success, false otherwise
-
successful
public static boolean successful(int statusCode) Check if the given status code is inResponse.Status.Family.SUCCESSFUL.- Parameters:
statusCode- the response status code- Returns:
- true if the status code indicates success, false otherwise
-
notSuccessful
public static boolean notSuccessful(int statusCode) Check if the given status code is not inResponse.Status.Family.SUCCESSFUL.- Parameters:
statusCode- the response status code- Returns:
- true if the status code doe not indicate success, false otherwise
-
successful
public static boolean successful(jakarta.ws.rs.core.Response.Status.Family family) Check if the given response family isResponse.Status.Family.SUCCESSFUL.- Parameters:
family- the response family- Returns:
- true if the family is successful, false otherwise
-
notSuccessful
public static boolean notSuccessful(jakarta.ws.rs.core.Response.Status.Family family) Check if the given response family is notResponse.Status.Family.SUCCESSFUL.- Parameters:
family- the response family- Returns:
- true if the family is not successful, false otherwise
-
successfulAlwaysClosing
public static boolean successfulAlwaysClosing(jakarta.ws.rs.core.Response response) Check if the given response has a status code inResponse.Status.Family.SUCCESSFUL, then close the response.NOTE: Closes the response after performing the check.
- Parameters:
response- the response object- Returns:
- true if the response is successful, false otherwise
-
notSuccessfulAlwaysClosing
public static boolean notSuccessfulAlwaysClosing(jakarta.ws.rs.core.Response response) Check if the given response has a status code that is not inResponse.Status.Family.SUCCESSFUL, then close the response.NOTE: Closes the response after performing the check.
- Parameters:
response- the response object- Returns:
- true if the response is not successful, false otherwise
-
ok
public static boolean ok(jakarta.ws.rs.core.Response response) Check if the given response has status 200 OK.- Parameters:
response- the response object- Returns:
- true if the response status is 200 OK, false otherwise
-
created
public static boolean created(jakarta.ws.rs.core.Response response) Check if the given response has status 201 Created.- Parameters:
response- the response object- Returns:
- true if the response status is 201 Created, false otherwise
-
notFound
public static boolean notFound(jakarta.ws.rs.core.Response response) Check if the given response has status 404 Not Found.- Parameters:
response- the response object- Returns:
- true if the response status is 404 Not Found, false otherwise
-
internalServerError
public static boolean internalServerError(jakarta.ws.rs.core.Response response) Check if the given response has status 500 Internal Server Error.- Parameters:
response- the response object- Returns:
- true if the response status is 500 Internal Server Error, false otherwise
-
hasStatus
public static boolean hasStatus(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.Response.Status status) Check if the given response has the expected status.- Parameters:
response- the response objectstatus- the expected status- Returns:
- true if the response has the given status, false otherwise
-
informational
public static boolean informational(jakarta.ws.rs.core.Response response) Check if the given response is in the INFORMATIONAL (1xx codes) family.- Parameters:
response- the response object- Returns:
- true if the response is in the INFORMATIONAL family, false otherwise
- See Also:
-
Response.Status.Family.INFORMATIONAL
-
redirection
public static boolean redirection(jakarta.ws.rs.core.Response response) Check if the given response is in the REDIRECTION (3xx codes) family.- Parameters:
response- the response object- Returns:
- true if the response is in the REDIRECTION family, false otherwise
- See Also:
-
Response.Status.Family.REDIRECTION
-
clientError
public static boolean clientError(jakarta.ws.rs.core.Response response) Check if the given response is in the CLIENT_ERROR (4xx codes) family.- Parameters:
response- the response object- Returns:
- true if the response is in the CLIENT_ERROR family, false otherwise
- See Also:
-
Response.Status.Family.CLIENT_ERROR
-
serverError
public static boolean serverError(jakarta.ws.rs.core.Response response) Check if the given response is in the SERVER_ERROR (5xx codes) family.- Parameters:
response- the response object- Returns:
- true if the response is in the SERVER_ERROR family, false otherwise
- See Also:
-
Response.Status.Family.SERVER_ERROR
-
otherFamily
public static boolean otherFamily(jakarta.ws.rs.core.Response response) Check if the given response is in the OTHER (unrecognized status codes) family.- Parameters:
response- the response object- Returns:
- true if the response is in the OTHER family, false otherwise
- See Also:
-
Response.Status.Family.OTHER
-
hasFamily
public static boolean hasFamily(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.Response.Status.Family family) Check if the given response has the expected family.- Parameters:
response- the response objectfamily- the expected family- Returns:
- true if the response has the given status, false otherwise
-
onSuccessOrFailure
public static void onSuccessOrFailure(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> successConsumer, Consumer<jakarta.ws.rs.core.Response> failureConsumer, Consumer<RuntimeException> exceptionConsumer) Given aResponseSupplier, perform an action depending on whether it was successful (successConsumer), failed (failureConsumer), or if the Supplier threw an exception (exceptionConsumer).Ensures the response is closed after performing the action.
- Parameters:
responseSupplier- a Supplier that provides the responsesuccessConsumer- the action to run if the response is successfulfailureConsumer- the action to run if the response is not successfulexceptionConsumer- the action to run if the Supplier throws an exception
-
onSuccessOrFailure
public static void onSuccessOrFailure(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> successConsumer, Consumer<jakarta.ws.rs.core.Response> failureConsumer) Given aResponse, perform an action depending on whether it was successful (successConsumer) or failed (failureConsumer).Ensures the response is closed after performing the action.
- Parameters:
response- the response objectsuccessConsumer- the action to run if the response is successfulfailureConsumer- the action to run if the response is not successful
-
onSuccessOrFailureThrow
public static void onSuccessOrFailureThrow(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> successConsumer, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponseSupplier, perform an action if it was successful (successConsumer. If the response was unsuccessful, throw the exception supplied bythrowingFun. If the Supplier throws an exception, then that exception is rethrown.Ensures the response is closed after performing the action.
- Parameters:
responseSupplier- a Supplier that provides the responsesuccessConsumer- the action to run if the response is successfulthrowingFun- a function that creates an appropriate (subclass of) RuntimeException- Throws:
RuntimeException- the result ofthrowingFun, or the exception thrown by the Supplier
-
onSuccessOrFailureThrow
public static void onSuccessOrFailureThrow(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> successConsumer, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponse, perform an action if it was successful (successConsumeror throw an exception supplied bythrowingFun.Ensures the response is closed after performing the action.
- Parameters:
response- the response objectsuccessConsumer- the action to run if the response is successfulthrowingFun- a function that creates an appropriate (subclass of) RuntimeException- Throws:
RuntimeException- the result ofthrowingFun
-
onSuccess
public static void onSuccess(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> successConsumer) Given aResponseSupplier, perform an action only if it was successful (successConsumer.No action is performed for an unsuccessful response, and exceptions thrown by the Supplier are ignored.
Ensures the response is closed after performing the action.
- Parameters:
responseSupplier- a Supplier that provides the responsesuccessConsumer- the action to run if the response is successful
-
onSuccess
public static void onSuccess(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> successConsumer) Given aResponse, perform an action only if it was successful (successConsumer.No action is performed for an unsuccessful response.
Ensures the response is closed after performing the action.
- Parameters:
response- the response objectsuccessConsumer- the action to run if the response is successful
-
onSuccessWithResult
public static <T> Optional<T> onSuccessWithResult(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> successFun) Given aResponseSupplier, perform an action that returns a result only if it was successful (successFun).No action is performed for an unsuccessful response, and exceptions thrown by the Supplier are ignored.
Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
responseSupplier- a Supplier that provides the responsesuccessFun- the function to apply if the response is successful- Returns:
- an Optional containing a result for successful responses, or an empty Optional
-
onSuccessWithResult
public static <T> Optional<T> onSuccessWithResult(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> successFun) Given aResponse, perform an action that returns a result only if it was successful (successFun).No action is performed for an unsuccessful response.
Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
response- the response objectsuccessFun- the function to apply if the response is successful- Returns:
- an Optional containing a result for successful responses, or an empty Optional
-
onFailure
public static void onFailure(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> failureConsumer, Consumer<RuntimeException> exceptionConsumer) Given aResponseSupplier, perform an action only if it was not successful (failureConsumer), or if the Supplier threw an exception (exceptionConsumer).No action is performed for a successful response.
Ensures the response is closed after performing the action.
- Parameters:
responseSupplier- a Supplier that provides the responsefailureConsumer- the action to run if the response is not successfulexceptionConsumer- the action to run if the Supplier throws an exception
-
onFailure
public static void onFailure(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> failureConsumer) Given aResponse, perform an action only if it was not successful (failureConsumer).No action is performed for a successful response.
Ensures the response is closed after performing the action.
- Parameters:
response- the response objectfailureConsumer- the action to run if the response is not successful
-
onFailureThrow
public static void onFailureThrow(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponseSupplier, throw a (subclass of)RuntimeExceptionfor failed responses usingthrowingFun. If the Supplier throws an exception, that exception is rethrown.No action is performed for a successful response.
Ensures the response is closed after performing the action.
- Parameters:
responseSupplier- a Supplier that provides the responsethrowingFun- function that creates an appropriate (subclass of) RuntimeException- Throws:
RuntimeException- the result ofthrowingFun, or the exception thrown by the Supplier
-
onFailureThrow
public static void onFailureThrow(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponse, throw a (subclass of)RuntimeExceptionfor failed responses usingthrowingFun.No action is performed for a successful response.
Ensures the response is closed after performing the action.
- Parameters:
response- the response objectthrowingFun- a function that creates an appropriate (subclass of) RuntimeException- Throws:
RuntimeException- the result ofthrowingFun
-
onSuccessWithResultOrFailure
public static <T> Optional<T> onSuccessWithResultOrFailure(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> successFun, Consumer<jakarta.ws.rs.core.Response> failureConsumer, Consumer<RuntimeException> exceptionConsumer) Given aResponseSupplier, perform an action that returns a result if the response was successful (successFun). Perform an action if the response was unsuccessful (failureConsumer, or if the Supplier threw an exception (exceptionConsumer).Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
responseSupplier- a Supplier that provides the responsesuccessFun- the function to apply if the response is successfulfailureConsumer- the action to run if the response is not successfulexceptionConsumer- the action to run if the Supplier throws an exception- Returns:
- the result from
successFunfor successful responses, or an empty Optional for unsuccessful responses or if the Supplier throws an exception
-
onSuccessWithResultOrFailure
public static <T> Optional<T> onSuccessWithResultOrFailure(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> successFun, Consumer<jakarta.ws.rs.core.Response> failureConsumer) Given aResponse, perform an action that returns a result if the response was successful (successFun) or perform an action if the response was unsuccessful (failureConsumer.Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
response- the response objectsuccessFun- the function to apply if the response is successfulfailureConsumer- the action to run if the response is not successful- Returns:
- the result from
successFunfor successful responses, or an empty Optional for unsuccessful ones
-
onSuccessOrFailureWithResult
public static <T> T onSuccessOrFailureWithResult(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> successFun, Function<jakarta.ws.rs.core.Response, T> failedFun, Function<RuntimeException, T> exceptionFun) Given aResponseSupplier, perform an action that returns a result if the response was successful (successFun. If the response was not successful return the result of a function (failedFun). If the Supplier threw an exception, return the result of a different function (exceptionFun).Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
responseSupplier- a Supplier that provides the responsesuccessFun- the function to apply if the response is successfulfailedFun- the function to apply if the response is not successfulexceptionFun- the function to apply if the Supplier throws an exception- Returns:
- the result from applying
successFun,failedFun, orexceptionFun
-
onSuccessOrFailureWithResult
public static <T> T onSuccessOrFailureWithResult(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> successFun, Function<jakarta.ws.rs.core.Response, T> failedFun) Given aResponse, perform an action that returns a result if the response was successful (successFun) or if not successful (failedFun).Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
response- the response objectsuccessFun- the function to apply if the response is successfulfailedFun- the function to apply if the response is not successful- Returns:
- the result from applying either
successFunorfailedFun
-
onSuccessWithResultOrFailureThrow
public static <T> T onSuccessWithResultOrFailureThrow(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> successFun, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponseSupplier, perform an action that returns a result if it was successful (successFunor throw a (subclass of)RuntimeExceptionif it failed (throwingFun). If the Supplier threw an exception, then that exception is rethrown.Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
responseSupplier- a Supplier that provides the responsesuccessFun- the function to apply if the response is successfulthrowingFun- a function that creates an appropriate (subclass of) RuntimeException- Returns:
- the result from applying
successFun - Throws:
RuntimeException- the result ofthrowingFunor the exception thrown by the Supplier
-
onSuccessWithResultOrFailureThrow
public static <T> T onSuccessWithResultOrFailureThrow(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> successFun, Function<jakarta.ws.rs.core.Response, ? extends RuntimeException> throwingFun) Given aResponse, perform an action that returns a result if it was successful (successFunor throw a (subclass of)RuntimeExceptionif it failed (throwingFun).Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
response- the response objectsuccessFun- the function to apply if the response is successfulthrowingFun- a function that creates an appropriate (subclass of) RuntimeException- Returns:
- the result from applying
successFun - Throws:
RuntimeException- the result ofthrowingFun
-
accept
public static void accept(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Consumer<jakarta.ws.rs.core.Response> responseConsumer, Consumer<RuntimeException> exceptionConsumer) Given aResponseSupplier, perform some action using one of the supplied consumers.Ensures the response is closed after performing the action.
- Parameters:
responseSupplier- a Supplier that provides the responseresponseConsumer- the action to run on any responseexceptionConsumer- the action to run if the Supplier throws an exception
-
accept
public static void accept(jakarta.ws.rs.core.Response response, Consumer<jakarta.ws.rs.core.Response> responseConsumer) Given aResponse, perform some action using the supplied consumer.Ensures the response is closed after performing the action.
- Parameters:
response- the response objectresponseConsumer- the action to run
-
apply
public static <T> T apply(Supplier<jakarta.ws.rs.core.Response> responseSupplier, Function<jakarta.ws.rs.core.Response, T> fun, Function<RuntimeException, T> exceptionFun) Given aResponseSupplier, perform an action tha returns a result using one of the given functions.Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
responseSupplier- a Supplier that provides the responsefun- the function to apply to the responseexceptionFun- the function to apply if the Supplier throws an exception- Returns:
- the result of applying the given function
-
apply
public static <T> T apply(jakarta.ws.rs.core.Response response, Function<jakarta.ws.rs.core.Response, T> fun) Given aResponse, perform an action tha returns a result using the given function.Ensures the response is closed after performing the action.
- Type Parameters:
T- the result type- Parameters:
response- the response objectfun- the function to apply to the response- Returns:
- the result of applying the given function
-
closeQuietly
public static void closeQuietly(jakarta.ws.rs.core.Response response) Closes the givenResponse, which can benull, swallowing any exceptions and logging them at INFO level.- Parameters:
response- the response object
-