NIFI-4970 - Add a property to deal with empty GZIP HTTP response

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #4127.
This commit is contained in:
Pierre Villard 2020-03-10 15:46:06 +01:00
parent afad982e91
commit a679e88b6f
No known key found for this signature in database
GPG Key ID: BEE1599F0726E9CD
2 changed files with 15 additions and 2 deletions

View File

@ -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<OkHttpClient> 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;

View File

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