Subversion Repositories SmartDukaan

Rev

Rev 23878 | Rev 23890 | Go to most recent revision | 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
 
23878 amit.gupta 3
import java.util.List;
4
 
21561 ashik.ali 5
import org.springframework.beans.factory.annotation.Autowired;
21555 kshitij.so 6
import org.springframework.context.annotation.ComponentScan;
7
import org.springframework.context.annotation.Configuration;
23886 amit.gupta 8
import org.springframework.format.FormatterRegistry;
9
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
23878 amit.gupta 10
import org.springframework.http.converter.HttpMessageConverter;
11
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
21555 kshitij.so 12
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
21561 ashik.ali 13
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
21555 kshitij.so 14
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
15
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
16
 
23878 amit.gupta 17
import com.fasterxml.jackson.databind.ObjectMapper;
18
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
19
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
20
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
21561 ashik.ali 21
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
22107 ashik.ali 22
import com.spice.profitmandi.web.interceptor.RoleInterceptor;
21561 ashik.ali 23
 
21555 kshitij.so 24
@EnableWebMvc
25
@Configuration
26
@ComponentScan({"com.spice.profitmandi.*"})
27
public class WebConfig extends WebMvcConfigurerAdapter{
28
 
29
	private static final String RESOURCES_PATTERN="/resources/**";
30
	private static final String RESOURCES_LOCATION="/resources/";
31
 
21561 ashik.ali 32
	@Autowired
33
	AuthenticationInterceptor authenticationInterceptor;
22107 ashik.ali 34
 
35
	@Autowired
36
	RoleInterceptor roleInterceptor;
37
 
21555 kshitij.so 38
	@Override
39
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
40
	   registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
41
	}
42
 
21561 ashik.ali 43
	@Override
44
	public void addInterceptors(InterceptorRegistry registry) {
22151 amit.gupta 45
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/login", "/login/", "/", "");
46
		registry.addInterceptor(roleInterceptor).excludePathPatterns("/login", "/login/", "/register", "/register/", "", "/");
21561 ashik.ali 47
	}
48
 
23886 amit.gupta 49
	@Override
50
    public void addFormatters(FormatterRegistry registry) {
51
        DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
52
        registrar.setUseIsoFormat(true);
53
        registrar.registerFormatters(registry);
54
    }
55
 
23878 amit.gupta 56
 
23886 amit.gupta 57
 
23878 amit.gupta 58
	@Override
59
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
60
 
61
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
62
        super.configureMessageConverters(converters);
63
    }
64
 
65
	private ObjectMapper objectMapper() {
66
		ObjectMapper mapper = new ObjectMapper()
67
				   .registerModule(new ParameterNamesModule())
68
				   .registerModule(new Jdk8Module())
69
				   .registerModule(new JavaTimeModule()); // new module, NOT JSR310Module
70
		return mapper;
71
	}
72
 
21555 kshitij.so 73
}