pvillard31 commented on code in PR #11303:
URL: https://github.com/apache/nifi/pull/11303#discussion_r3342454716
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/test/java/org/apache/nifi/web/controller/StandardContentViewerControllerTest.java:
##########
@@ -67,8 +75,39 @@ class StandardContentViewerControllerTest {
@Mock
private ContentAccess contentAccess;
+ @Captor
+ private ArgumentCaptor<String> errorMessageCaptor;
+
private final StandardContentViewerController controller = new
StandardContentViewerController();
+ @Test
+ void testDoGetFormattedContentTypeNotSupported() throws IOException {
+ final InputStream contentStream = new
ByteArrayInputStream(XML_DOCUMENT.getBytes(StandardCharsets.UTF_8));
+ final DownloadableContent downloadableContent = new
DownloadableContent(FILENAME, APPLICATION_OCTET_STREAM, contentStream);
+ setDownloadableContent(downloadableContent);
+
when(request.getParameter(eq(FORMATTED_PARAMETER))).thenReturn(Boolean.TRUE.toString());
+
when(request.getParameter(eq(CLIENT_ID_PARAMETER))).thenReturn(UUID.randomUUID().toString());
+
+ controller.doGet(request, response);
+
+ verify(response).sendError(eq(HttpServletResponse.SC_NOT_ACCEPTABLE),
anyString());
+ }
+
+ @Test
+ void testDoGetNotFormattedPartialContent() throws IOException {
+ final InputStream contentStream = new
ByteArrayInputStream(XML_DOCUMENT.getBytes(StandardCharsets.UTF_8));
+ final DownloadableContent downloadableContent = new
DownloadableContent(FILENAME, APPLICATION_OCTET_STREAM, contentStream);
+ setDownloadableContent(downloadableContent);
+
+ final MockServletOutputStream mockServletOutputStream = new
MockServletOutputStream();
+ when(response.getOutputStream()).thenReturn(mockServletOutputStream);
+
+ final LimitedStandardContentViewerController limitedController = new
LimitedStandardContentViewerController();
+ limitedController.doGet(request, response);
+
+ verify(response).setStatus(eq(HttpServletResponse.SC_PARTIAL_CONTENT));
Review Comment:
Since MockServletOutputStream never commits the response, does this test
really verify that a real container would send 206 after the body is written?
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/controller/StandardContentViewerController.java:
##########
@@ -80,38 +92,47 @@ public void doGet(final HttpServletRequest request, final
HttpServletResponse re
return;
}
- response.setStatus(HttpServletResponse.SC_OK);
-
+ final LimitingInputStream contentStream =
getContentStream(downloadableContent);
final boolean formatted =
Boolean.parseBoolean(request.getParameter("formatted"));
- if (!formatted) {
- final InputStream contentStream = downloadableContent.getContent();
+ if (formatted) {
+ final ContentType formattedContentType =
getFormattedContentType(request, downloadableContent.getType());
+ if (formattedContentType == null) {
+ response.sendError(HttpURLConnection.HTTP_NOT_ACCEPTABLE,
"Unknown Content Type");
+ } else {
+ final String dataUri = requestContext.getDataUri();
+ writeContentFormatted(dataUri, formattedContentType,
contentStream, response);
+ response.setStatus(HttpServletResponse.SC_OK);
+ }
+ } else {
contentStream.transferTo(response.getOutputStream());
Review Comment:
For content larger than the response buffer, the response commits during
transferTo, so does the later setStatus(SC_PARTIAL_CONTENT) actually reach the
client, or does it silently return 200 with truncated content?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]