Subversion Repositories SmartDukaan

Rev

Rev 29482 | Rev 30275 | 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
 
23951 amit.gupta 3
import java.time.LocalDateTime;
4
import java.time.format.DateTimeFormatter;
5
import java.time.format.DateTimeFormatterBuilder;
23878 amit.gupta 6
import java.util.List;
7
 
21561 ashik.ali 8
import org.springframework.beans.factory.annotation.Autowired;
23951 amit.gupta 9
import org.springframework.context.annotation.Bean;
21555 kshitij.so 10
import org.springframework.context.annotation.ComponentScan;
11
import org.springframework.context.annotation.Configuration;
23886 amit.gupta 12
import org.springframework.format.FormatterRegistry;
13
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
27013 amit.gupta 14
import org.springframework.http.MediaType;
23878 amit.gupta 15
import org.springframework.http.converter.HttpMessageConverter;
16
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
27013 amit.gupta 17
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
21555 kshitij.so 18
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
21561 ashik.ali 19
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
21555 kshitij.so 20
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
21
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
22
 
23878 amit.gupta 23
import com.fasterxml.jackson.databind.ObjectMapper;
24
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
25
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
23951 amit.gupta 26
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
27
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
23878 amit.gupta 28
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
21561 ashik.ali 29
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
22107 ashik.ali 30
import com.spice.profitmandi.web.interceptor.RoleInterceptor;
21561 ashik.ali 31
 
21555 kshitij.so 32
@EnableWebMvc
33
@Configuration
27013 amit.gupta 34
@ComponentScan({ "com.spice.profitmandi.*" })
35
public class WebConfig extends WebMvcConfigurerAdapter {
36
 
37
	private static final String RESOURCES_PATTERN = "/resources/**";
38
	private static final String RESOURCES_LOCATION = "/resources/";
39
 
21561 ashik.ali 40
	@Autowired
41
	AuthenticationInterceptor authenticationInterceptor;
27013 amit.gupta 42
 
22107 ashik.ali 43
	@Autowired
44
	RoleInterceptor roleInterceptor;
27013 amit.gupta 45
 
21555 kshitij.so 46
	@Override
47
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
27013 amit.gupta 48
		registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
21555 kshitij.so 49
	}
27013 amit.gupta 50
 
21561 ashik.ali 51
	@Override
52
	public void addInterceptors(InterceptorRegistry registry) {
27013 amit.gupta 53
		// registry.addInterceptor()
54
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/hdfctest/**",
55
				"/hdfc/**", "/spicemoney/callback", "/login", "/login/", "/forgetPassword", "/forgetPassword/", "/",
30039 tejbeer 56
				"/checkplans", "/12dashboard34", "/mandii", "/imei/validate", "/fundfina/getTransactions",
57
				"/fundfina/getUserData/{userId}", "/fundfina/pushPreApproval");
27013 amit.gupta 58
		registry.addInterceptor(roleInterceptor).excludePathPatterns("/hdfctest/**", "/hdfc/**", "/spicemoney/callback",
59
				"/login", "/login/", "/register", "/register/", "/forgetPassword", "/forgetPassword/", "/", "",
30039 tejbeer 60
				"/12dashboard34", "/mandii", "/imei/validate", "/fundfina/getTransactions",
61
				"/fundfina/getUserData/{userId}", "/fundfina/pushPreApproval");
21561 ashik.ali 62
	}
27013 amit.gupta 63
 
23886 amit.gupta 64
	@Override
27013 amit.gupta 65
	public void addFormatters(FormatterRegistry registry) {
66
		DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
67
		registrar.setUseIsoFormat(true);
68
		registrar.registerFormatters(registry);
69
	}
23886 amit.gupta 70
 
23878 amit.gupta 71
	@Override
27013 amit.gupta 72
	public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
73
		converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
74
	}
75
 
23951 amit.gupta 76
	@Bean
77
	public ObjectMapper objectMapper() {
27013 amit.gupta 78
		DateTimeFormatter df = new DateTimeFormatterBuilder().parseCaseInsensitive()
79
				.append(DateTimeFormatter.ISO_LOCAL_DATE).optionalStart().appendLiteral('T').optionalEnd()
80
				.appendLiteral(' ').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();
81
		DateTimeFormatter sf = new DateTimeFormatterBuilder().parseCaseInsensitive()
82
				.append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME)
23951 amit.gupta 83
				.toFormatter();
84
		LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
85
		LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
86
		JavaTimeModule jtm = new JavaTimeModule();
87
		jtm.addSerializer(LocalDateTime.class, serializer);
88
		jtm.addDeserializer(LocalDateTime.class, deserializer);
27013 amit.gupta 89
		ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule())
90
				.registerModule(new Jdk8Module()).registerModule(jtm); // new module, NOT JSR310Module
23878 amit.gupta 91
		return mapper;
92
	}
27013 amit.gupta 93
 
94
	@Override
95
	public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
96
		configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
97
	}
98
 
21555 kshitij.so 99
}