mirror of https://github.com/apache/nifi.git
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:
parent
0b2816baa4
commit
bad254ec5b
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue