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/02/19 05:35:46 UTC

[1/2] incubator-nifi git commit: NIFI-353: - Updating the mark up on the content page.

Repository: incubator-nifi
Updated Branches:
  refs/heads/NIFI-353 78bab591d -> bd9ef8431


NIFI-353:
- Updating the mark up on the content page.

Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/2334e488
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/2334e488
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/2334e488

Branch: refs/heads/NIFI-353
Commit: 2334e4888e48764b93671b8ac2a00d26a07dc3bc
Parents: 78bab59
Author: Matt Gilman <ma...@gmail.com>
Authored: Tue Feb 17 23:00:07 2015 -0500
Committer: Matt Gilman <ma...@gmail.com>
Committed: Tue Feb 17 23:00:07 2015 -0500

----------------------------------------------------------------------
 .../src/main/webapp/WEB-INF/jsp/footer.jsp             |  1 +
 .../src/main/webapp/WEB-INF/jsp/header.jsp             | 13 ++++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/2334e488/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/footer.jsp
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/footer.jsp b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/footer.jsp
index 195c9e8..5288315 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/footer.jsp
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/footer.jsp
@@ -15,5 +15,6 @@
   limitations under the License.
 --%>
 <%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %>
+        </div>
     </body>
 </html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/2334e488/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/header.jsp
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/header.jsp b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/header.jsp
index 9079e71..1e83c99 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/header.jsp
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/header.jsp
@@ -17,11 +17,14 @@
 <%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %>
 <!DOCTYPE html>
 <html>
+    <% String contextPath = "/".equals(request.getContextPath()) ? "" : request.getContextPath(); %>
     <head>
-        <title>NiFi</title>
-        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <link rel="shortcut icon" href="../nifi/images/nifi16.ico"/>
-        <link href="../../css/component-usage.css" rel="stylesheet" type="text/css" />
+        <title>NiFi</title>
+        <link href="<%= contextPath %>/nifi/css/message-pane.css" rel="stylesheet" type="text/css" />
+        <link href="<%= contextPath %>/nifi/css/message-page.css" rel="stylesheet" type="text/css" />
     </head>
-    <body>
\ No newline at end of file
+
+    <body class="message-pane">
+        <div class="message-pane-message-box">
\ No newline at end of file


[2/2] incubator-nifi git commit: NIFI-353: - Continuing to wire up the content viewer controller to NiFi (standalone/clustered) and the content type specific renderer.

Posted by mc...@apache.org.
NIFI-353:
- Continuing to wire up the content viewer controller to NiFi (standalone/clustered) and the content type specific renderer.

Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/bd9ef843
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/bd9ef843
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/bd9ef843

Branch: refs/heads/NIFI-353
Commit: bd9ef8431bc66f567d8e526e06f0635de2417254
Parents: 2334e48
Author: Matt Gilman <ma...@gmail.com>
Authored: Wed Feb 18 23:35:28 2015 -0500
Committer: Matt Gilman <ma...@gmail.com>
Committed: Wed Feb 18 23:35:28 2015 -0500

----------------------------------------------------------------------
 .../org/apache/nifi/web/ViewableContent.java    |   9 ++
 .../org/apache/nifi/web/server/JettyServer.java |  50 ++++++---
 .../nifi/web/StandardNiFiContentAccess.java     | 109 ++++++++++++++++++-
 .../src/main/resources/nifi-web-api-context.xml |   7 ++
 .../java/org/apache/nifi/web/ContentAccess.java |   4 +-
 .../apache/nifi/web/ContentRequestContext.java  |  27 +++++
 .../nifi-web/nifi-web-content-viewer/pom.xml    |   1 +
 .../nifi/web/ContentViewerController.java       |  40 +++++--
 .../nifi-standard-content-viewer/pom.xml        |   8 ++
 .../web/StandardContentViewerController.java    |  15 ++-
 .../src/main/webapp/WEB-INF/jsp/codemirror.jsp  |  18 +++
 .../src/main/webapp/WEB-INF/jsp/content.jsp     |  18 ---
 12 files changed, 251 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java b/nifi/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java
