[ 
https://issues.apache.org/jira/browse/ARTEMIS-3808?focusedWorklogId=769521&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-769521
 ]

ASF GitHub Bot logged work on ARTEMIS-3808:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/May/22 10:15
            Start Date: 12/May/22 10:15
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on code in PR #4061:
URL: https://github.com/apache/activemq-artemis/pull/4061#discussion_r871120191


##########
artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java:
##########
@@ -193,87 +203,97 @@ public void configure(ComponentDTO config, String 
artemisInstance, String artemi
       instanceContext.setResourceBase(instanceWarDir.toString());
       instanceContext.setHandler(instanceResourceHandler);
       instanceContext.setVirtualHosts(virtualHosts);
-      
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", 
"false");
+      homeContext.setInitParameter(DIR_ALLOWED, "false");
 
       DefaultHandler defaultHandler = new DefaultHandler();
       defaultHandler.setServeIcon(false);
 
-      if (webServerConfig.requestLog != null) {
+      if (this.config.requestLog != null) {
          handlers.addHandler(getLogHandler());
       }
       handlers.addHandler(homeContext);
       handlers.addHandler(instanceContext);
       handlers.addHandler(defaultHandler); // this should be last
 
       server.setHandler(handlers);
-   }
 
-   private RequestLogHandler getLogHandler() {
-      RequestLogWriter requestLogWriter = new RequestLogWriter();
-      CustomRequestLog requestLog;
+      cleanupTmp();
+      server.start();
 
-      // required via config so no check necessary
-      requestLogWriter.setFilename(webServerConfig.requestLog.filename);
+      ActiveMQWebLogger.LOGGER.webserverStarted(bindings
+                                                   .stream()
+                                                   .map(binding -> binding.uri)
+                                                   
.collect(Collectors.joining(", ")));
 
-      if (webServerConfig.requestLog.append != null) {
-         requestLogWriter.setAppend(webServerConfig.requestLog.append);
-      }
+      ActiveMQWebLogger.LOGGER.jolokiaAvailable(String.join(", ", 
jolokiaUrls));
+      ActiveMQWebLogger.LOGGER.consoleAvailable(String.join(", ", 
consoleUrls));
+   }
 
-      if (webServerConfig.requestLog.filenameDateFormat != null) {
-         
requestLogWriter.setFilenameDateFormat(webServerConfig.requestLog.filenameDateFormat);
-      }
+   private ServerConnector createServerConnector(HttpConfiguration 
httpConfiguration,
+                                              int i,
+                                              BindingDTO binding,
+                                              URI uri,
+                                              String scheme) throws Exception {
+      ServerConnector connector;
 
-      if (webServerConfig.requestLog.retainDays != null) {
-         requestLogWriter.setRetainDays(webServerConfig.requestLog.retainDays);
-      }
+      if ("https".equals(scheme)) {
+         SslContextFactory.Server sslFactory = new SslContextFactory.Server();
+         sslFactory.setKeyStorePath(binding.keyStorePath == null ? 
artemisInstance + "/etc/keystore.jks" : binding.keyStorePath);
+         sslFactory.setKeyStorePassword(binding.getKeyStorePassword() == null 
? "password" : binding.getKeyStorePassword());
 
-      if (webServerConfig.requestLog.format != null) {
-         requestLog = new CustomRequestLog(requestLogWriter, 
webServerConfig.requestLog.format);
-      } else if (webServerConfig.requestLog.extended != null && 
webServerConfig.requestLog.extended) {
-         requestLog = new CustomRequestLog(requestLogWriter, 
CustomRequestLog.EXTENDED_NCSA_FORMAT);
-      } else {
-         requestLog = new CustomRequestLog(requestLogWriter, 
CustomRequestLog.NCSA_FORMAT);
-      }
-
-      if (webServerConfig.requestLog.ignorePaths != null && 
webServerConfig.requestLog.ignorePaths.length() > 0) {
-         String[] split = webServerConfig.requestLog.ignorePaths.split(",");
-         String[] ignorePaths = new String[split.length];
-         for (int i = 0; i < ignorePaths.length; i++) {
-            ignorePaths[i] = split[i].trim();
+         if (binding.getIncludedTLSProtocols() != null) {
+            sslFactory.setIncludeProtocols(binding.getIncludedTLSProtocols());
+         }
+         if (binding.getExcludedTLSProtocols() != null) {
+            sslFactory.setExcludeProtocols(binding.getExcludedTLSProtocols());
+         }
+         if (binding.getIncludedCipherSuites() != null) {
+            
sslFactory.setIncludeCipherSuites(binding.getIncludedCipherSuites());
+         }
+         if (binding.getExcludedCipherSuites() != null) {
+            
sslFactory.setExcludeCipherSuites(binding.getExcludedCipherSuites());
+         }
+         if (binding.clientAuth != null) {
+            sslFactory.setNeedClientAuth(binding.clientAuth);
+            if (binding.clientAuth) {
+               sslFactory.setTrustStorePath(binding.trustStorePath);
+               
sslFactory.setTrustStorePassword(binding.getTrustStorePassword());
+            }
          }
-         requestLog.setIgnorePaths(ignorePaths);
-      }
 
-      RequestLogHandler requestLogHandler = new RequestLogHandler();
-      requestLogHandler.setRequestLog(requestLog);
-      return requestLogHandler;
-   }
+         SslConnectionFactory sslConnectionFactory = new 
SslConnectionFactory(sslFactory, "HTTP/1.1");
 
-   @Override
-   public void start() throws Exception {
-      if (isStarted()) {
-         return;
-      }
-      cleanupTmp();
-      server.start();
+         httpConfiguration.addCustomizer(new SecureRequestCustomizer());
+         httpConfiguration.setSendServerVersion(false);
+         HttpConnectionFactory httpFactory = new 
HttpConnectionFactory(httpConfiguration);
 
-      String bindings = webServerConfig.getBindings()
-            .stream()
-            .map(binding -> binding.uri)
-            .collect(Collectors.joining(", "));
-      ActiveMQWebLogger.LOGGER.webserverStarted(bindings);
+         connector = new ServerConnector(server, sslConnectionFactory, 
httpFactory);
 
-      ActiveMQWebLogger.LOGGER.jolokiaAvailable(String.join(", ", 
jolokiaUrls));
-      ActiveMQWebLogger.LOGGER.consoleAvailable(String.join(", ", 
consoleUrls));
+      } else {
+         httpConfiguration.setSendServerVersion(false);
+         ConnectionFactory connectionFactory = new 
HttpConnectionFactory(httpConfiguration);
+         connector = new ServerConnector(server, connectionFactory);
+      }
+      connector.setPort(uri.getPort());
+      connector.setHost(uri.getHost());
+      connector.setName("Connector-" + i);
+      return connector;
    }
 
    public void internalStop() throws Exception {
+      ActiveMQWebLogger.LOGGER.stoppingEmbeddedWebServer();
+      System.out.println("Stopping...");

Review Comment:
   Leftover System.out.println ?



##########
artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java:
##########
@@ -53,115 +54,122 @@
 import org.eclipse.jetty.webapp.WebAppContext;
 import org.jboss.logging.Logger;
 
-public class WebServerComponent implements ExternalComponent {
+public class WebServerComponent implements ExternalComponent, 
WebServerComponentMarker {
 
    private static final Logger logger = 
Logger.getLogger(WebServerComponent.class);
+   public static final String DIR_ALLOWED = 
"org.eclipse.jetty.servlet.Default.dirAllowed";
 
    private Server server;
    private HandlerList handlers;
-   private WebServerDTO webServerConfig;
+   private WebServerDTO config;
    private final List<String> consoleUrls = new ArrayList<>();
    private final List<String> jolokiaUrls = new ArrayList<>();
-   private List<WebAppContext> webContexts;
+   private List<WebAppContext> webContexts = new ArrayList<>();;

Review Comment:
   Could it also be final if it is never nulled/recreated now.



##########
artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java:
##########
@@ -193,87 +203,97 @@ public void configure(ComponentDTO config, String 
artemisInstance, String artemi
       instanceContext.setResourceBase(instanceWarDir.toString());
       instanceContext.setHandler(instanceResourceHandler);
       instanceContext.setVirtualHosts(virtualHosts);
-      
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", 
"false");
+      homeContext.setInitParameter(DIR_ALLOWED, "false");
 
       DefaultHandler defaultHandler = new DefaultHandler();
       defaultHandler.setServeIcon(false);
 
-      if (webServerConfig.requestLog != null) {
+      if (this.config.requestLog != null) {
          handlers.addHandler(getLogHandler());
       }
       handlers.addHandler(homeContext);
       handlers.addHandler(instanceContext);
       handlers.addHandler(defaultHandler); // this should be last
 
       server.setHandler(handlers);
-   }
 
-   private RequestLogHandler getLogHandler() {
-      RequestLogWriter requestLogWriter = new RequestLogWriter();
-      CustomRequestLog requestLog;
+      cleanupTmp();
+      server.start();
 
-      // required via config so no check necessary
-      requestLogWriter.setFilename(webServerConfig.requestLog.filename);
+      ActiveMQWebLogger.LOGGER.webserverStarted(bindings
+                                                   .stream()
+                                                   .map(binding -> binding.uri)
+                                                   
.collect(Collectors.joining(", ")));
 
-      if (webServerConfig.requestLog.append != null) {
-         requestLogWriter.setAppend(webServerConfig.requestLog.append);
-      }
+      ActiveMQWebLogger.LOGGER.jolokiaAvailable(String.join(", ", 
jolokiaUrls));
+      ActiveMQWebLogger.LOGGER.consoleAvailable(String.join(", ", 
consoleUrls));
+   }
 
-      if (webServerConfig.requestLog.filenameDateFormat != null) {
-         
requestLogWriter.setFilenameDateFormat(webServerConfig.requestLog.filenameDateFormat);
-      }
+   private ServerConnector createServerConnector(HttpConfiguration 
httpConfiguration,
+                                              int i,
+                                              BindingDTO binding,
+                                              URI uri,
+                                              String scheme) throws Exception {
+      ServerConnector connector;
 
-      if (webServerConfig.requestLog.retainDays != null) {
-         requestLogWriter.setRetainDays(webServerConfig.requestLog.retainDays);
-      }
+      if ("https".equals(scheme)) {
+         SslContextFactory.Server sslFactory = new SslContextFactory.Server();
+         sslFactory.setKeyStorePath(binding.keyStorePath == null ? 
artemisInstance + "/etc/keystore.jks" : binding.keyStorePath);
+         sslFactory.setKeyStorePassword(binding.getKeyStorePassword() == null 
? "password" : binding.getKeyStorePassword());
 
-      if (webServerConfig.requestLog.format != null) {
-         requestLog = new CustomRequestLog(requestLogWriter, 
webServerConfig.requestLog.format);
-      } else if (webServerConfig.requestLog.extended != null && 
webServerConfig.requestLog.extended) {
-         requestLog = new CustomRequestLog(requestLogWriter, 
CustomRequestLog.EXTENDED_NCSA_FORMAT);
-      } else {
-         requestLog = new CustomRequestLog(requestLogWriter, 
CustomRequestLog.NCSA_FORMAT);
-      }
-
-      if (webServerConfig.requestLog.ignorePaths != null && 
webServerConfig.requestLog.ignorePaths.length() > 0) {
-         String[] split = webServerConfig.requestLog.ignorePaths.split(",");
-         String[] ignorePaths = new String[split.length];
-         for (int i = 0; i < ignorePaths.length; i++) {
-            ignorePaths[i] = split[i].trim();
+         if (binding.getIncludedTLSProtocols() != null) {
+            sslFactory.setIncludeProtocols(binding.getIncludedTLSProtocols());
+         }
+         if (binding.getExcludedTLSProtocols() != null) {
+            sslFactory.setExcludeProtocols(binding.getExcludedTLSProtocols());
+         }
+         if (binding.getIncludedCipherSuites() != null) {
+            
sslFactory.setIncludeCipherSuites(binding.getIncludedCipherSuites());
+         }
+         if (binding.getExcludedCipherSuites() != null) {
+            
sslFactory.setExcludeCipherSuites(binding.getExcludedCipherSuites());
+         }
+         if (binding.clientAuth != null) {
+            sslFactory.setNeedClientAuth(binding.clientAuth);
+            if (binding.clientAuth) {
+               sslFactory.setTrustStorePath(binding.trustStorePath);
+               
sslFactory.setTrustStorePassword(binding.getTrustStorePassword());
+            }
          }
-         requestLog.setIgnorePaths(ignorePaths);
-      }
 
-      RequestLogHandler requestLogHandler = new RequestLogHandler();
-      requestLogHandler.setRequestLog(requestLog);
-      return requestLogHandler;
-   }
+         SslConnectionFactory sslConnectionFactory = new 
SslConnectionFactory(sslFactory, "HTTP/1.1");
 
-   @Override
-   public void start() throws Exception {
-      if (isStarted()) {
-         return;
-      }
-      cleanupTmp();
-      server.start();
+         httpConfiguration.addCustomizer(new SecureRequestCustomizer());
+         httpConfiguration.setSendServerVersion(false);
+         HttpConnectionFactory httpFactory = new 
HttpConnectionFactory(httpConfiguration);
 
-      String bindings = webServerConfig.getBindings()
-            .stream()
-            .map(binding -> binding.uri)
-            .collect(Collectors.joining(", "));
-      ActiveMQWebLogger.LOGGER.webserverStarted(bindings);
+         connector = new ServerConnector(server, sslConnectionFactory, 
httpFactory);
 
-      ActiveMQWebLogger.LOGGER.jolokiaAvailable(String.join(", ", 
jolokiaUrls));
-      ActiveMQWebLogger.LOGGER.consoleAvailable(String.join(", ", 
consoleUrls));
+      } else {
+         httpConfiguration.setSendServerVersion(false);
+         ConnectionFactory connectionFactory = new 
HttpConnectionFactory(httpConfiguration);
+         connector = new ServerConnector(server, connectionFactory);
+      }
+      connector.setPort(uri.getPort());
+      connector.setHost(uri.getHost());
+      connector.setName("Connector-" + i);
+      return connector;
    }
 
    public void internalStop() throws Exception {
+      ActiveMQWebLogger.LOGGER.stoppingEmbeddedWebServer();
+      System.out.println("Stopping...");
       server.stop();
+      server = null;

Review Comment:
   This makes isStarted() vulnerable to NPE as it uses the value twice and isnt 
synchronized. It should either be synchronized also or changed to capture it 
once.



##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java:
##########
@@ -4479,5 +4483,45 @@ public void replay(String startScan, String endScan, 
String address, String targ
 
       server.replay(startScanDate, endScanDate, address, target, filter);
    }
+
+   @Override
+   public void stopEmbeddedWebServer() throws Exception {
+      getEmbeddedWebServerComponent().stop(true);
+   }
+
+   @Override
+   public void startEmbeddedWebServer() throws Exception {
+      getEmbeddedWebServerComponent().start();
+   }
+
+   @Override
+   public void restartEmbeddedWebServer() throws Exception {
+      /*
+       * This needs to be run in its own thread managed by the broker because 
if it is run on a thread managed by Jetty
+       * (e.g. if it is invoked from the web console) then the thread will die 
before Jetty can be restarted.
+       */
+      server.getThreadPool().execute(() -> {
+         try {
+            stopEmbeddedWebServer();
+            startEmbeddedWebServer();
+         } catch (Exception e) {
+            ActiveMQServerLogger.LOGGER.failedToRestartEmbeddedWebServer(e);
+         }
+      });
+   }
+
+   @Override
+   public boolean isEmbeddedWebServerStarted() throws Exception {
+      return getEmbeddedWebServerComponent().isStarted();
+   }

Review Comment:
   Its not clear to me this one should throw rather than just return false, and 
possibly trace log in the case it couldnt find the server.
   
   My thinking is, are there potential uses of this simple boolean property 
method that could still reasonably occur even without the web server, e.g this 
seems to be an MBean so could this be used without explicit invocation by a 
user via the JMX management even if running without it, which seems ok as it 
isnt actually part of the broker, and returning false then still seems 
reasonable?



##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java:
##########
@@ -4290,6 +4292,80 @@ public boolean isStarted() {
       }
    }
 
+   @Test
+   public void testManualStopStartEmbeddedWebServer() throws Exception {
+      testStartStopEmbeddedWebServer(true);
+   }
+
+   @Test
+   public void testRestartEmbeddedWebServer() throws Exception {
+      testStartStopEmbeddedWebServer(false);
+   }
+
+   private void testStartStopEmbeddedWebServer(boolean manual) throws 
Exception {
+      class Fake implements ServiceComponent, WebServerComponentMarker {
+         boolean started = false;
+         long startTime = 0;
+         long stopTime = 0;

Review Comment:
   As these are being used by different threads they should be volatile or 
their use synchronized like the real component.



##########
artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java:
##########
@@ -53,115 +54,122 @@
 import org.eclipse.jetty.webapp.WebAppContext;
 import org.jboss.logging.Logger;
 
-public class WebServerComponent implements ExternalComponent {
+public class WebServerComponent implements ExternalComponent, 
WebServerComponentMarker {
 
    private static final Logger logger = 
Logger.getLogger(WebServerComponent.class);
+   public static final String DIR_ALLOWED = 
"org.eclipse.jetty.servlet.Default.dirAllowed";
 
    private Server server;
    private HandlerList handlers;
-   private WebServerDTO webServerConfig;
+   private WebServerDTO config;
    private final List<String> consoleUrls = new ArrayList<>();
    private final List<String> jolokiaUrls = new ArrayList<>();
-   private List<WebAppContext> webContexts;
+   private List<WebAppContext> webContexts = new ArrayList<>();;
    private ServerConnector[] connectors;
    private Path artemisHomePath;
    private Path temporaryWarDir;
+   private String artemisInstance;
+   private String artemisHome;
 
    @Override
    public void configure(ComponentDTO config, String artemisInstance, String 
artemisHome) throws Exception {
-      webServerConfig = (WebServerDTO) config;
-      server = new Server();
-
-      HttpConfiguration httpConfiguration = new HttpConfiguration();
+      this.config = (WebServerDTO) config;
+      this.artemisInstance = artemisInstance;
+      this.artemisHome = artemisHome;
 
-      if (webServerConfig.customizer != null) {
-         try {
-            httpConfiguration.addCustomizer((HttpConfiguration.Customizer) 
Class.forName(webServerConfig.customizer).getConstructor().newInstance());
-         } catch (Throwable t) {
-            
ActiveMQWebLogger.LOGGER.customizerNotLoaded(webServerConfig.customizer, t);
-         }
+      temporaryWarDir = Paths.get(artemisInstance != null ? artemisInstance : 
".").resolve("tmp").resolve("webapps").toAbsolutePath();
+      if (!Files.exists(temporaryWarDir)) {
+         Files.createDirectories(temporaryWarDir);
       }
+   }
 
-      List<BindingDTO> bindings = webServerConfig.getBindings();
-      connectors = new ServerConnector[bindings.size()];
-      String[] virtualHosts = new String[bindings.size()];
-
-      for (int i = 0; i < bindings.size(); i++) {
-         BindingDTO binding = bindings.get(i);
-         URI uri = new URI(binding.uri);
-         String scheme = uri.getScheme();
-         ServerConnector connector;
+   private RequestLogHandler getLogHandler() {

Review Comment:
   The diff seems like it could perhaps be a smaller and more easily 
understandable if this methods ~40 lines hadnt all moved at the same time as 
the other 'actual changes' in the same area...does it actually need to?



##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java:
##########
@@ -4479,5 +4483,45 @@ public void replay(String startScan, String endScan, 
String address, String targ
 
       server.replay(startScanDate, endScanDate, address, target, filter);
    }
+
+   @Override
+   public void stopEmbeddedWebServer() throws Exception {
+      getEmbeddedWebServerComponent().stop(true);
+   }
+
+   @Override
+   public void startEmbeddedWebServer() throws Exception {
+      getEmbeddedWebServerComponent().start();
+   }
+
+   @Override
+   public void restartEmbeddedWebServer() throws Exception {
+      /*
+       * This needs to be run in its own thread managed by the broker because 
if it is run on a thread managed by Jetty
+       * (e.g. if it is invoked from the web console) then the thread will die 
before Jetty can be restarted.
+       */
+      server.getThreadPool().execute(() -> {
+         try {
+            stopEmbeddedWebServer();
+            startEmbeddedWebServer();

Review Comment:
   Thinking about this more I still think these need coordinated here in some 
way. If I call restart, and then I immediately call stop from the same thread, 
the webserver should end up stopped. As this is now, because they are handled 
in different threads it seems just as likely it will end up [re]started instead.
   
   Regardless of approach taken to addressing that, it feels like maybe it 
should even also await the operation being completed for some period before 
returning. It could even throw on failure like start and stop would.



##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java:
##########
@@ -4290,6 +4292,80 @@ public boolean isStarted() {
       }
    }
 
+   @Test
+   public void testManualStopStartEmbeddedWebServer() throws Exception {
+      testStartStopEmbeddedWebServer(true);
+   }
+
+   @Test
+   public void testRestartEmbeddedWebServer() throws Exception {
+      testStartStopEmbeddedWebServer(false);
+   }
+
+   private void testStartStopEmbeddedWebServer(boolean manual) throws 
Exception {
+      class Fake implements ServiceComponent, WebServerComponentMarker {
+         boolean started = false;
+         long startTime = 0;
+         long stopTime = 0;
+
+         @Override
+         public void start() throws Exception {
+            if (started) {
+               return;
+            }
+            started = true;
+            startTime = System.currentTimeMillis();
+         }
+
+         @Override
+         public void stop() throws Exception {
+         }
+
+         @Override
+         public void stop(boolean shutdown) throws Exception {
+            if (!shutdown) {
+               throw new RuntimeException("shutdown flag must be true");
+            }
+            started = false;
+            stopTime = System.currentTimeMillis();
+         }
+
+         @Override
+         public boolean isStarted() {
+            return started;
+         }
+
+         public long getStartTime() {
+            return startTime;
+         }
+
+         public long getStopTime() {
+            return startTime;
+         }
+      }
+      Fake fake = new Fake();
+      server.addExternalComponent(fake, true);
+      Assert.assertTrue(fake.isStarted());
+
+      ActiveMQServerControl serverControl = createManagementControl();
+      if (manual) {
+         serverControl.stopEmbeddedWebServer();
+         Assert.assertFalse(fake.isStarted());
+         serverControl.startEmbeddedWebServer();
+         Assert.assertTrue(fake.isStarted());
+      } else {
+         // this is technically async so need to do some gymnastics to test 
effectively
+         long time = System.currentTimeMillis();
+         Thread.sleep(5);
+         Assert.assertTrue(time > fake.getStartTime());
+         Assert.assertTrue(time > fake.getStopTime());
+         serverControl.restartEmbeddedWebServer();
+         Wait.assertTrue(() -> time < fake.getStopTime(), 5000, 100);
+         Wait.assertTrue(() -> serverControl.isEmbeddedWebServerStarted(), 
5000, 100);

Review Comment:
   Shouldnt there be a tiny sleep before getting currentTimeMillis, helping 
ensure the 'time' is definitely later than the prior startTime. Its likely to 
be already, but doesnt seem guaranteed. The second sleep would then seem better 
placed just before the restart is called since its there to influence the times 
from that.
   
   Alternatively, rather than having any sleeps, you could just reset the Fake 
components variable to 0 and just track they got updated by it changing from 0 
again.
   
   The 100ms recheck period seems quite slow. Unless its known to be glacially 
slow I'd go with something more granular, e.g 10ms.



##########
artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java:
##########
@@ -193,87 +203,97 @@ public void configure(ComponentDTO config, String 
artemisInstance, String artemi
       instanceContext.setResourceBase(instanceWarDir.toString());
       instanceContext.setHandler(instanceResourceHandler);
       instanceContext.setVirtualHosts(virtualHosts);
-      
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", 
"false");
+      homeContext.setInitParameter(DIR_ALLOWED, "false");
 
       DefaultHandler defaultHandler = new DefaultHandler();
       defaultHandler.setServeIcon(false);
 
-      if (webServerConfig.requestLog != null) {
+      if (this.config.requestLog != null) {
          handlers.addHandler(getLogHandler());
       }
       handlers.addHandler(homeContext);
       handlers.addHandler(instanceContext);
       handlers.addHandler(defaultHandler); // this should be last
 
       server.setHandler(handlers);
-   }
 
-   private RequestLogHandler getLogHandler() {
-      RequestLogWriter requestLogWriter = new RequestLogWriter();
-      CustomRequestLog requestLog;
+      cleanupTmp();
+      server.start();
 
-      // required via config so no check necessary
-      requestLogWriter.setFilename(webServerConfig.requestLog.filename);
+      ActiveMQWebLogger.LOGGER.webserverStarted(bindings
+                                                   .stream()
+                                                   .map(binding -> binding.uri)
+                                                   
.collect(Collectors.joining(", ")));
 
-      if (webServerConfig.requestLog.append != null) {
-         requestLogWriter.setAppend(webServerConfig.requestLog.append);
-      }
+      ActiveMQWebLogger.LOGGER.jolokiaAvailable(String.join(", ", 
jolokiaUrls));
+      ActiveMQWebLogger.LOGGER.consoleAvailable(String.join(", ", 
consoleUrls));
+   }
 
-      if (webServerConfig.requestLog.filenameDateFormat != null) {
-         
requestLogWriter.setFilenameDateFormat(webServerConfig.requestLog.filenameDateFormat);
-      }
+   private ServerConnector createServerConnector(HttpConfiguration 
httpConfiguration,
+                                              int i,
+                                              BindingDTO binding,
+                                              URI uri,
+                                              String scheme) throws Exception {
+      ServerConnector connector;
 
-      if (webServerConfig.requestLog.retainDays != null) {
-         requestLogWriter.setRetainDays(webServerConfig.requestLog.retainDays);
-      }
+      if ("https".equals(scheme)) {
+         SslContextFactory.Server sslFactory = new SslContextFactory.Server();
+         sslFactory.setKeyStorePath(binding.keyStorePath == null ? 
artemisInstance + "/etc/keystore.jks" : binding.keyStorePath);
+         sslFactory.setKeyStorePassword(binding.getKeyStorePassword() == null 
? "password" : binding.getKeyStorePassword());
 
-      if (webServerConfig.requestLog.format != null) {
-         requestLog = new CustomRequestLog(requestLogWriter, 
webServerConfig.requestLog.format);
-      } else if (webServerConfig.requestLog.extended != null && 
webServerConfig.requestLog.extended) {
-         requestLog = new CustomRequestLog(requestLogWriter, 
CustomRequestLog.EXTENDED_NCSA_FORMAT);
-      } else {
-         requestLog = new CustomRequestLog(requestLogWriter, 
CustomRequestLog.NCSA_FORMAT);
-      }
-
-      if (webServerConfig.requestLog.ignorePaths != null && 
webServerConfig.requestLog.ignorePaths.length() > 0) {
-         String[] split = webServerConfig.requestLog.ignorePaths.split(",");
-         String[] ignorePaths = new String[split.length];
-         for (int i = 0; i < ignorePaths.length; i++) {
-            ignorePaths[i] = split[i].trim();
+         if (binding.getIncludedTLSProtocols() != null) {
+            sslFactory.setIncludeProtocols(binding.getIncludedTLSProtocols());
+         }
+         if (binding.getExcludedTLSProtocols() != null) {
+            sslFactory.setExcludeProtocols(binding.getExcludedTLSProtocols());
+         }
+         if (binding.getIncludedCipherSuites() != null) {
+            
sslFactory.setIncludeCipherSuites(binding.getIncludedCipherSuites());
+         }
+         if (binding.getExcludedCipherSuites() != null) {
+            
sslFactory.setExcludeCipherSuites(binding.getExcludedCipherSuites());
+         }
+         if (binding.clientAuth != null) {
+            sslFactory.setNeedClientAuth(binding.clientAuth);
+            if (binding.clientAuth) {
+               sslFactory.setTrustStorePath(binding.trustStorePath);
+               
sslFactory.setTrustStorePassword(binding.getTrustStorePassword());
+            }
          }
-         requestLog.setIgnorePaths(ignorePaths);
-      }
 
-      RequestLogHandler requestLogHandler = new RequestLogHandler();
-      requestLogHandler.setRequestLog(requestLog);
-      return requestLogHandler;
-   }
+         SslConnectionFactory sslConnectionFactory = new 
SslConnectionFactory(sslFactory, "HTTP/1.1");
 
-   @Override
-   public void start() throws Exception {
-      if (isStarted()) {
-         return;
-      }
-      cleanupTmp();
-      server.start();
+         httpConfiguration.addCustomizer(new SecureRequestCustomizer());
+         httpConfiguration.setSendServerVersion(false);
+         HttpConnectionFactory httpFactory = new 
HttpConnectionFactory(httpConfiguration);
 
-      String bindings = webServerConfig.getBindings()
-            .stream()
-            .map(binding -> binding.uri)
-            .collect(Collectors.joining(", "));
-      ActiveMQWebLogger.LOGGER.webserverStarted(bindings);
+         connector = new ServerConnector(server, sslConnectionFactory, 
httpFactory);
 
-      ActiveMQWebLogger.LOGGER.jolokiaAvailable(String.join(", ", 
jolokiaUrls));
-      ActiveMQWebLogger.LOGGER.consoleAvailable(String.join(", ", 
consoleUrls));
+      } else {
+         httpConfiguration.setSendServerVersion(false);
+         ConnectionFactory connectionFactory = new 
HttpConnectionFactory(httpConfiguration);
+         connector = new ServerConnector(server, connectionFactory);
+      }
+      connector.setPort(uri.getPort());
+      connector.setHost(uri.getHost());
+      connector.setName("Connector-" + i);
+      return connector;
    }
 
    public void internalStop() throws Exception {
+      ActiveMQWebLogger.LOGGER.stoppingEmbeddedWebServer();

Review Comment:
   This comment is actually for the line above the logger, the internalStop() 
method seems like it should be private.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 769521)
    Time Spent: 3h 20m  (was: 3h 10m)

> Support starting/stopping the embedded web server via mangement
> ---------------------------------------------------------------
>
>                 Key: ARTEMIS-3808
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-3808
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>          Time Spent: 3h 20m
>  Remaining Estimate: 0h
>
> It would be useful to be able to cycle the embedded web server if, for 
> example, one needed to renew the SSL certificates.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to