NIFI-6928 - add connect/read timeout to RestLookupService

This closes #3920

Signed-off-by: Mike Thomsen <mthomsen@apache.org>
This commit is contained in:
Pierre Villard 2019-12-06 06:45:32 +01:00 committed by Mike Thomsen
parent 5f0f801e46
commit ad636789f0
No known key found for this signature in database
GPG Key ID: 88511C3D4CAD246F
1 changed files with 28 additions and 1 deletions

View File

@ -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);
}