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