You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2015/06/04 19:10:53 UTC
[1/2] incubator-nifi git commit: NIFI-644: - Using mime.type
attribute when known. If not specified or is octet-stream continue using
content detection (tika).
Repository: incubator-nifi
Updated Branches:
refs/heads/develop efc862eac -> e2227cdaf
NIFI-644:
- Using mime.type attribute when known. If not specified or is octet-stream continue using content detection (tika).
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/be50793d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/be50793d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/be50793d
Branch: refs/heads/develop
Commit: be50793decde1279f78e68548f5807a4cc646780
Parents: 07628f7
Author: Matt Gilman <ma...@gmail.com>
Authored: Thu Jun 4 12:53:42 2015 -0400
Committer: Matt Gilman <ma...@gmail.com>
Committed: Thu Jun 4 12:53:42 2015 -0400
----------------------------------------------------------------------
.../apache/nifi/web/api/ProvenanceResource.java | 4 +-
.../nifi/web/ContentViewerController.java | 210 ++++++++++---------
2 files changed, 111 insertions(+), 103 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/be50793d/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.java
index afa404d..a2e7ef3 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.java
@@ -276,7 +276,7 @@ public class ProvenanceResource extends ApplicationResource {
*/
@GET
@Consumes(MediaType.WILDCARD)
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.WILDCARD)
@Path("/events/{id}/content/input")
@PreAuthorize("hasRole('ROLE_PROVENANCE')")
@ApiOperation(
@@ -375,7 +375,7 @@ public class ProvenanceResource extends ApplicationResource {
*/
@GET
@Consumes(MediaType.WILDCARD)
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Produces(MediaType.WILDCARD)
@Path("/events/{id}/content/output")
@PreAuthorize("hasRole('ROLE_PROVENANCE')")
@ApiOperation(
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/be50793d/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
index 304f85e..984b8a9 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java
@@ -132,130 +132,138 @@ public class ContentViewerController extends HttpServlet {
}
// buffer the content to support reseting in case we need to detect the content type or char encoding
- final BufferedInputStream bis = new BufferedInputStream(downloadableContent.getContent());
+ try (final BufferedInputStream bis = new BufferedInputStream(downloadableContent.getContent());) {
+ final String mimeType;
- // detect the content type
- final DefaultDetector detector = new DefaultDetector();
+ // when standalone and we don't know the type is null as we were able to directly access the content bypassing the rest endpoint,
+ // when clustered and we don't know the type set to octet stream since the content was retrieved from the node's rest endpoint
+ if (downloadableContent.getType() == null || downloadableContent.getType().equals(MediaType.OCTET_STREAM.toString())) {
+ // attempt to detect the content stream if we don't know what it is ()
+ final DefaultDetector detector = new DefaultDetector();
- // create the stream for tika to process, buffered to support reseting
- final TikaInputStream tikaStream = TikaInputStream.get(bis);
+ // create the stream for tika to process, buffered to support reseting
+ final TikaInputStream tikaStream = TikaInputStream.get(bis);
- // provide a hint based on the filename
- final Metadata metadata = new Metadata();
- metadata.set(Metadata.RESOURCE_NAME_KEY, downloadableContent.getFilename());
+ // provide a hint based on the filename
+ final Metadata metadata = new Metadata();
+ metadata.set(Metadata.RESOURCE_NAME_KEY, downloadableContent.getFilename());
- // Get mime type
- final MediaType mediatype = detector.detect(tikaStream, metadata);
- final String mimeType = mediatype.toString();
+ // Get mime type
+ final MediaType mediatype = detector.detect(tikaStream, metadata);
+ mimeType = mediatype.toString();
+ } else {
+ mimeType = downloadableContent.getType();
+ }
- // add attributes needed for the header
- request.setAttribute("filename", downloadableContent.getFilename());
- request.setAttribute("contentType", mimeType);
+ // add attributes needed for the header
+ request.setAttribute("filename", downloadableContent.getFilename());
+ request.setAttribute("contentType", mimeType);
- // generate the header
- request.getRequestDispatcher("/WEB-INF/jsp/header.jsp").include(request, response);
+ // generate the header
+ request.getRequestDispatcher("/WEB-INF/jsp/header.jsp").include(request, response);
- // remove the attributes needed for the header
- request.removeAttribute("filename");
- request.removeAttribute("contentType");
+ // remove the attributes needed for the header
+ request.removeAttribute("filename");
+ request.removeAttribute("contentType");
- // generate the markup for the content based on the display mode
- if (DisplayMode.Hex.equals(displayMode)) {
- final byte[] buffer = new byte[BUFFER_LENGTH];
- final int read = StreamUtils.fillBuffer(bis, buffer, false);
+ // generate the markup for the content based on the display mode
+ if (DisplayMode.Hex.equals(displayMode)) {
+ final byte[] buffer = new byte[BUFFER_LENGTH];
+ final int read = StreamUtils.fillBuffer(bis, buffer, false);
- // trim the byte array if necessary
- byte[] bytes = buffer;
- if (read != buffer.length) {
- bytes = new byte[read];
- System.arraycopy(buffer, 0, bytes, 0, read);
- }
-
- // convert bytes into the base 64 bytes
- final String base64 = Base64.encodeBase64String(bytes);
+ // trim the byte array if necessary
+ byte[] bytes = buffer;
+ if (read != buffer.length) {
+ bytes = new byte[read];
+ System.arraycopy(buffer, 0, bytes, 0, read);
+ }
- // defer to the jsp
- request.setAttribute("content", base64);
- request.getRequestDispatcher("/WEB-INF/jsp/hexview.jsp").include(request, response);
- } else {
- // lookup a viewer for the content
- final String contentViewerUri = servletContext.getInitParameter(mimeType);
+ // convert bytes into the base 64 bytes
+ final String base64 = Base64.encodeBase64String(bytes);
- // handle no viewer for content type
- if (contentViewerUri == null) {
- request.getRequestDispatcher("/WEB-INF/jsp/no-viewer.jsp").include(request, response);
+ // defer to the jsp
+ request.setAttribute("content", base64);
+ request.getRequestDispatcher("/WEB-INF/jsp/hexview.jsp").include(request, response);
} else {
- // create a request attribute for accessing the content
- request.setAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE, new ViewableContent() {
- @Override
- public InputStream getContentStream() {
- return bis;
- }
+ // lookup a viewer for the content
+ final String contentViewerUri = servletContext.getInitParameter(mimeType);
+
+ // handle no viewer for content type
+ if (contentViewerUri == null) {
+ request.getRequestDispatcher("/WEB-INF/jsp/no-viewer.jsp").include(request, response);
+ } else {
+ // create a request attribute for accessing the content
+ request.setAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE, new ViewableContent() {
+ @Override
+ public InputStream getContentStream() {
+ return bis;
+ }
- @Override
- public String getContent() throws IOException {
- // detect the charset
- final CharsetDetector detector = new CharsetDetector();
- detector.setText(bis);
- detector.enableInputFilter(true);
- final CharsetMatch match = detector.detect();
-
- // ensure we were able to detect the charset
- if (match == null) {
- throw new IOException("Unable to detect character encoding.");
+ @Override
+ public String getContent() throws IOException {
+ // detect the charset
+ final CharsetDetector detector = new CharsetDetector();
+ detector.setText(bis);
+ detector.enableInputFilter(true);
+ final CharsetMatch match = detector.detect();
+
+ // ensure we were able to detect the charset
+ if (match == null) {
+ throw new IOException("Unable to detect character encoding.");
+ }
+
+ // convert the stream using the detected charset
+ return IOUtils.toString(bis, match.getName());
}
- // convert the stream using the detected charset
- return IOUtils.toString(bis, match.getName());
- }
+ @Override
+ public ViewableContent.DisplayMode getDisplayMode() {
+ return displayMode;
+ }
- @Override
- public ViewableContent.DisplayMode getDisplayMode() {
- return displayMode;
- }
+ @Override
+ public String getFileName() {
+ return downloadableContent.getFilename();
+ }
- @Override
- public String getFileName() {
- return downloadableContent.getFilename();
- }
+ @Override
+ public String getContentType() {
+ return mimeType;
+ }
+ });
+
+ try {
+ // generate the content
+ final ServletContext viewerContext = servletContext.getContext(contentViewerUri);
+ viewerContext.getRequestDispatcher("/view-content").include(request, response);
+ } catch (final Exception e) {
+ String message = e.getMessage() != null ? e.getMessage() : e.toString();
+ message = "Unable to generate view of data: " + message;
+
+ // log the error
+ logger.error(message);
+ if (logger.isDebugEnabled()) {
+ logger.error(StringUtils.EMPTY, e);
+ }
- @Override
- public String getContentType() {
- return mimeType;
- }
- });
-
- try {
- // generate the content
- final ServletContext viewerContext = servletContext.getContext(contentViewerUri);
- viewerContext.getRequestDispatcher("/view-content").include(request, response);
- } catch (final Exception e) {
- String message = e.getMessage() != null ? e.getMessage() : e.toString();
- message = "Unable to generate view of data: " + message;
-
- // log the error
- logger.error(message);
- if (logger.isDebugEnabled()) {
- logger.error(StringUtils.EMPTY, e);
- }
+ // populate the request attributes
+ request.setAttribute("title", "Error");
+ request.setAttribute("messages", message);
- // populate the request attributes
- request.setAttribute("title", "Error");
- request.setAttribute("messages", message);
+ // forward to the error page
+ final ServletContext viewerContext = servletContext.getContext("/nifi");
+ viewerContext.getRequestDispatcher("/message").forward(request, response);
+ return;
+ }
- // forward to the error page
- final ServletContext viewerContext = servletContext.getContext("/nifi");
- viewerContext.getRequestDispatcher("/message").forward(request, response);
- return;
+ // remove the request attribute
+ request.removeAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE);
}
-
- // remove the request attribute
- request.removeAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE);
}
- }
- // generate footer
- request.getRequestDispatcher("/WEB-INF/jsp/footer.jsp").include(request, response);
+ // generate footer
+ request.getRequestDispatcher("/WEB-INF/jsp/footer.jsp").include(request, response);
+ }
}
/**
[2/2] incubator-nifi git commit: Merge branch 'develop' of
https://git-wip-us.apache.org/repos/asf/incubator-nifi into develop
Posted by mc...@apache.org.
Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/incubator-nifi into develop
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/e2227cda
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/e2227cda
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/e2227cda
Branch: refs/heads/develop
Commit: e2227cdafadabf9d8e57437a5b71bc01d21d3367
Parents: be50793 efc862e
Author: Matt Gilman <ma...@gmail.com>
Authored: Thu Jun 4 13:10:27 2015 -0400
Committer: Matt Gilman <ma...@gmail.com>
Committed: Thu Jun 4 13:10:27 2015 -0400
----------------------------------------------------------------------
.../nifi-hl7-query-language/pom.xml | 2 +-
nifi/nifi-docs/pom.xml | 2 +-
.../nifi-aws-bundle/nifi-aws-processors/pom.xml | 2 +-
.../nifi-framework-cluster/pom.xml | 2 +-
.../nifi-framework/nifi-framework-core/pom.xml | 2 +-
.../repository/StandardProcessSession.java | 173 ++++++++++---------
.../nifi-web/nifi-web-content-viewer/pom.xml | 2 +-
.../nifi-framework/nifi-web/nifi-web-ui/pom.xml | 2 +-
.../nifi-hl7-bundle/nifi-hl7-processors/pom.xml | 2 +-
.../nifi-mongodb-processors/pom.xml | 31 ----
.../nifi/processors/mongodb/GetMongoTest.java | 4 +-
.../nifi/processors/mongodb/PutMongoTest.java | 8 +-
.../nifi-solr-processors/pom.xml | 2 +-
.../nifi-standard-processors/pom.xml | 2 +-
14 files changed, 106 insertions(+), 130 deletions(-)
----------------------------------------------------------------------