From f2368a0dd14aff31c5c5e7b4b9b7e470baf87fa7 Mon Sep 17 00:00:00 2001 From: Wouter de Vries Date: Fri, 24 Apr 2020 11:26:20 +0200 Subject: [PATCH] NIFI-7393: Add max idle time and idle connections to InvokeHTTP This closes #4233. Signed-off-by: Joey Frazee --- .../nifi/processors/standard/InvokeHTTP.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java index 8f0e123eec..778e5ddaf0 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java @@ -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());