Commit 2533a5d7 authored by Aleksandr Sharaban's avatar Aleksandr Sharaban
Browse files

Migration from web.xml to Java config.

parent 58cfd28a
package org.genesys2.server.config;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionListener implements HttpSessionListener {
private int sessionTimeout;
public SessionListener(int sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}
@Override
public void sessionCreated(HttpSessionEvent se) {
se.getSession().setMaxInactiveInterval(sessionTimeout);
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
}
}
package org.genesys2.server.config;
import com.hazelcast.web.SessionListener;
import org.genesys2.spring.config.ApplicationConfig;
import org.genesys2.spring.config.SpringServletConfig;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.SessionTrackingMode;
import java.util.EnumSet;
public class WebAppInitializer implements WebApplicationInitializer {
private static final int SESSION_TIMEOUT = 30;
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(ApplicationConfig.class);
servletContext.addListener(new SessionListener());
servletContext.addListener(new ContextLoaderListener(rootContext));
servletContext.addListener(new org.genesys2.server.config.SessionListener(SESSION_TIMEOUT));
// servletContext.setInitParameter("contextConfigLocation", "classpath:spring/application-context.xml");
servletContext.setInitParameter("defaultHtmlEscape", "true");
servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
servletContext.getSessionCookieConfig().setHttpOnly(true);
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(SpringServletConfig.class);
registerServlets(servletContext, dispatcherContext);
registerFilters(servletContext, dispatcherContext);
}
private void registerServlets(ServletContext servletContext, AnnotationConfigWebApplicationContext appContext) {
//Dispatcher servlet configuration
ServletRegistration.Dynamic dispatcherServlet = servletContext
.addServlet("mvc", new DispatcherServlet(appContext));
dispatcherServlet.setLoadOnStartup(1);
dispatcherServlet.addMapping("/");
//Default Jetty servlet configuration
ServletRegistration defaultServlet = servletContext.getServletRegistration("default");
defaultServlet.setInitParameter("dirAllowed", "false");
defaultServlet.setInitParameter("maxCacheSize", "256000000");
defaultServlet.setInitParameter("maxCachedFileSize", "200000000");
defaultServlet.setInitParameter("maxCachedFiles", "2048");
defaultServlet.setInitParameter("gzip", "true");
defaultServlet.setInitParameter("etags", "true");
defaultServlet.setInitParameter("useFileMappedBuffer", "true");
defaultServlet.setInitParameter("resourceCache", "resourceCache");
defaultServlet.setInitParameter("cacheControl", "private, max-age=3600");
defaultServlet.addMapping("/html/*");
}
private void registerFilters(ServletContext servletContext, AnnotationConfigWebApplicationContext appContext) {
//UrlRewrite filter configuration
FilterRegistration.Dynamic urlRewriteFilter = servletContext
.addFilter("urlRewriteFilter", "org.tuckey.web.filters.urlrewrite.UrlRewriteFilter");
urlRewriteFilter.setInitParameter("confReloadCheckInterval", "10");
// urlRewriteFilter.setInitParameter("logLevel", "sysout:DEBUG");
urlRewriteFilter.addMappingForUrlPatterns(
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
//Encoding filter configuration
FilterRegistration.Dynamic encodingFilter = servletContext
.addFilter("encodingFilter", "org.springframework.web.filter.CharacterEncodingFilter");
encodingFilter.setInitParameter("encoding", "UTF-8");
encodingFilter.setInitParameter("forceEncoding", "true");
urlRewriteFilter.addMappingForUrlPatterns(null, false, "/*");
//Configuration of cross origin filter for web REST API clients
FilterRegistration.Dynamic crossOriginFilter = servletContext
.addFilter("cross-origin", "org.eclipse.jetty.servlets.CrossOriginFilter");
crossOriginFilter.setInitParameter("allowedOrigins", "*");
crossOriginFilter.setInitParameter("allowCredentials", "true");
crossOriginFilter.setInitParameter("allowedMethods", "GET,POST,PUT,DELETE");
crossOriginFilter.setInitParameter("allowedHeaders", "*");
//Do not chain preflight request to application
crossOriginFilter.setInitParameter("chainPreflight", "false");
crossOriginFilter.addMappingForUrlPatterns(null, false, "/oauth/token");
crossOriginFilter.addMappingForUrlPatterns(null, false, "/api/*");
crossOriginFilter.addMappingForUrlPatterns(null, false, "/webapi/*");
//Hazelcast web filter configuration
FilterRegistration.Dynamic hazelcastWebFilter = servletContext
.addFilter("hazelcastWebFilter", "org.springframework.web.filter.DelegatingFilterProxy");
hazelcastWebFilter.setInitParameter("targetFilterLifecycle", "true");
hazelcastWebFilter.addMappingForUrlPatterns(
EnumSet.of(DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST), false, "/*");
//Filter chain proxy configuration
FilterRegistration.Dynamic filterChainProxy = servletContext
.addFilter("org.springframework.security.filterChainProxy",
"org.springframework.web.filter.DelegatingFilterProxy");
filterChainProxy.addMappingForUrlPatterns(null, false, "/*");
//Locale URL filter configuration
FilterRegistration.Dynamic localeURLFilter = servletContext
.addFilter("localeURLFilter", "org.genesys2.server.servlet.filter.LocaleURLFilter");
localeURLFilter.setInitParameter("exclude-paths", "/html /login-attempt");
localeURLFilter.setInitParameter("default-locale", "en");
localeURLFilter.setInitParameter("allowed-locales", "en es de fr fa ar ru zh pt");
localeURLFilter.addMappingForUrlPatterns(null, false, "/*");
//EnvVar filter configuration
//Adds variables to all requests
FilterRegistration.Dynamic envVarFilter = servletContext
.addFilter("envVarFilter", "org.springframework.web.filter.DelegatingFilterProxy");
envVarFilter.addMappingForUrlPatterns(null, false, "/*");
//Genesys Web API Filter configuration
FilterRegistration.Dynamic webApiFilter = servletContext
.addFilter("webApiFilter", "org.springframework.web.filter.DelegatingFilterProxy");
webApiFilter.addMappingForUrlPatterns(null, false, "/webapi/*");
//Sitemesh filter configuration
FilterRegistration.Dynamic sitemeshFilter = servletContext
.addFilter("sitemesh", "org.sitemesh.config.ConfigurableSiteMeshFilter");
sitemeshFilter.addMappingForUrlPatterns(null, false, "/*");
//New GUI filter configuration
FilterRegistration.Dynamic newGUIFilter = servletContext
.addFilter("newGUIFilter", "org.genesys2.server.servlet.filter.NewGUIFilter");
newGUIFilter.setInitParameter("exclude-paths", "/html /login-attempt");
newGUIFilter.addMappingForUrlPatterns(null, false, "/*");
}
}
......@@ -21,298 +21,22 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!--<context-param>-->
<!--<param-name>contextConfigLocation</param-name>-->
<!--<param-value>classpath:spring/application-context.xml</param-value>-->
<!--</context-param>-->
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.genesys2.spring.config.ApplicationConfig</param-value>
</context-param>
<context-param>
<param-name>defaultHtmlEscape</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>com.hazelcast.web.SessionListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>10</param-value>
</init-param>
<!-- <init-param>
<param-name>logLevel</param-name>
<param-value>sysout:DEBUG</param-value>
</init-param> -->
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Cross origin for web REST API clients -->
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<!-- <init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param> -->
<!-- <init-param>
<param-name>allowCredentials</param-name>
<param-value>true</param-value>
</init-param>
-->
<init-param>
<param-name>allowedMethods</param-name>
<param-value>GET,POST,PUT,DELETE</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>*</param-value>
</init-param>
<!-- Do not chain preflight request to application -->
<init-param>
<param-name>chainPreflight</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/oauth/token</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/api/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/webapi/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>hazelcastWebFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hazelcastWebFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter>
<filter-name>org.springframework.security.filterChainProxy</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>org.springframework.security.filterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>localeURLFilter</filter-name>
<filter-class>org.genesys2.server.servlet.filter.LocaleURLFilter</filter-class>
<init-param>
<param-name>exclude-paths</param-name>
<param-value>/html /login-attempt</param-value>
</init-param>
<init-param>
<param-name>default-locale</param-name>
<param-value>en</param-value>
</init-param>
<init-param>
<param-name>allowed-locales</param-name>
<param-value>en es de fr fa ar ru zh pt</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>localeURLFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<description>Adds variables to all requests</description>
<filter-name>envVarFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>envVarFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<description>Genesys Web API Filter</description>
<filter-name>webApiFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>webApiFilter</filter-name>
<url-pattern>/webapi/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>newGUIFilter</filter-name>
<filter-class>org.genesys2.server.servlet.filter.NewGUIFilter</filter-class>
<init-param>
<param-name>exclude-paths</param-name>
<param-value>/html /login-attempt</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>newGUIFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
org.genesys2.spring.config.SpringServletConfig
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>default</servlet-name>
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>maxCacheSize</param-name>
<param-value>256000000</param-value>
</init-param>
<init-param>
<param-name>maxCachedFileSize</param-name>
<param-value>200000000</param-value>
</init-param>
<init-param>
<param-name>maxCachedFiles</param-name>
<param-value>2048</param-value>
</init-param>
<init-param>
<param-name>gzip</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>etags</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>useFileMappedBuffer</param-name>
<param-value>true</param-value>
</init-param>
<!--
<init-param>
<param-name>resourceCache</param-name>
<param-value>resourceCache</param-value>
</init-param>
-->
<init-param>
<param-name>cacheControl</param-name>
<param-value>private, max-age=3600</param-value>
</init-param>
</servlet>
<!-- Use default Jetty servlet for static resources in /html/* -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/html/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
<error-page>
<error-code>401</error-code>
<location>/errors/401</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/errors/404</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/errors/500</location>
</error-page>
<error-page>
<error-code>503</error-code>
<location>/errors/503</location>
</error-page>
<session-config>
<session-timeout>30</session-timeout>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<error-page>
<error-code>401</error-code>
<location>/errors/401</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/errors/404</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/errors/500</location>
</error-page>
<error-page>
<error-code>503</error-code>
<location>/errors/503</location>
</error-page>
<jsp-config>
<jsp-property-group>
......@@ -320,9 +44,4 @@
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
<session-config>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
</session-config>
</web-app>
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