diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java index 6ce7cb4f8d..70f2cecf34 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java @@ -43,15 +43,18 @@ public class ApplicationStartupContextListener implements ServletContextListener private static final Logger logger = LoggerFactory.getLogger(ApplicationStartupContextListener.class); + private FlowController flowController = null; + private FlowService flowService = null; + private RequestReplicator requestReplicator = null; + @Override public void contextInitialized(ServletContextEvent sce) { - - ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); - NiFiProperties properties = ctx.getBean("nifiProperties", NiFiProperties.class); - FlowService flowService = null; + final ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); + final NiFiProperties properties = ctx.getBean("nifiProperties", NiFiProperties.class); try { flowService = ctx.getBean("flowService", FlowService.class); - final FlowController flowController = ctx.getBean("flowController", FlowController.class); + flowController = ctx.getBean("flowController", FlowController.class); + requestReplicator = ctx.getBean("requestReplicator", RequestReplicator.class); // start and load the flow if we're not clustered (clustered flow loading should // happen once the application (wars) is fully loaded and initialized). non clustered @@ -81,7 +84,7 @@ public class ApplicationStartupContextListener implements ServletContextListener logger.info("Flow Controller started successfully."); } } catch (BeansException | RepositoryPurgeException | IOException e) { - shutdown(flowService, ctx.getBean("requestReplicator", RequestReplicator.class)); + shutdown(); throw new NiFiCoreException("Unable to start Flow Controller.", e); } @@ -90,21 +93,19 @@ public class ApplicationStartupContextListener implements ServletContextListener ctx.getBean("loginIdentityProvider", LoginIdentityProvider.class); ctx.getBean("authorizer", Authorizer.class); } catch (final BeansException e) { - shutdown(flowService, ctx.getBean("requestReplicator", RequestReplicator.class)); + shutdown(); throw new NiFiCoreException("Unable to start Flow Controller.", e); } } @Override public void contextDestroyed(ServletContextEvent sce) { - ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); - logger.info("Initiating shutdown of flow service..."); - shutdown(ctx.getBean("flowService", FlowService.class), ctx.getBean("requestReplicator", RequestReplicator.class)); + shutdown(); logger.info("Flow service termination completed."); } - private void shutdown(final FlowService flowService, final RequestReplicator requestReplicator) { + private void shutdown() { try { // ensure the flow service is terminated if (flowService != null && flowService.isRunning()) {