NIFI-4970 - EOF Exception in InvokeHttp when body's response is empty with gzip

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

This closes #4109.
This commit is contained in:
Eduardo Fontes 2020-03-03 23:38:12 -03:00 committed by Pierre Villard
parent 0b2816baa4
commit bad254ec5b
No known key found for this signature in database
GPG Key ID: BEE1599F0726E9CD
2 changed files with 39 additions and 1 deletions

View File

@ -842,7 +842,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;
boolean bodyExists = responseBody != null ? responseBody.contentLength() > 0 : false;
InputStream responseBodyStream = null;
SoftLimitBoundedByteArrayOutputStream outputStreamToRequestAttribute = null;

View File

@ -268,4 +268,42 @@ public class TestInvokeHTTP extends TestInvokeHttpCommon {
assertNull(regexAttributesToSendField.get(processor));
}
@Test
public void testEmptyGzipHttpReponse() throws Exception {
addHandler(new EmptyGzipResponseHandler());
runner.setProperty(InvokeHTTP.PROP_URL, url);
createFlowFiles(runner);
runner.run();
runner.assertTransferCount(InvokeHTTP.REL_SUCCESS_REQ, 1);
runner.assertTransferCount(InvokeHTTP.REL_RESPONSE, 1);
runner.assertTransferCount(InvokeHTTP.REL_RETRY, 0);
runner.assertTransferCount(InvokeHTTP.REL_NO_RETRY, 0);
runner.assertTransferCount(InvokeHTTP.REL_FAILURE, 0);
runner.assertPenalizeCount(0);
//expected empty content in response FlowFile
final MockFlowFile bundle = runner.getFlowFilesForRelationship(InvokeHTTP.REL_RESPONSE).get(0);
bundle.assertContentEquals(new byte[0]);
bundle.assertAttributeEquals(InvokeHTTP.STATUS_CODE, "200");
bundle.assertAttributeEquals(InvokeHTTP.STATUS_MESSAGE, "OK");
bundle.assertAttributeEquals("Foo", "Bar");
bundle.assertAttributeEquals("Content-Type", "text/plain");
}
public static class EmptyGzipResponseHandler extends AbstractHandler {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
response.setStatus(200);
response.setContentLength(0);
response.setContentType("text/plain");
response.setHeader("Content-Encoding", "gzip");
}
}
}