aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2020-11-19 16:47:21 +0000
committerGerrit Code Review <gerrit@onap.org>2020-11-19 16:47:21 +0000
commit2cff4050e89571db0b974acede942517dd415015 (patch)
tree59a00719362ad6df0301b86eadc26b6e84fe87f4 /common/src/main/java/org
parentd37ee99ec74546371eee71b9f002390aa2cafb68 (diff)
parentc183d2d73b46a51a028bd65c742ee46df5e7d547 (diff)
Merge "added configurable read timeout value for A&AI"
Diffstat (limited to 'common/src/main/java/org')
-rw-r--r--common/src/main/java/org/onap/so/client/RestClient.java8
-rw-r--r--common/src/main/java/org/onap/so/client/RestClientSSL.java4
-rw-r--r--common/src/main/java/org/onap/so/client/RestProperties.java9
3 files changed, 18 insertions, 3 deletions
diff --git a/common/src/main/java/org/onap/so/client/RestClient.java b/common/src/main/java/org/onap/so/client/RestClient.java
index ece1333f83..9fce328b1d 100644
--- a/common/src/main/java/org/onap/so/client/RestClient.java
+++ b/common/src/main/java/org/onap/so/client/RestClient.java
@@ -34,10 +34,12 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.ResponseProcessingException;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
@@ -187,7 +189,7 @@ public abstract class RestClient {
}
protected Client getClient() {
- return ClientBuilder.newBuilder().build();
+ return ClientBuilder.newBuilder().readTimeout(props.getReadTimeout(), TimeUnit.MILLISECONDS).build();
}
protected abstract ONAPComponentsList getTargetEntity();
@@ -201,7 +203,6 @@ public abstract class RestClient {
metricLogClientFilter = new SOMetricLogClientFilter();
mdcSetup.setTargetEntity(getTargetEntity());
client.register(metricLogClientFilter);
-
if (!path.isPresent()) {
webTarget = client.target(host.toString());
} else {
@@ -225,6 +226,9 @@ public abstract class RestClient {
result.add(e -> {
return e.getCause() instanceof ConnectException;
});
+ result.add(e -> {
+ return e.getCause() instanceof ResponseProcessingException;
+ });
return result;
}
diff --git a/common/src/main/java/org/onap/so/client/RestClientSSL.java b/common/src/main/java/org/onap/so/client/RestClientSSL.java
index 1e8953892e..8956e20a5a 100644
--- a/common/src/main/java/org/onap/so/client/RestClientSSL.java
+++ b/common/src/main/java/org/onap/so/client/RestClientSSL.java
@@ -24,6 +24,7 @@ import java.net.URI;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
+import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
@@ -56,7 +57,8 @@ public abstract class RestClientSSL extends RestClient {
}
}
// Use default SSL context
- client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault()).build();
+ client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault())
+ .readTimeout(props.getReadTimeout(), TimeUnit.MILLISECONDS).build();
logger.info("RestClientSSL using default SSL context!");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
diff --git a/common/src/main/java/org/onap/so/client/RestProperties.java b/common/src/main/java/org/onap/so/client/RestProperties.java
index 9e4e99cb4e..36da424f93 100644
--- a/common/src/main/java/org/onap/so/client/RestProperties.java
+++ b/common/src/main/java/org/onap/so/client/RestProperties.java
@@ -40,4 +40,13 @@ public interface RestProperties {
public default boolean mapNotFoundToEmpty() {
return false;
}
+
+ /**
+ * Time in milliseconds
+ *
+ * @return
+ */
+ public default Long getReadTimeout() {
+ return Long.valueOf(60000);
+ }
}