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