| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
|
|
2 |
|
| 23947 |
tejbeer |
3 |
import java.util.List;
|
| 23691 |
tejbeer |
4 |
|
| 23954 |
tejbeer |
5 |
import org.apache.logging.log4j.LogManager;
|
|
|
6 |
import org.apache.logging.log4j.Logger;
|
| 21220 |
ashik.ali |
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21272 |
kshitij.so |
8 |
import org.springframework.context.annotation.Bean;
|
| 21165 |
ashik.ali |
9 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
10 |
import org.springframework.context.annotation.Configuration;
|
| 27014 |
amit.gupta |
11 |
import org.springframework.http.MediaType;
|
| 23947 |
tejbeer |
12 |
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
13 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
| 27014 |
amit.gupta |
14 |
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
| 21285 |
kshitij.so |
15 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
| 21165 |
ashik.ali |
16 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
17 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
18 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
19 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
| 23965 |
amit.gupta |
20 |
|
|
|
21 |
import com.fasterxml.jackson.databind.DeserializationFeature;
|
| 23947 |
tejbeer |
22 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 23954 |
tejbeer |
23 |
import com.fasterxml.jackson.databind.SerializationFeature;
|
| 23947 |
tejbeer |
24 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
| 21236 |
ashik.ali |
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21743 |
ashik.ali |
26 |
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
|
| 21812 |
amit.gupta |
27 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
| 23965 |
amit.gupta |
28 |
|
| 21272 |
kshitij.so |
29 |
import springfox.documentation.builders.PathSelectors;
|
|
|
30 |
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
31 |
import springfox.documentation.service.ApiInfo;
|
|
|
32 |
import springfox.documentation.spi.DocumentationType;
|
|
|
33 |
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
34 |
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
35 |
|
| 21165 |
ashik.ali |
36 |
@Configuration
|
|
|
37 |
@EnableWebMvc
|
| 21272 |
kshitij.so |
38 |
@EnableSwagger2
|
| 21220 |
ashik.ali |
39 |
@ComponentScan("com.spice.profitmandi.*")
|
| 21165 |
ashik.ali |
40 |
public class WebMVCConfig extends WebMvcConfigurerAdapter{
|
|
|
41 |
|
|
|
42 |
private static final String RESOURCES_PATTERN="/resources/**";
|
|
|
43 |
private static final String RESOURCES_LOCATION="/resources/";
|
|
|
44 |
|
| 23954 |
tejbeer |
45 |
|
|
|
46 |
private static final Logger log = LogManager.getLogger(WebMVCConfig.class);
|
|
|
47 |
|
| 21220 |
ashik.ali |
48 |
@Autowired
|
| 21285 |
kshitij.so |
49 |
SimpleCORSInterceptor simpleCORSInterceptor;
|
| 21452 |
amit.gupta |
50 |
|
|
|
51 |
@Autowired
|
|
|
52 |
AuthenticationInterceptor authenticationInterceptor;
|
| 21302 |
ashik.ali |
53 |
|
| 21272 |
kshitij.so |
54 |
@Bean
|
|
|
55 |
public Docket api() {
|
|
|
56 |
return new Docket(DocumentationType.SWAGGER_2).select()
|
|
|
57 |
.apis(RequestHandlerSelectors.any())
|
|
|
58 |
.paths(PathSelectors.any()).build()
|
|
|
59 |
.apiInfo(apiInfo());
|
|
|
60 |
}
|
|
|
61 |
|
| 21165 |
ashik.ali |
62 |
@Override
|
| 21272 |
kshitij.so |
63 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
64 |
registry.addResourceHandler("swagger-ui.html")
|
|
|
65 |
.addResourceLocations("classpath:/META-INF/resources/");
|
|
|
66 |
registry.addResourceHandler("/webjars/**")
|
|
|
67 |
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
68 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
|
|
69 |
}
|
| 21165 |
ashik.ali |
70 |
|
|
|
71 |
@Override
|
|
|
72 |
public void addInterceptors(InterceptorRegistry registry) {
|
| 27113 |
tejbeer |
73 |
registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html",
|
|
|
74 |
ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED,
|
|
|
75 |
ProfitMandiConstants.URL_CCAVENUE_PAY_RESPONSE, ProfitMandiConstants.URL_CCAVENUE_PAY_CANCELLED,
|
|
|
76 |
ProfitMandiConstants.URL_POST_OFFICE);
|
|
|
77 |
|
| 26863 |
amit.gupta |
78 |
registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**")
|
|
|
79 |
.excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
|
| 22812 |
amit.gupta |
80 |
.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**").excludePathPatterns("/document")
|
| 26522 |
amit.gupta |
81 |
.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP)
|
| 26611 |
amit.gupta |
82 |
.excludePathPatterns("/store/token")
|
| 26522 |
amit.gupta |
83 |
.excludePathPatterns("/gc/**");
|
|
|
84 |
|
| 21469 |
amit.gupta |
85 |
//registry to check api access on basis of UserInfo
|
| 21165 |
ashik.ali |
86 |
}
|
| 21272 |
kshitij.so |
87 |
|
| 21285 |
kshitij.so |
88 |
@Override
|
|
|
89 |
public void addCorsMappings(CorsRegistry registry) {
|
|
|
90 |
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
|
|
|
91 |
allowedHeaders("*").allowCredentials(false);
|
|
|
92 |
}
|
|
|
93 |
|
| 21272 |
kshitij.so |
94 |
private ApiInfo apiInfo() {
|
|
|
95 |
@SuppressWarnings("deprecation")
|
|
|
96 |
ApiInfo apiInfo = new ApiInfo(
|
|
|
97 |
"ProfitMandi API",
|
|
|
98 |
"Api's for profitmandi app",
|
|
|
99 |
"API TOS",
|
|
|
100 |
"Terms of service",
|
|
|
101 |
"New Spice Solutions Pvt. Ltd.",
|
|
|
102 |
"License of API",
|
|
|
103 |
"API license URL");
|
|
|
104 |
return apiInfo;
|
|
|
105 |
}
|
| 23947 |
tejbeer |
106 |
|
| 23954 |
tejbeer |
107 |
|
| 23947 |
tejbeer |
108 |
@Override
|
| 23954 |
tejbeer |
109 |
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
110 |
|
| 23947 |
tejbeer |
111 |
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
| 23954 |
tejbeer |
112 |
super.configureMessageConverters(converters);
|
| 23947 |
tejbeer |
113 |
}
|
| 23949 |
amit.gupta |
114 |
@Bean
|
|
|
115 |
public ObjectMapper objectMapper() {
|
| 23954 |
tejbeer |
116 |
ObjectMapper objectMapper = new ObjectMapper();
|
| 23965 |
amit.gupta |
117 |
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
| 23954 |
tejbeer |
118 |
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
|
119 |
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
|
120 |
objectMapper.registerModule(javaTimeModule);
|
|
|
121 |
return objectMapper;
|
| 23947 |
tejbeer |
122 |
}
|
| 27014 |
amit.gupta |
123 |
|
| 23954 |
tejbeer |
124 |
|
| 27014 |
amit.gupta |
125 |
@Override
|
|
|
126 |
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
|
|
127 |
configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
128 |
}
|
|
|
129 |
|
| 21220 |
ashik.ali |
130 |
}
|