mirror of
https://github.com/apache/nifi.git
synced 2025-03-06 09:29:33 +00:00
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:
parent
afad982e91
commit
a679e88b6f
@ -23,6 +23,7 @@ import com.burgstaller.okhttp.CachingAuthenticatorDecorator;
|
|||||||
import com.burgstaller.okhttp.digest.CachingAuthenticator;
|
import com.burgstaller.okhttp.digest.CachingAuthenticator;
|
||||||
import com.burgstaller.okhttp.digest.DigestAuthenticator;
|
import com.burgstaller.okhttp.digest.DigestAuthenticator;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -408,6 +409,15 @@ public final class InvokeHTTP extends AbstractProcessor {
|
|||||||
.addValidator(StandardValidators.DATA_SIZE_VALIDATOR)
|
.addValidator(StandardValidators.DATA_SIZE_VALIDATOR)
|
||||||
.build();
|
.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};
|
private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH, ProxySpec.SOCKS};
|
||||||
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE
|
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE
|
||||||
= ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);
|
= ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);
|
||||||
@ -439,7 +449,8 @@ public final class InvokeHTTP extends AbstractProcessor {
|
|||||||
PROP_USE_CHUNKED_ENCODING,
|
PROP_USE_CHUNKED_ENCODING,
|
||||||
PROP_PENALIZE_NO_RETRY,
|
PROP_PENALIZE_NO_RETRY,
|
||||||
PROP_USE_ETAG,
|
PROP_USE_ETAG,
|
||||||
PROP_ETAG_MAX_CACHE_SIZE));
|
PROP_ETAG_MAX_CACHE_SIZE,
|
||||||
|
IGNORE_RESPONSE_CONTENT));
|
||||||
|
|
||||||
// relationships
|
// relationships
|
||||||
public static final Relationship REL_SUCCESS_REQ = new Relationship.Builder()
|
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<>();
|
private final AtomicReference<OkHttpClient> okHttpClientAtomicReference = new AtomicReference<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void init(ProcessorInitializationContext context) {
|
protected void init(ProcessorInitializationContext context) {
|
||||||
excludedHeaders.put("Trusted Hostname", "HTTP request header '{}' excluded. " +
|
excludedHeaders.put("Trusted Hostname", "HTTP request header '{}' excluded. " +
|
||||||
"Update processor to use the SSLContextService instead. " +
|
"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 outputBodyToRequestAttribute = (!isSuccess(statusCode) || putToAttribute) && requestFlowFile != null;
|
||||||
boolean outputBodyToResponseContent = (isSuccess(statusCode) && !putToAttribute) || context.getProperty(PROP_OUTPUT_RESPONSE_REGARDLESS).asBoolean();
|
boolean outputBodyToResponseContent = (isSuccess(statusCode) && !putToAttribute) || context.getProperty(PROP_OUTPUT_RESPONSE_REGARDLESS).asBoolean();
|
||||||
ResponseBody responseBody = responseHttp.body();
|
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;
|
InputStream responseBodyStream = null;
|
||||||
SoftLimitBoundedByteArrayOutputStream outputStreamToRequestAttribute = null;
|
SoftLimitBoundedByteArrayOutputStream outputStreamToRequestAttribute = null;
|
||||||
|
@ -273,6 +273,7 @@ public class TestInvokeHTTP extends TestInvokeHttpCommon {
|
|||||||
addHandler(new EmptyGzipResponseHandler());
|
addHandler(new EmptyGzipResponseHandler());
|
||||||
|
|
||||||
runner.setProperty(InvokeHTTP.PROP_URL, url);
|
runner.setProperty(InvokeHTTP.PROP_URL, url);
|
||||||
|
runner.setProperty(InvokeHTTP.IGNORE_RESPONSE_CONTENT, "true");
|
||||||
|
|
||||||
createFlowFiles(runner);
|
createFlowFiles(runner);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user