Subversion Repositories SmartDukaan

Rev

Rev 36510 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21561 ashik.ali 1
package com.spice.profitmandi.web.config;
21555 kshitij.so 2
 
37191 ranu 3
import com.spice.profitmandi.web.filter.BrandParamNormalizingFilter;
4
import com.spice.profitmandi.web.filter.RequestCachingFilter;
23628 ashik.ali 5
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.Logger;
23575 ashik.ali 7
import org.springframework.context.ApplicationContext;
8
import org.springframework.context.annotation.Bean;
21555 kshitij.so 9
import org.springframework.web.WebApplicationInitializer;
10
import org.springframework.web.context.ContextLoaderListener;
11
import org.springframework.web.context.WebApplicationContext;
12
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
13
import org.springframework.web.servlet.DispatcherServlet;
14
 
37191 ranu 15
import javax.servlet.FilterRegistration;
16
import javax.servlet.ServletContext;
17
import javax.servlet.ServletException;
18
import javax.servlet.ServletRegistration;
19
 
21555 kshitij.so 20
public class SpringWebAppInitializer implements WebApplicationInitializer{
21
 
23628 ashik.ali 22
	private static final Logger LOGGER = LogManager.getLogger(SpringWebAppInitializer.class);
21555 kshitij.so 23
 
24
	private static final String DISPATCHER_SERVLET_NAME="DispatcherServlet";
21568 ashik.ali 25
	private static final String SPRING_CONFIG_PACKAGE_LOCATION="com.spice.profitmandi.web.config";
21555 kshitij.so 26
 
23575 ashik.ali 27
	private ApplicationContext applicationContext;
28
 
21555 kshitij.so 29
	public void onStartup(ServletContext servletContext) throws ServletException {
30
		WebApplicationContext context = getContext();
23575 ashik.ali 31
		applicationContext = context;
21555 kshitij.so 32
        servletContext.addListener(new ContextLoaderListener(context));
33
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(context));
34
        dispatcher.setLoadOnStartup(1);
35
        dispatcher.addMapping("/");
36510 amit 36
 
37
        FilterRegistration.Dynamic cachingFilter = servletContext.addFilter("requestCachingFilter", new RequestCachingFilter());
38
        cachingFilter.addMappingForServletNames(null, false, DISPATCHER_SERVLET_NAME);
39
 
37191 ranu 40
        // Safety-net for URL '+' decode issue on brand query params. Only touches GET
41
        // requests with a brand/brands param present; falls back only when the raw value
42
        // doesn't exist in catalog.brand but "<value>+" does.
43
        FilterRegistration.Dynamic brandFilter = servletContext.addFilter("brandParamNormalizingFilter", new BrandParamNormalizingFilter());
44
        brandFilter.addMappingForServletNames(null, false, DISPATCHER_SERVLET_NAME);
45
 
21555 kshitij.so 46
        LOGGER.info("Context is loaded");
47
	}
48
 
49
	private AnnotationConfigWebApplicationContext getContext() {
50
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
51
        context.setConfigLocation(SPRING_CONFIG_PACKAGE_LOCATION);
52
        return context;
53
    }
54
 
23575 ashik.ali 55
	@Bean(name="applicationContext")
56
	public ApplicationContext getApplicationContext() {
57
		return applicationContext;
58
	}
21555 kshitij.so 59
 
60
}