View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.catalog.config;
18  
19  import org.apache.logging.log4j.LogManager;
20  import org.apache.logging.log4j.Logger;
21  import org.apache.logging.log4j.catalog.api.util.ProfileUtil;
22  import org.springframework.boot.web.servlet.ServletContextInitializer;
23  import org.springframework.context.annotation.Bean;
24  import org.springframework.context.annotation.Configuration;
25  import org.springframework.web.WebApplicationInitializer;
26  import org.springframework.web.context.ContextLoaderListener;
27  import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
28  import org.springframework.web.servlet.DispatcherServlet;
29  
30  import javax.servlet.ServletContext;
31  import javax.servlet.ServletException;
32  import javax.servlet.ServletRegistration;
33  
34  public class WebAppInitializer {
35      private static final String APPLICATION_NAME = "AuditCatalog";
36      private static Logger LOGGER = LogManager.getLogger(WebAppInitializer.class);
37  
38      @Bean
39      public ServletContextInitializer initializer() {
40          return new ServletContextInitializer() {
41  
42              @Override
43              public void onStartup(ServletContext servletContext) throws ServletException {
44                  LOGGER.info("Starting Audit Catalog Editor");
45                  servletContext.setInitParameter("applicationName", APPLICATION_NAME);
46                  ProfileUtil.setActiveProfile(servletContext);
47                  servletContext.setInitParameter("isEmbedded", "true");
48                  System.setProperty("applicationName", APPLICATION_NAME);
49                  //AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
50                  //rootContext.setDisplayName(APPLICATION_NAME);
51                  //rootContext.register(WebMvcAppContext.class);
52                  //servletContext.addListener(new ContextLoaderListener(rootContext));
53  
54                  //ServletRegistration.Dynamic restServlet = servletContext.addServlet("dispatcherServlet", new DispatcherServlet(rootContext));
55                  //restServlet.setLoadOnStartup(1);
56                  //restServlet.addMapping("/*");
57              }
58          };
59      }
60  }