Skip to content

Commit

Permalink
NIFI-4970 - EOF Exception in InvokeHttp when body's response is empty…
Browse files Browse the repository at this point in the history
… with gzip

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

This closes #4109.
  • Loading branch information
eduardofontes authored and pvillard31 committed Mar 4, 2020
1 parent 0b2816b commit bad254e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Expand Up @@ -842,7 +842,7 @@ public void onTrigger(ProcessContext context, ProcessSession session) throws Pro
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;
Expand Down
Expand Up @@ -268,4 +268,42 @@ public void testOnPropertyModified() throws Exception {
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");
}

}
}

0 comments on commit bad254e

Please sign in to comment.