exceptionfactory commented on a change in pull request #4603:
URL: https://github.com/apache/nifi/pull/4603#discussion_r506781064



##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/HealthCheckServlet.java
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.processors.standard.servlets;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.Path;
+import java.io.IOException;
+
+@Path("/healthcheck")
+public class HealthCheckServlet extends HttpServlet {
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+        response.setStatus(HttpServletResponse.SC_OK);

Review comment:
       When returning a successful empty response, HTTP 204 No Content would be 
a more precise response code than HTTP 200.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenHTTP.java
##########
@@ -351,6 +372,60 @@ synchronized private void 
createHttpServerFromService(final ProcessContext conte
         initialized.set(true);
     }
 
+    private ServerConnector createServerConnector(Server server, int port, 
SSLContextService sslContextService, boolean sslRequired, boolean 
needClientAuth) {
+        final SslContextFactory contextFactory = 
createSslContextFactory(sslContextService, sslRequired, needClientAuth);
+        return createServerConnector(server, port, contextFactory, 
sslRequired);
+    }
+
+    private ServerConnector createServerConnector(Server server, int port, 
SslContextFactory contextFactory, boolean sslRequired) {
+        final ServerConnector connector;
+        final HttpConfiguration httpConfiguration = new HttpConfiguration();
+        if (!sslRequired) {
+            // create the connector
+            connector = new ServerConnector(server, new 
HttpConnectionFactory(httpConfiguration));
+        } else {
+            // configure the ssl connector
+            httpConfiguration.setSecureScheme("https");
+            httpConfiguration.setSecurePort(port);
+            httpConfiguration.addCustomizer(new SecureRequestCustomizer());
+
+            // build the connector
+
+            connector = new ServerConnector(server, new 
SslConnectionFactory(contextFactory, "http/1.1"), new 
HttpConnectionFactory(httpConfiguration));
+        }
+
+        // configure the port
+        connector.setPort(port);
+        return connector;
+    }
+
+    private SslContextFactory createSslContextFactory(SSLContextService 
sslContextService, boolean sslRequired, boolean needClientAuth) {
+        final SslContextFactory contextFactory = new 
SslContextFactory.Server();
+        contextFactory.setNeedClientAuth(needClientAuth);
+
+        if (needClientAuth) {
+            
contextFactory.setTrustStorePath(sslContextService.getTrustStoreFile());
+            
contextFactory.setTrustStoreType(sslContextService.getTrustStoreType());
+            
contextFactory.setTrustStorePassword(sslContextService.getTrustStorePassword());
+        }
+
+        if (sslRequired) {
+            final String keystorePassword = 
sslContextService.getKeyStorePassword();
+            final String keyStoreType = sslContextService.getKeyStoreType();
+            final String keyStorePath = sslContextService.getKeyStoreFile();
+
+            contextFactory.setKeyStorePath(keyStorePath);
+            contextFactory.setKeyManagerPassword(keystorePassword);

Review comment:
       Although this simply moves the existing implementation to a new method, 
this would be a good opportunity to set the keyManagerPassword from the 
getKeyPassword() method on SSLContextService, when configured.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/ContentAcknowledgmentServlet.java
##########
@@ -57,10 +58,17 @@ public void init(final ServletConfig config) throws 
ServletException {
         this.logger = (ComponentLog) 
context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_LOGGER);
         this.authorizedPattern = (Pattern) 
context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_AUTHORITY_PATTERN);
         this.flowFileMap = (ConcurrentMap<String, FlowFileEntryTimeWrapper>) 
context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_FLOWFILE_MAP);
+        this.port = (int) 
context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_PORT);
     }
 
     @Override
     protected void doDelete(final HttpServletRequest request, final 
HttpServletResponse response) throws ServletException, IOException {
+
+        if (request.getLocalPort() != port) {
+            super.doPost(request, response);

Review comment:
       Did you intend to call doDelete() instead of doPost()?  In either case, 
simply wrapping the rest of the method logic inside a conditional that checks 
for matching port numbers seems more straightforward.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/servlets/ListenHTTPServlet.java
##########
@@ -120,17 +121,28 @@ public void init(final ServletConfig config) throws 
ServletException {
         this.returnCode = (int) 
context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_RETURN_CODE);
         this.multipartRequestMaxSize = (long) 
context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_MULTIPART_REQUEST_MAX_SIZE);
         this.multipartReadBufferSize = (int) 
context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_MULTIPART_READ_BUFFER_SIZE);
+        this.port = (int) 
context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_PORT);
     }
 
     @Override
     protected void doHead(final HttpServletRequest request, final 
HttpServletResponse response) throws ServletException, IOException {
-        response.addHeader(ACCEPT_ENCODING_NAME, ACCEPT_ENCODING_VALUE);
-        response.addHeader(ACCEPT_HEADER_NAME, ACCEPT_HEADER_VALUE);
-        response.addHeader(PROTOCOL_VERSION_HEADER, PROTOCOL_VERSION);
+        if (request.getLocalPort() == port) {

Review comment:
       Is it necessary to check the port in this method?  Adding static headers 
in either case seems like a reasonable implementation as opposed to making them 
conditional on the requested port number.

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenHTTP.java
##########
@@ -351,6 +372,60 @@ synchronized private void 
createHttpServerFromService(final ProcessContext conte
         initialized.set(true);
     }
 
+    private ServerConnector createServerConnector(Server server, int port, 
SSLContextService sslContextService, boolean sslRequired, boolean 
needClientAuth) {
+        final SslContextFactory contextFactory = 
createSslContextFactory(sslContextService, sslRequired, needClientAuth);
+        return createServerConnector(server, port, contextFactory, 
sslRequired);
+    }
+
+    private ServerConnector createServerConnector(Server server, int port, 
SslContextFactory contextFactory, boolean sslRequired) {
+        final ServerConnector connector;
+        final HttpConfiguration httpConfiguration = new HttpConfiguration();
+        if (!sslRequired) {

Review comment:
       Changing the logic to check if (sslRequired) { ... } else { ... } would 
be more straightforward.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to