Commit eb17069e authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

Removing not needed dispatchers. Tomcat now handles static content

parent d8cee7dc
Pipeline #8772 passed with stage
in 9 minutes and 45 seconds
package lcsb.mapviewer.web.config;
import java.io.InputStream;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Properties;
import java.util.*;
import javax.faces.webapp.FacesServlet;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;
......@@ -22,14 +17,12 @@ import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.DispatcherServlet;
import lcsb.mapviewer.annotation.SpringAnnotationConfig;
import lcsb.mapviewer.api.SpringRestApiConfig;
import lcsb.mapviewer.persist.SpringPersistConfig;
import lcsb.mapviewer.services.SpringServiceConfig;
import lcsb.mapviewer.web.bean.utils.CssContentTypeFilter;
import lcsb.mapviewer.web.bean.utils.JsfAjaxAccessControlAllowFilter;
import lcsb.mapviewer.web.bean.utils.XFrameAccessControlFilter;
......@@ -39,18 +32,12 @@ public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
/*
* ============ ROOT CONTEXT ============
*/
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.setDisplayName("MapViewer2");
rootContext.register(
SpringAnnotationConfig.class,
SpringPersistConfig.class,
SpringRestApiConfig.class,
SpringServiceConfig.class,
SpringWebConfig.class);
SpringServiceConfig.class);
container.addListener(new ContextLoaderListener(rootContext));
container.addListener(SessionListener.class);
......@@ -79,68 +66,15 @@ public class WebAppInitializer implements WebApplicationInitializer {
logger.error("Problem with loading log4j configuration: " + file);
}
/*
* =========== APP CONTEXT ===========
*/
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.setParent(rootContext);
ServletRegistration.Dynamic appDispatcher = container.addServlet("App Servlet", new DispatcherServlet(appContext));
appDispatcher.setLoadOnStartup(1);
appDispatcher.addMapping(
"*.css",
"*.js",
"*.gif",
"*.jpg",
"*.png",
"*.pdf",
"*.ttf",
"*.svg",
"*.eot",
"*.woff",
"*.woff2",
"/login",
"/j_spring_security_logout");
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.setParent(rootContext);
dispatcherContext.register(SpringWebConfig.class);
/*
* ============= FACES CONTEXT =============
*/
AnnotationConfigWebApplicationContext facesContext = new AnnotationConfigWebApplicationContext();
facesContext.setParent(rootContext);
ServletRegistration.Dynamic facesDispatcher = container.addServlet("Faces Servlet", new FacesServlet());
facesDispatcher.setLoadOnStartup(1);
facesDispatcher.addMapping(
"*.xhtml",
"*.jsf",
"*.faces");
ServletRegistration.Dynamic dispatcher =
container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/api/*");
/*
* ================ REST API CONTEXT ================
*/
AnnotationConfigWebApplicationContext restApiContext = new AnnotationConfigWebApplicationContext();
restApiContext.setParent(rootContext);
restApiContext.register(SpringRestApiConfig.class);
ServletRegistration.Dynamic restApiDispatcher = container.addServlet("REST API Servlet",
new DispatcherServlet(restApiContext));
restApiDispatcher.setLoadOnStartup(1);
restApiDispatcher.addMapping("/api/*");
/*
* ================ WEB CONTEXT ================
*/
AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
webContext.setParent(rootContext);
webContext.register(SpringWebConfig.class);
ServletRegistration.Dynamic webDispatcher = container.addServlet("WEB Servlet",
new DispatcherServlet(webContext));
webDispatcher.setLoadOnStartup(1);
webDispatcher.addMapping("/");
/*
* ======= FILTERS =======
*/
......@@ -151,10 +85,6 @@ public class WebAppInitializer implements WebApplicationInitializer {
fileUploadFilterReg.setInitParameter("thresholdSize", "51200");
fileUploadFilterReg.addMappingForServletNames(null, true, "Faces Servlet");
CssContentTypeFilter cssContentTypeFilter = new CssContentTypeFilter();
FilterRegistration.Dynamic cssContentTypeFilterReg = container.addFilter("cssContentTypeFix", cssContentTypeFilter);
cssContentTypeFilterReg.addMappingForUrlPatterns(null, true, "/*");
XFrameAccessControlFilter xFrameFilter = new XFrameAccessControlFilter();
FilterRegistration.Dynamic xFrameFilterReg = container.addFilter("xFrameFilter", xFrameFilter);
xFrameFilterReg.addMappingForUrlPatterns(null, true, "/*");
......@@ -164,12 +94,6 @@ public class WebAppInitializer implements WebApplicationInitializer {
jsfAjaxAccessControlAllowFilter);
jsfAjaxAccessControlAllowFilterReg.addMappingForUrlPatterns(null, true, "/*");
DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy();
FilterRegistration.Dynamic delegatingFilterProxyReg = container.addFilter("springSecurityFilterChain",
delegatingFilterProxy);
delegatingFilterProxyReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST), false,
"/*");
/*
* =============== COOKIE SETTINGS ===============
*/
......
package lcsb.mapviewer.web.controler;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/")
public class RootController {
/**
* Default class logger.
*/
private Logger logger = Logger.getLogger(RootController.class);
@RequestMapping(value = "/", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView rootPage(ModelMap model) {
logger.debug("Accessing root page");
return new ModelAndView("/index.xhtml", model);
}
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0; url=index.xhtml" />
<p><a href="index.xhtml">Redirect</a></p>
</head>
<body>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment