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