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