You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "exceptionfactory (via GitHub)" <gi...@apache.org> on 2023/02/01 18:41:48 UTC
[GitHub] [nifi] exceptionfactory opened a new pull request, #6915: NIFI-11126 Delete MultiPart files in ListenHTTP after processing
exceptionfactory opened a new pull request, #6915:
URL: https://github.com/apache/nifi/pull/6915
# Summary
[NIFI-11126](https://issues.apache.org/jira/browse/NIFI-11126) Updates `ListenHTTP` to delete MultiPart elements after processing to avoid leaving files in the system temporary directory.
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [X] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
### Pull Request Tracking
- [X] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
- [X] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
### Pull Request Formatting
- [X] Pull Request based on current revision of the `main` branch
- [X] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
### Build
- [ ] Build completed using `mvn clean install -P contrib-check`
- [ ] JDK 8
- [ ] JDK 11
- [ ] JDK 17
### Licensing
- [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
- [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
### Documentation
- [ ] Documentation formatting appears as expected in rendered files
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] ChrisSamo632 commented on a diff in pull request #6915: NIFI-11126 Delete MultiPart files in ListenHTTP after processing
Posted by "ChrisSamo632 (via GitHub)" <gi...@apache.org>.
ChrisSamo632 commented on code in PR #6915:
URL: https://github.com/apache/nifi/pull/6915#discussion_r1093675510
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/ListenHTTPServlet.java:
##########
@@ -276,18 +274,17 @@ private Set<FlowFile> handleMultipartRequest(HttpServletRequest request, Process
Set<FlowFile> flowFileSet = new HashSet<>();
String tempDir = System.getProperty("java.io.tmpdir");
request.setAttribute(Request.MULTIPART_CONFIG_ELEMENT, new MultipartConfigElement(tempDir, multipartRequestMaxSize, multipartRequestMaxSize, multipartReadBufferSize));
- Collection<Part> requestParts = Collections.unmodifiableCollection(request.getParts());
- final Iterator<Part> parts = requestParts.iterator();
int i = 0;
- while (parts.hasNext()) {
- Part part = parts.next();
+ final Collection<Part> requestParts = request.getParts();
+ for (final Part part : requestParts) {
FlowFile flowFile = session.create();
try (OutputStream flowFileOutputStream = session.write(flowFile)) {
StreamUtils.copy(part.getInputStream(), flowFileOutputStream);
}
flowFile = saveRequestDetailsAsAttributes(request, session, foundSubject, foundIssuer, flowFile);
flowFile = savePartDetailsAsAttributes(session, part, flowFile, i, requestParts.size());
flowFileSet.add(flowFile);
+ part.delete();
Review Comment:
Would this be better in a `finally` block to ensure cleanup even if there are exceptions thrown elsewhere in this loop/method after the possible point of file creation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] ChrisSamo632 commented on pull request #6915: NIFI-11126 Delete MultiPart files in ListenHTTP after processing
Posted by "ChrisSamo632 (via GitHub)" <gi...@apache.org>.
ChrisSamo632 commented on PR #6915:
URL: https://github.com/apache/nifi/pull/6915#issuecomment-1413654622
LGTM, thanks for the fix @exceptionfactory , will merge 👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on pull request #6915: NIFI-11126 Delete MultiPart files in ListenHTTP after processing
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #6915:
URL: https://github.com/apache/nifi/pull/6915#issuecomment-1412786764
It looks like the tests failed on Windows, reviewing...
```
Error: org.apache.nifi.processors.standard.TestListenHTTP.testMultipartFormDataRequest Time elapsed: 0.297 s <<< FAILURE!
org.opentest4j.AssertionFailedError: MultiPart files found in temporary directory [C:\Users\RUNNER~1\AppData\Local\Temp] ==> expected: <0> but was: <3>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on pull request #6915: NIFI-11126 Delete MultiPart files in ListenHTTP after processing
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #6915:
URL: https://github.com/apache/nifi/pull/6915#issuecomment-1412960319
It turns out that the current `ListenHTTPServlet` was not closing the Part `InputStream`. I corrected the behavior by moving `Part.getInputStream()` to the try-with-resources block and that works as expected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a diff in pull request #6915: NIFI-11126 Delete MultiPart files in ListenHTTP after processing
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #6915:
URL: https://github.com/apache/nifi/pull/6915#discussion_r1093682251
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/ListenHTTPServlet.java:
##########
@@ -276,18 +274,17 @@ private Set<FlowFile> handleMultipartRequest(HttpServletRequest request, Process
Set<FlowFile> flowFileSet = new HashSet<>();
String tempDir = System.getProperty("java.io.tmpdir");
request.setAttribute(Request.MULTIPART_CONFIG_ELEMENT, new MultipartConfigElement(tempDir, multipartRequestMaxSize, multipartRequestMaxSize, multipartReadBufferSize));
- Collection<Part> requestParts = Collections.unmodifiableCollection(request.getParts());
- final Iterator<Part> parts = requestParts.iterator();
int i = 0;
- while (parts.hasNext()) {
- Part part = parts.next();
+ final Collection<Part> requestParts = request.getParts();
+ for (final Part part : requestParts) {
FlowFile flowFile = session.create();
try (OutputStream flowFileOutputStream = session.write(flowFile)) {
StreamUtils.copy(part.getInputStream(), flowFileOutputStream);
}
flowFile = saveRequestDetailsAsAttributes(request, session, foundSubject, foundIssuer, flowFile);
flowFile = savePartDetailsAsAttributes(session, part, flowFile, i, requestParts.size());
flowFileSet.add(flowFile);
+ part.delete();
Review Comment:
Thanks @ChrisSamo632, that's a good suggestion. I pushed an update that iterates through the Parts in a finally block where the Servlet calls `handleMultipartRequest()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] asfgit closed pull request #6915: NIFI-11126 Delete MultiPart files in ListenHTTP after processing
Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #6915: NIFI-11126 Delete MultiPart files in ListenHTTP after processing
URL: https://github.com/apache/nifi/pull/6915
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org