| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
|
|
2 |
|
| 23691 |
tejbeer |
3 |
import java.io.IOException;
|
|
|
4 |
import java.sql.Timestamp;
|
|
|
5 |
import java.time.LocalDateTime;
|
|
|
6 |
import java.time.ZoneId;
|
|
|
7 |
import java.time.ZonedDateTime;
|
|
|
8 |
import java.time.format.DateTimeFormatter;
|
|
|
9 |
import java.util.List;
|
|
|
10 |
|
| 21220 |
ashik.ali |
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21272 |
kshitij.so |
12 |
import org.springframework.context.annotation.Bean;
|
| 21165 |
ashik.ali |
13 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
14 |
import org.springframework.context.annotation.Configuration;
|
| 23691 |
tejbeer |
15 |
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
16 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
| 21285 |
kshitij.so |
17 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
| 21165 |
ashik.ali |
18 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
19 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
20 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
21 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
22 |
|
| 23691 |
tejbeer |
23 |
import com.fasterxml.jackson.core.JsonGenerator;
|
|
|
24 |
import com.fasterxml.jackson.core.JsonParser;
|
|
|
25 |
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
|
26 |
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
|
27 |
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
|
28 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
29 |
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
30 |
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
|
31 |
import com.fasterxml.jackson.databind.ser.std.DateSerializer;
|
|
|
32 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
| 21236 |
ashik.ali |
33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21743 |
ashik.ali |
34 |
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
|
| 21812 |
amit.gupta |
35 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
| 21220 |
ashik.ali |
36 |
|
| 21272 |
kshitij.so |
37 |
import springfox.documentation.builders.PathSelectors;
|
|
|
38 |
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
39 |
import springfox.documentation.service.ApiInfo;
|
|
|
40 |
import springfox.documentation.spi.DocumentationType;
|
|
|
41 |
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
42 |
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
43 |
|
| 21165 |
ashik.ali |
44 |
@Configuration
|
|
|
45 |
@EnableWebMvc
|
| 21272 |
kshitij.so |
46 |
@EnableSwagger2
|
| 21220 |
ashik.ali |
47 |
@ComponentScan("com.spice.profitmandi.*")
|
| 21165 |
ashik.ali |
48 |
public class WebMVCConfig extends WebMvcConfigurerAdapter{
|
|
|
49 |
|
|
|
50 |
private static final String RESOURCES_PATTERN="/resources/**";
|
|
|
51 |
private static final String RESOURCES_LOCATION="/resources/";
|
| 23691 |
tejbeer |
52 |
public static final DateTimeFormatter FORMATTER =DateTimeFormatter.ofPattern("dd::MM::yyyy");
|
| 21165 |
ashik.ali |
53 |
|
| 21220 |
ashik.ali |
54 |
@Autowired
|
| 21285 |
kshitij.so |
55 |
SimpleCORSInterceptor simpleCORSInterceptor;
|
| 21452 |
amit.gupta |
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
AuthenticationInterceptor authenticationInterceptor;
|
| 21302 |
ashik.ali |
59 |
|
| 21272 |
kshitij.so |
60 |
@Bean
|
|
|
61 |
public Docket api() {
|
|
|
62 |
return new Docket(DocumentationType.SWAGGER_2).select()
|
|
|
63 |
.apis(RequestHandlerSelectors.any())
|
|
|
64 |
.paths(PathSelectors.any()).build()
|
|
|
65 |
.apiInfo(apiInfo());
|
|
|
66 |
}
|
|
|
67 |
|
| 21165 |
ashik.ali |
68 |
@Override
|
| 21272 |
kshitij.so |
69 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
70 |
registry.addResourceHandler("swagger-ui.html")
|
|
|
71 |
.addResourceLocations("classpath:/META-INF/resources/");
|
|
|
72 |
registry.addResourceHandler("/webjars/**")
|
|
|
73 |
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
74 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
|
|
75 |
}
|
| 21165 |
ashik.ali |
76 |
|
|
|
77 |
@Override
|
|
|
78 |
public void addInterceptors(InterceptorRegistry registry) {
|
| 21473 |
amit.gupta |
79 |
registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html", ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED);
|
| 21469 |
amit.gupta |
80 |
registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
|
| 22812 |
amit.gupta |
81 |
.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**").excludePathPatterns("/document")
|
| 21471 |
amit.gupta |
82 |
.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP);
|
| 21469 |
amit.gupta |
83 |
//registry to check api access on basis of UserInfo
|
| 21165 |
ashik.ali |
84 |
}
|
| 21272 |
kshitij.so |
85 |
|
| 21285 |
kshitij.so |
86 |
@Override
|
|
|
87 |
public void addCorsMappings(CorsRegistry registry) {
|
|
|
88 |
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
|
|
|
89 |
allowedHeaders("*").allowCredentials(false);
|
|
|
90 |
}
|
|
|
91 |
|
| 21272 |
kshitij.so |
92 |
private ApiInfo apiInfo() {
|
|
|
93 |
@SuppressWarnings("deprecation")
|
|
|
94 |
ApiInfo apiInfo = new ApiInfo(
|
|
|
95 |
"ProfitMandi API",
|
|
|
96 |
"Api's for profitmandi app",
|
|
|
97 |
"API TOS",
|
|
|
98 |
"Terms of service",
|
|
|
99 |
"New Spice Solutions Pvt. Ltd.",
|
|
|
100 |
"License of API",
|
|
|
101 |
"API license URL");
|
|
|
102 |
return apiInfo;
|
|
|
103 |
}
|
| 23691 |
tejbeer |
104 |
|
|
|
105 |
@Override
|
|
|
106 |
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
107 |
|
|
|
108 |
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
|
|
109 |
super.configureMessageConverters(converters);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
private ObjectMapper objectMapper() {
|
|
|
113 |
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
114 |
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
|
115 |
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
|
116 |
javaTimeModule.addSerializer(java.sql.Date.class, new DateSerializer());
|
| 23700 |
amit.gupta |
117 |
//javaTimeModule.addDeserializer(Timestamp.class, new LocalDateDeserializer());
|
| 23691 |
tejbeer |
118 |
objectMapper.registerModule(javaTimeModule);
|
|
|
119 |
return objectMapper;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
public class LocalDateSerializer extends JsonSerializer<Timestamp> {
|
|
|
123 |
|
|
|
124 |
@Override
|
|
|
125 |
public void serialize(Timestamp value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
|
|
126 |
|
|
|
127 |
ZonedDateTime z = value.toInstant().atZone(ZoneId.systemDefault());
|
|
|
128 |
String str = FORMATTER.format(z);
|
|
|
129 |
gen.writeString(str);
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
|
| 23700 |
amit.gupta |
133 |
/* public class LocalDateDeserializer extends JsonDeserializer<Timestamp> {
|
| 23691 |
tejbeer |
134 |
|
|
|
135 |
@Override
|
|
|
136 |
public Timestamp deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
|
|
137 |
LocalDateTime dt = LocalDateTime.parse(p.getText(), FORMATTER);
|
|
|
138 |
// the date/time is in the default timezone
|
|
|
139 |
return Timestamp.from(dt.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
140 |
}
|
| 23700 |
amit.gupta |
141 |
}*/
|
| 23691 |
tejbeer |
142 |
|
|
|
143 |
|
| 21220 |
ashik.ali |
144 |
}
|