NIFI-7393: Add max idle time and idle connections to InvokeHTTP

This closes #4233.

Signed-off-by: Joey Frazee <jfrazee@apache.org>
This commit is contained in:
Wouter de Vries 2020-04-24 11:26:20 +02:00 committed by Joey Frazee
parent 845b66ab92
commit f2368a0dd1
1 changed files with 29 additions and 0 deletions

View File

@ -57,6 +57,7 @@ import javax.annotation.Nullable;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import okhttp3.Cache;
import okhttp3.ConnectionPool;
import okhttp3.Credentials;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
@ -202,6 +203,24 @@ public class InvokeHTTP extends AbstractProcessor {
.addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
.build();
public static final PropertyDescriptor PROP_IDLE_TIMEOUT = new PropertyDescriptor.Builder()
.name("idle-timeout")
.displayName("Idle Timeout")
.description("Max idle time before closing connection to the remote service.")
.required(true)
.defaultValue("5 mins")
.addValidator(StandardValidators.createTimePeriodValidator(1, TimeUnit.MILLISECONDS, Integer.MAX_VALUE, TimeUnit.SECONDS))
.build();
public static final PropertyDescriptor PROP_MAX_IDLE_CONNECTIONS = new PropertyDescriptor.Builder()
.name("max-idle-connections")
.displayName("Max Idle Connections")
.description("Max number of idle connections to keep open.")
.required(true)
.defaultValue("5")
.addValidator(StandardValidators.INTEGER_VALIDATOR)
.build();
public static final PropertyDescriptor PROP_DATE_HEADER = new PropertyDescriptor.Builder()
.name("Include Date Header")
.description("Include an RFC-2616 Date header in the request.")
@ -466,6 +485,8 @@ public class InvokeHTTP extends AbstractProcessor {
PROP_SSL_CONTEXT_SERVICE,
PROP_CONNECT_TIMEOUT,
PROP_READ_TIMEOUT,
PROP_IDLE_TIMEOUT,
PROP_MAX_IDLE_CONNECTIONS,
PROP_DATE_HEADER,
PROP_FOLLOW_REDIRECTS,
PROP_ATTRIBUTES_TO_SEND,
@ -727,6 +748,14 @@ public class InvokeHTTP extends AbstractProcessor {
okHttpClientBuilder.connectTimeout((context.getProperty(PROP_CONNECT_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()), TimeUnit.MILLISECONDS);
okHttpClientBuilder.readTimeout(context.getProperty(PROP_READ_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue(), TimeUnit.MILLISECONDS);
// Set connectionpool limits
okHttpClientBuilder.connectionPool(
new ConnectionPool(
context.getProperty(PROP_MAX_IDLE_CONNECTIONS).asInteger(),
context.getProperty(PROP_IDLE_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue(), TimeUnit.MILLISECONDS
)
);
// Set whether to follow redirects
okHttpClientBuilder.followRedirects(context.getProperty(PROP_FOLLOW_REDIRECTS).asBoolean());