pvillard31 commented on code in PR #10012: URL: https://github.com/apache/nifi/pull/10012#discussion_r2142159898
########## nifi-extension-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/content/viewer/StandardServletContextListener.java: ########## @@ -0,0 +1,73 @@ +/* + * 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.content.viewer; + +import jakarta.servlet.DispatcherType; +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletRegistration; +import jakarta.servlet.annotation.WebListener; +import org.apache.nifi.web.controller.StandardContentViewerController; +import org.apache.nifi.web.servlet.filter.QueryStringToFragmentFilter; +import org.eclipse.jetty.ee10.servlet.DefaultServlet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.EnumSet; + +/** + * Servlet Context Listener supporting registration of Filters + */ +@WebListener +public class StandardServletContextListener implements ServletContextListener { + private static final String ALL_URLS = "/*"; + + private static final String API_CONTENT_MAPPING = "/api/content"; + + private static final int LOAD_ON_STARTUP_ENABLED = 1; + + private static final String DIR_ALLOWED_PARAMETER = "dirAllowed"; + + private static final String BASE_RESOURCE_PARAMETER = "baseResource"; + + private static final String BASE_RESOURCE_DIRECTORY = "WEB-INF/classes/static"; + + private static final String FILTER_URL = ""; + + private static final Logger logger = LoggerFactory.getLogger(StandardServletContextListener.class); + + @Override + public void contextInitialized(final ServletContextEvent sce) { + final ServletContext servletContext = sce.getServletContext(); + final FilterRegistration.Dynamic filter = servletContext.addFilter(QueryStringToFragmentFilter.class.getSimpleName(), QueryStringToFragmentFilter.class); + filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, FILTER_URL); + + final ServletRegistration.Dynamic servlet = servletContext.addServlet(StandardContentViewerController.class.getSimpleName(), StandardContentViewerController.class); + servlet.addMapping(API_CONTENT_MAPPING); + servlet.setLoadOnStartup(LOAD_ON_STARTUP_ENABLED); + + final ServletRegistration.Dynamic defaultServlet = servletContext.addServlet(DefaultServlet.class.getSimpleName(), DefaultServlet.class); Review Comment: When opening the content viewer for the first time after NiFi starts, I get this warning in the logs: ```` 2025-06-12 11:21:40,457 WARN [NiFi Web Server-138] o.e.jetty.ee10.servlet.DefaultServlet Incorrect mapping for DefaultServlet at /*. Use ResourceServlet ```` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
