add connect/read timeout to RestLookupService
This closes
@@ -71,6 +71,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -120,6 +121,7 @@ public class RestLookupService extends AbstractControllerService implements Reco
.required(false)
.identifiesControllerService(SSLContextService.class)
.build();
+
public static final PropertyDescriptor PROP_BASIC_AUTH_USERNAME = new PropertyDescriptor.Builder()
.name("rest-lookup-basic-auth-username")
.displayName("Basic Authentication Username")
@@ -138,6 +140,7 @@ public class RestLookupService extends AbstractControllerService implements Reco
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
.addValidator(StandardValidators.createRegexMatchingValidator(Pattern.compile("^[\\x20-\\x7e\\x80-\\xff]+$")))
.build();
+
public static final PropertyDescriptor PROP_DIGEST_AUTH = new PropertyDescriptor.Builder()
.name("rest-lookup-digest-auth")
.displayName("Use Digest Authentication")
@@ -148,6 +151,24 @@ public class RestLookupService extends AbstractControllerService implements Reco
.allowableValues("true", "false")
.build();
+ public static final PropertyDescriptor PROP_CONNECT_TIMEOUT = new PropertyDescriptor.Builder()
+ .name("rest-lookup-connection-timeout")
+ .displayName("Connection Timeout")
+ .description("Max wait time for connection to remote service.")
+ .required(true)
+ .defaultValue("5 secs")
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor PROP_READ_TIMEOUT = new PropertyDescriptor.Builder()
+ .name("rest-lookup-read-timeout")
+ .displayName("Read Timeout")
+ .description("Max wait time for response from remote service.")
+ .required(true)
+ .defaultValue("15 secs")
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH, ProxySpec.SOCKS};
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE
= ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);
@@ -170,7 +191,9 @@ public class RestLookupService extends AbstractControllerService implements Reco
PROXY_CONFIGURATION_SERVICE,
PROP_BASIC_AUTH_USERNAME,
PROP_BASIC_AUTH_PASSWORD,
- PROP_DIGEST_AUTH
+ PROP_DIGEST_AUTH,
+ PROP_CONNECT_TIMEOUT,
+ PROP_READ_TIMEOUT
));
KEYS = Collections.emptySet();
}
@@ -199,6 +222,10 @@ public class RestLookupService extends AbstractControllerService implements Reco
setAuthenticator(builder, context);
+ // Set timeouts
+ builder.connectTimeout((context.getProperty(PROP_CONNECT_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()), TimeUnit.MILLISECONDS);
+ builder.readTimeout(context.getProperty(PROP_READ_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue(), TimeUnit.MILLISECONDS);
+
if (proxyConfigurationService != null) {
setProxy(builder);
}
