From a679e88b6f4f0e5f800aba5a6891494bdbdfb193 Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Tue, 10 Mar 2020 15:46:06 +0100 Subject: [PATCH] NIFI-4970 - Add a property to deal with empty GZIP HTTP response Signed-off-by: Pierre Villard This closes #4127. --- .../nifi/processors/standard/InvokeHTTP.java | 16 ++++++++++++++-- .../nifi/processors/standard/TestInvokeHTTP.java | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) 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 b5c853cfee..2ccaed5922 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 @@ -23,6 +23,7 @@ import com.burgstaller.okhttp.CachingAuthenticatorDecorator; import com.burgstaller.okhttp.digest.CachingAuthenticator; import com.burgstaller.okhttp.digest.DigestAuthenticator; import com.google.common.io.Files; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -408,6 +409,15 @@ public final class InvokeHTTP extends AbstractProcessor { .addValidator(StandardValidators.DATA_SIZE_VALIDATOR) .build(); + public static final PropertyDescriptor IGNORE_RESPONSE_CONTENT = new PropertyDescriptor.Builder() + .name("ignore-response-content") + .description("If true, the processor will not write the response's content into the flow file.") + .displayName("Ignore response's content") + .required(true) + .defaultValue("false") + .allowableValues("true", "false") + .build(); + private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH, ProxySpec.SOCKS}; public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS); @@ -439,7 +449,8 @@ public final class InvokeHTTP extends AbstractProcessor { PROP_USE_CHUNKED_ENCODING, PROP_PENALIZE_NO_RETRY, PROP_USE_ETAG, - PROP_ETAG_MAX_CACHE_SIZE)); + PROP_ETAG_MAX_CACHE_SIZE, + IGNORE_RESPONSE_CONTENT)); // relationships public static final Relationship REL_SUCCESS_REQ = new Relationship.Builder() @@ -486,6 +497,7 @@ public final class InvokeHTTP extends AbstractProcessor { private final AtomicReference okHttpClientAtomicReference = new AtomicReference<>(); + @Override protected void init(ProcessorInitializationContext context) { excludedHeaders.put("Trusted Hostname", "HTTP request header '{}' excluded. " + "Update processor to use the SSLContextService instead. " + @@ -842,7 +854,7 @@ public final class InvokeHTTP extends AbstractProcessor { boolean outputBodyToRequestAttribute = (!isSuccess(statusCode) || putToAttribute) && requestFlowFile != null; boolean outputBodyToResponseContent = (isSuccess(statusCode) && !putToAttribute) || context.getProperty(PROP_OUTPUT_RESPONSE_REGARDLESS).asBoolean(); ResponseBody responseBody = responseHttp.body(); - boolean bodyExists = responseBody != null ? responseBody.contentLength() > 0 : false; + boolean bodyExists = responseBody != null && !context.getProperty(IGNORE_RESPONSE_CONTENT).asBoolean(); InputStream responseBodyStream = null; SoftLimitBoundedByteArrayOutputStream outputStreamToRequestAttribute = null; diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java index 1a9ee10e16..e25344ceb0 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java @@ -273,6 +273,7 @@ public class TestInvokeHTTP extends TestInvokeHttpCommon { addHandler(new EmptyGzipResponseHandler()); runner.setProperty(InvokeHTTP.PROP_URL, url); + runner.setProperty(InvokeHTTP.IGNORE_RESPONSE_CONTENT, "true"); createFlowFiles(runner);