From 62f1c059b6e9ab834f0ef1a51be1f6e15e0acb3b Mon Sep 17 00:00:00 2001 From: Lubos Racansky Date: Tue, 11 Jun 2024 09:02:00 +0200 Subject: [PATCH] Fix #845: Missing timeout options for REST client --- .../getlime/push/client/PushServerClient.java | 19 +++++++++++++++++- .../client/PushServerClientException.java | 20 ++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/powerauth-push-client/src/main/java/io/getlime/push/client/PushServerClient.java b/powerauth-push-client/src/main/java/io/getlime/push/client/PushServerClient.java index 4d9966c3e..bd99bdccb 100644 --- a/powerauth-push-client/src/main/java/io/getlime/push/client/PushServerClient.java +++ b/powerauth-push-client/src/main/java/io/getlime/push/client/PushServerClient.java @@ -16,8 +16,10 @@ package io.getlime.push.client; +import com.fasterxml.jackson.databind.Module; import com.wultra.core.rest.client.base.DefaultRestClient; import com.wultra.core.rest.client.base.RestClient; +import com.wultra.core.rest.client.base.RestClientConfiguration; import com.wultra.core.rest.client.base.RestClientException; import io.getlime.core.rest.model.base.entity.Error; import io.getlime.core.rest.model.base.request.ObjectRequest; @@ -64,7 +66,22 @@ public PushServerClient(String serviceBaseUrl) throws PushServerClientException try { this.restClient = DefaultRestClient.builder().baseUrl(serviceBaseUrl).build(); } catch (RestClientException ex) { - throw new PushServerClientException("Rest client initialization failed, error: " + ex.getMessage()); + throw new PushServerClientException("Rest client initialization failed, error: " + ex.getMessage(), ex); + } + } + + /** + * Construct the push server client with the given configuration. + * + * @param config REST client configuration. + * @param modules Optional jackson modules. + * @throws PushServerClientException Thrown in case REST client initialization fails. + */ + public PushServerClient(final RestClientConfiguration config, final Module... modules) throws PushServerClientException { + try { + this.restClient = new DefaultRestClient(config, modules); + } catch (RestClientException ex) { + throw new PushServerClientException("Rest client initialization failed, error: " + ex.getMessage(), ex); } } diff --git a/powerauth-push-client/src/main/java/io/getlime/push/client/PushServerClientException.java b/powerauth-push-client/src/main/java/io/getlime/push/client/PushServerClientException.java index 9bdba1d3c..f623e56c3 100644 --- a/powerauth-push-client/src/main/java/io/getlime/push/client/PushServerClientException.java +++ b/powerauth-push-client/src/main/java/io/getlime/push/client/PushServerClientException.java @@ -30,7 +30,7 @@ public class PushServerClientException extends Exception { /** * Error object. */ - private Error error; + private final Error error; /** * Constructor with message. @@ -71,6 +71,16 @@ public PushServerClientException(String message, Throwable cause, Error error) { this.error = error; } + /** + * Constructor with message, cause and error object. + * @param message Message. + * @param cause Cause. + */ + public PushServerClientException(String message, Throwable cause) { + super(message, cause); + this.error = new PushServerClientError(message); + } + /** * Constructor with cause and error object. * @param cause Cause. @@ -95,14 +105,6 @@ public PushServerClientException(String message, Throwable cause, boolean enable this.error = error; } - /** - * Set error object. - * @param error Error object. - */ - public void setError(Error error) { - this.error = error; - } - /** * Get error object. * @return Error object.