Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2544#discussion_r174922021
--- Diff:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java
---
@@ -520,6 +521,27 @@ public void onTrigger(final ProcessContext context,
final ProcessSession session
new Object[]{request.getRemoteAddr(), e});
session.remove(flowFile);
return;
+ } catch (final FlowFileAccessException e) {
+ // some bad requests can produce a IOException on the HTTP
stream, which makes a FlowFileAccessException to
+ // be thrown. We should handle these cases here, while other
FlowFileAccessException are re-thrown
+ if (!(e.getCause() != null && e.getCause() instanceof
FlowFileAccessException
--- End diff --
This logic seems very specific to me. I'm afraid that it's also quite
brittle, as well, because the wrapping of those exceptions could change at any
time. I *think* the idea here is "If you hit an IOException when reading from
the HTTP Request, then send back a BAD REQUEST status code. Else, rethrow the
Exception." Correct?
If so, we could make this a little cleaner and more stable, IMO, if we
change the logic above a little bit. Instead of calling
`ProcessSession.importFrom(InputStream, FlowFile)` (which would throw
FlowFileAccessException if any IOException is thrown), we can change it to
something like:
```
try (OutputStream flowFileOut = session.write(flowFile)) {
StreamUtils.copy(request.getInputStream(), flowFileOut);
} catch (IOException ioe) {
// this will occur only if an IOException is thrown from reading the
InputStream. If an IOException is thrown from
// the OutputStream, the OutputStream will always wrap it with a
FlowFileAccessException because this is
// a "special case" where we are writing to the Content Repo.
// ... new logic here to remove flowfile and send back bad request
status code
}
```
---