index 4558aa8..46a4ab7 100644
--- a/nifi/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java
+++ b/nifi/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java
@@ -23,6 +23,8 @@ import java.io.InputStream;
  */
 public interface ViewableContent {
 
+    public static final String CONTENT_REQUEST_ATTRIBUTE = "org.apache.nifi.web.content";
+    
     /**
      * The stream to the viewable content.
      * 
@@ -36,4 +38,11 @@ public interface ViewableContent {
      * @return 
      */
     String getFileName();
+    
+    /**
+     * The mime type of the content.
+     * 
+     * @return 
+     */
+    String getContentType();
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
index 6fdd6d1..54111a1 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
@@ -52,6 +52,7 @@ import org.apache.nifi.util.NiFiProperties;
 import org.apache.nifi.web.NiFiWebContext;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.web.ContentAccess;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Handler;
 import org.eclipse.jetty.server.HttpConfiguration;
@@ -99,6 +100,7 @@ public class JettyServer implements NiFiServer {
     private ExtensionMapping extensionMapping;
     private WebAppContext webApiContext;
     private WebAppContext webDocsContext;
+    private WebAppContext webContentViewerContext;
     private Collection<WebAppContext> customUiWebContexts;
     private Collection<WebAppContext> contentViewerWebContexts;
     private final NiFiProperties props;
@@ -261,7 +263,7 @@ public class JettyServer implements NiFiServer {
         handlers.addHandler(webApiContext);
 
         // load the content viewer app
-        final WebAppContext webContentViewerContext = loadWar(webContentViewerWar, "/nifi-content-viewer", frameworkClassLoader);
+        webContentViewerContext = loadWar(webContentViewerWar, "/nifi-content-viewer", frameworkClassLoader);
         webContentViewerContext.getInitParams().putAll(mimeTypeMappings);
         handlers.addHandler(webContentViewerContext);
         
@@ -559,30 +561,48 @@ public class JettyServer implements NiFiServer {
 
             // ensure the appropriate wars deployed successfully before injecting the NiFi context and security filters - 
             // this must be done after starting the server (and ensuring there were no start up failures)
-            if (webApiContext != null && CollectionUtils.isNotEmpty(customUiWebContexts)) {
+            if (webApiContext != null) {
                 final ServletContext webApiServletContext = webApiContext.getServletHandler().getServletContext();
                 final WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(webApiServletContext);
-                final NiFiWebContext niFiWebContext = webApplicationContext.getBean("nifiWebContext", NiFiWebContext.class);
 
-                for (final WebAppContext customUiContext : customUiWebContexts) {
-                    // set the NiFi context in each custom ui servlet context
-                    final ServletContext customUiServletContext = customUiContext.getServletHandler().getServletContext();
-                    customUiServletContext.setAttribute("nifi-web-context", niFiWebContext);
-
-                    // add the security filter to any custom ui wars
-                    final FilterHolder securityFilter = webApiContext.getServletHandler().getFilter("springSecurityFilterChain");
-                    if (securityFilter != null) {
-                        customUiContext.addFilter(securityFilter, "/*", EnumSet.of(DispatcherType.REQUEST));
+                if (CollectionUtils.isNotEmpty(customUiWebContexts)) {
+                    final NiFiWebContext niFiWebContext = webApplicationContext.getBean("nifiWebContext", NiFiWebContext.class);
+                    
+                    for (final WebAppContext customUiContext : customUiWebContexts) {
+                        // set the NiFi context in each custom ui servlet context
+                        final ServletContext customUiServletContext = customUiContext.getServletHandler().getServletContext();
+                        customUiServletContext.setAttribute("nifi-web-context", niFiWebContext);
+
+                        // add the security filter to any custom ui wars
+                        final FilterHolder securityFilter = webApiContext.getServletHandler().getFilter("springSecurityFilterChain");
+                        if (securityFilter != null) {
+                            customUiContext.addFilter(securityFilter, "/*", EnumSet.of(DispatcherType.REQUEST));
+                        }
+                    }
+                }
+                
+                if (CollectionUtils.isNotEmpty(contentViewerWebContexts)) {
+                    for (final WebAppContext contentViewerContext : contentViewerWebContexts) {
+                        // add the security filter to any content viewer  wars
+                        final FilterHolder securityFilter = webApiContext.getServletHandler().getFilter("springSecurityFilterChain");
+                        if (securityFilter != null) {
+                            contentViewerContext.addFilter(securityFilter, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE));
+                        }
                     }
                 }
                 
-                for (final WebAppContext contentViewerContext : contentViewerWebContexts) {
+                // ensure the web content viewer war was loaded
+                if (webContentViewerContext != null) {
+                    final ContentAccess contentAccess = webApplicationContext.getBean("contentAccess", ContentAccess.class);
                     
+                    // add the content access
+                    final ServletContext webContentViewerServletContext = webContentViewerContext.getServletHandler().getServletContext();
+                    webContentViewerServletContext.setAttribute("nifi-content-access", contentAccess);
                     
-                    // add the security filter to any custom ui wars
+                    // add the security filter to the content viewer controller
                     final FilterHolder securityFilter = webApiContext.getServletHandler().getFilter("springSecurityFilterChain");
                     if (securityFilter != null) {
-                        contentViewerContext.addFilter(securityFilter, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE));
+                        webContentViewerContext.addFilter(securityFilter, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE));
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiContentAccess.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/StandardNiFiContentAccess.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiContentAccess.java
index c95f671..b5735d2 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiContentAccess.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiContentAccess.java
@@ -16,23 +16,120 @@
  */
 package org.apache.nifi.web;
 
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.MultivaluedMap;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.cluster.manager.NodeResponse;
+import org.apache.nifi.cluster.manager.exception.UnknownNodeException;
+import org.apache.nifi.cluster.manager.impl.WebClusterManager;
+import org.apache.nifi.cluster.node.Node;
+import org.apache.nifi.cluster.protocol.NodeIdentifier;
 import org.apache.nifi.controller.repository.claim.ContentDirection;
+import org.apache.nifi.util.NiFiProperties;
+import org.apache.nifi.web.security.user.NiFiUserDetails;
+import org.apache.nifi.web.util.WebUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
 
 /**
  *
  */
 public class StandardNiFiContentAccess implements ContentAccess {
 
+    private static final Logger logger = LoggerFactory.getLogger(StandardNiFiContentAccess.class);
+    public static final String CLIENT_ID_PARAM = "clientId";
+    
+    private NiFiProperties properties;
     private NiFiServiceFacade serviceFacade;
-
+    private WebClusterManager clusterManager;
+    
     @Override
     @PreAuthorize("hasRole('ROLE_DFM')")
-    public DownloadableContent getContent(final String ref) {
+    public DownloadableContent getContent(final ContentRequestContext request) {
         // if clustered, send request to cluster manager
-        
-        // otherwise defer locally
-//        return serviceFacade.getContent(eventId, uri, contentDirection);
-        return null;
+        if (properties.isClusterManager()) {
+            // get the URI
+            URI dataUri;
+            try {
+                dataUri = new URI(request.getDataUri());
+            } catch (final URISyntaxException use) {
+                throw new ClusterRequestException(use);
+            }
+            
+            // set the request parameters
+            final MultivaluedMap<String, String> parameters = new MultivaluedMapImpl();
+            parameters.add(CLIENT_ID_PARAM, request.getClientId());
+            
+            // set the headers
+            final Map<String, String> headers = new HashMap<>();
+            headers.put("Accept", "application/json,application/xml");
+            if (StringUtils.isNotBlank(request.getProxiedEntitiesChain())) {
+                headers.put("X-ProxiedEntitiesChain", request.getProxiedEntitiesChain());
+            }
+
+            // add the user's authorities (if any) to the headers
+            final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+            if (authentication != null) {
+                final Object userDetailsObj = authentication.getPrincipal();
+                if (userDetailsObj instanceof NiFiUserDetails) {
+                    // serialize user details object
+                    final String hexEncodedUserDetails = WebUtils.serializeObjectToHex((Serializable) userDetailsObj);
+
+                    // put serialized user details in header
+                    headers.put("X-ProxiedEntityUserDetails", hexEncodedUserDetails);
+                }
+            }
+            
+            // get the target node and ensure it exists
+            final Node targetNode = clusterManager.getNode(request.getClusterNodeId());
+            if (targetNode == null) {
+                throw new UnknownNodeException("The specified cluster node does not exist.");
+            }
+
+            final Set<NodeIdentifier> targetNodes = new HashSet<>();
+            targetNodes.add(targetNode.getNodeId());
+
+            // replicate the request to the specific node
+            final NodeResponse nodeResponse = clusterManager.applyRequest(HttpMethod.GET, dataUri, parameters, headers, targetNodes);
+            final ClientResponse clientResponse = nodeResponse.getClientResponse();
+            final MultivaluedMap<String, String> responseHeaders = clientResponse.getHeaders();
+            
+            // create the downloadable content
+            return new DownloadableContent(null, null, clientResponse.getEntityInputStream());
+        } else {
+//            http://localhost:8080/nifi-api/controller/provenance/events/1/content/input
+            final String eventDetails = StringUtils.substringAfterLast(request.getDataUri(), "events/");
+            final String rawEventId = StringUtils.substringBefore(eventDetails, "/content/");
+            final String rawDirection = StringUtils.substringAfterLast(eventDetails, "/content/");
+            
+            // get the content type
+            final Long eventId = Long.parseLong(rawEventId);
+            final ContentDirection direction = ContentDirection.valueOf(rawDirection.toUpperCase());
+            return serviceFacade.getContent(eventId, request.getDataUri(), direction);
+        }
+    }
+
+    public void setProperties(NiFiProperties properties) {
+        this.properties = properties;
+    }
+
+    public void setServiceFacade(NiFiServiceFacade serviceFacade) {
+        this.serviceFacade = serviceFacade;
+    }
+
+    public void setClusterManager(WebClusterManager clusterManager) {
+        this.clusterManager = clusterManager;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
index 39677ca..a822442 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
@@ -30,6 +30,13 @@
             <bean class="org.apache.nifi.web.StandardOptimisticLockingManager" />
         </constructor-arg>
     </bean>
+    
+    <!-- content access -->
+    <bean id="contentAccess" class="org.apache.nifi.web.StandardNiFiContentAccess">
+        <property name="serviceFacade" ref="serviceFacade"/>
+        <property name="properties" ref="nifiProperties"/>
+        <property name="clusterManager" ref="clusterManager"/>
+    </bean>
 
     <!-- dto factory -->
     <bean id="dtoFactory" class="org.apache.nifi.web.api.dto.DtoFactory">

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentAccess.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentAccess.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentAccess.java
index 2e0da70..84f6421 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentAccess.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentAccess.java
@@ -25,8 +25,8 @@ public interface ContentAccess {
     /**
      * Gets the content for the specified claim.
      *
-     * @param ref
+     * @param request
      * @return
      */
-    DownloadableContent getContent(String ref);
+    DownloadableContent getContent(ContentRequestContext request);
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentRequestContext.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentRequestContext.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentRequestContext.java
new file mode 100644
index 0000000..afe9ab7
--- /dev/null
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-access/src/main/java/org/apache/nifi/web/ContentRequestContext.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web;
+
+/**
+ *
+ */
+public interface ContentRequestContext {
+    String getDataUri();
+    String getClusterNodeId();
+    String getClientId();
+    String getProxiedEntitiesChain();
+}

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml
index b8edd61..b51c456 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml
@@ -30,6 +30,7 @@
         <dependency>
             <groupId>org.apache.nifi</groupId>
             <artifactId>nifi-web-content-access</artifactId>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/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 5855e6d..e7def77 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
@@ -18,17 +18,14 @@ package org.apache.nifi.web;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Map;
 import javax.servlet.RequestDispatcher;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,8 +37,6 @@ public class ContentViewerController extends HttpServlet {
 
     private static final Logger logger = LoggerFactory.getLogger(ContentViewerController.class);
     
-    private static final String CONTENT_REQUEST_ATTRIBUTE = "org.apache.nifi.web.content";
-    
     // context for accessing the extension mapping
 //    private ServletContext servletContext;
 //
@@ -59,13 +54,33 @@ public class ContentViewerController extends HttpServlet {
      * @throws IOException if an I/O error occurs
      */
     @Override
-    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+    protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
         logger.info(request.getServletPath());
         
         // get the content
         final ServletContext servletContext = request.getServletContext();
         final ContentAccess contentAccess = (ContentAccess) servletContext.getAttribute("nifi-content-access");
-        final DownloadableContent downloadableContent = contentAccess.getContent(request.getParameter("ref"));
+        final DownloadableContent downloadableContent = contentAccess.getContent(new ContentRequestContext() {
+            @Override
+            public String getDataUri() {
+                return request.getParameter("ref");
+            }
+
+            @Override
+            public String getClusterNodeId() {
+                return request.getParameter("clusterNodeId");
+            }
+
+            @Override
+            public String getClientId() {
+                return request.getParameter("clientId");
+            }
+
+            @Override
+            public String getProxiedEntitiesChain() {
+                return request.getHeader("X-ProxiedEntitiesChain");
+            }
+        });
         
         // ensure the content is found
         if (downloadableContent == null) {
@@ -75,7 +90,7 @@ public class ContentViewerController extends HttpServlet {
         // detect the content type
         
         // lookup a viewer for the content
-        final String contentViewerUri = servletContext.getInitParameter("application/xml");
+        final String contentViewerUri = servletContext.getInitParameter("application/json");
         
         // handle no viewer for content type
         if (contentViewerUri == null) {
@@ -87,7 +102,7 @@ public class ContentViewerController extends HttpServlet {
         header.include(request, response);
         
         // create a request attribute for accessing the content
-        request.setAttribute(CONTENT_REQUEST_ATTRIBUTE, new ViewableContent() {
+        request.setAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE, new ViewableContent() {
             @Override
             public InputStream getContent() {
                 return downloadableContent.getContent();
@@ -97,6 +112,11 @@ public class ContentViewerController extends HttpServlet {
             public String getFileName() {
                 return downloadableContent.getFilename();
             }
+
+            @Override
+            public String getContentType() {
+                return downloadableContent.getType();
+            }
         });
         
         // generate the content
@@ -105,7 +125,7 @@ public class ContentViewerController extends HttpServlet {
         content.include(request, response);
         
         // remove the request attribute
-        request.removeAttribute(CONTENT_REQUEST_ATTRIBUTE);
+        request.removeAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE);
         
         // generate footer
         final RequestDispatcher footer = request.getRequestDispatcher("/WEB-INF/jsp/footer.jsp");

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml
index 2cd9c34..4025ff0 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/pom.xml
@@ -28,6 +28,14 @@
             <artifactId>commons-lang3</artifactId>
         </dependency>
         <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-api</artifactId>
+        </dependency>
+        <dependency>
             <groupId>javax.servlet.jsp</groupId>
             <artifactId>javax.servlet.jsp-api</artifactId>
             <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java
index 8648539..0988f53 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java
@@ -17,6 +17,7 @@
 package org.apache.nifi.web;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -25,6 +26,7 @@ import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.io.IOUtils;
 
 /**
  *
@@ -41,10 +43,15 @@ public class StandardContentViewerController extends HttpServlet {
      */
     @Override
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-//        final ExtensionMapping extensionMappings = (ExtensionMapping) servletContext.getAttribute("nifi-extension-mapping");
-
-        // forward appropriately
-        request.getRequestDispatcher("/WEB-INF/jsp/content.jsp").include(request, response);
+        
+        final ViewableContent content = (ViewableContent) request.getAttribute(ViewableContent.CONTENT_REQUEST_ATTRIBUTE);
+        
+        // handle json/xml
+        if ("application/json".equals(content.getContentType()) || "application/xml".equals(content.getContentType())) {
+            request.setAttribute("content", IOUtils.toString(content.getContent(), StandardCharsets.UTF_8));
+            request.getRequestDispatcher("/WEB-INF/jsp/codemirror.jsp").include(request, response);
+        } 
+        
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/WEB-INF/jsp/codemirror.jsp
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/WEB-INF/jsp/codemirror.jsp b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/WEB-INF/jsp/codemirror.jsp
new file mode 100644
index 0000000..5f73d47
--- /dev/null
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/WEB-INF/jsp/codemirror.jsp
@@ -0,0 +1,18 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+--%>
+<%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %>
+<p>${content}</p>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/bd9ef843/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/WEB-INF/jsp/content.jsp
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/WEB-INF/jsp/content.jsp b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/WEB-INF/jsp/content.jsp
deleted file mode 100644
index adabebd..0000000
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/webapp/WEB-INF/jsp/content.jsp
+++ /dev/null
@@ -1,18 +0,0 @@
-<%--
- Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
---%>
-<%@ page contentType="text/html" pageEncoding="UTF-8" session="false" %>
-<p>This is the content rendered...</p>
\ No newline at end of file