| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
|
|
2 |
|
| 21220 |
ashik.ali |
3 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21272 |
kshitij.so |
4 |
import org.springframework.context.annotation.Bean;
|
| 21165 |
ashik.ali |
5 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
6 |
import org.springframework.context.annotation.Configuration;
|
| 21285 |
kshitij.so |
7 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
| 21165 |
ashik.ali |
8 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
9 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
10 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
11 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
12 |
|
| 21236 |
ashik.ali |
13 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
14 |
import com.spice.profitmandi.web.interceptor.ApiRequestInterceptor;
|
| 21302 |
ashik.ali |
15 |
import com.spice.profitmandi.web.interceptor.CreateRetailerRequestInterceptor;
|
| 21309 |
ashik.ali |
16 |
import com.spice.profitmandi.web.interceptor.CreateShopRequestInterceptor;
|
| 21278 |
ashik.ali |
17 |
import com.spice.profitmandi.web.interceptor.CreateUserRequestInterceptor;
|
| 21277 |
ashik.ali |
18 |
import com.spice.profitmandi.web.interceptor.GoogleLoginRequestInterceptor;
|
| 21236 |
ashik.ali |
19 |
import com.spice.profitmandi.web.interceptor.RoleRequestInterceptor;
|
| 21285 |
kshitij.so |
20 |
import com.spice.profitmandi.web.interceptor.SimpleCORSInterceptor;
|
| 21220 |
ashik.ali |
21 |
|
| 21272 |
kshitij.so |
22 |
import springfox.documentation.builders.PathSelectors;
|
|
|
23 |
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
24 |
import springfox.documentation.service.ApiInfo;
|
|
|
25 |
import springfox.documentation.spi.DocumentationType;
|
|
|
26 |
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
27 |
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
28 |
|
| 21165 |
ashik.ali |
29 |
@Configuration
|
|
|
30 |
@EnableWebMvc
|
| 21272 |
kshitij.so |
31 |
@EnableSwagger2
|
| 21220 |
ashik.ali |
32 |
@ComponentScan("com.spice.profitmandi.*")
|
| 21165 |
ashik.ali |
33 |
public class WebMVCConfig extends WebMvcConfigurerAdapter{
|
|
|
34 |
|
|
|
35 |
private static final String RESOURCES_PATTERN="/resources/**";
|
|
|
36 |
private static final String RESOURCES_LOCATION="/resources/";
|
|
|
37 |
|
| 21220 |
ashik.ali |
38 |
@Autowired
|
| 21236 |
ashik.ali |
39 |
ApiRequestInterceptor apiRequestInterceptor;
|
| 21165 |
ashik.ali |
40 |
|
| 21236 |
ashik.ali |
41 |
@Autowired
|
|
|
42 |
RoleRequestInterceptor roleRequestInterceptor;
|
|
|
43 |
|
| 21277 |
ashik.ali |
44 |
@Autowired
|
|
|
45 |
GoogleLoginRequestInterceptor googleLoginRequestInterceptor;
|
| 21272 |
kshitij.so |
46 |
|
| 21278 |
ashik.ali |
47 |
@Autowired
|
|
|
48 |
CreateUserRequestInterceptor createUserRequestInterceptor;
|
| 21277 |
ashik.ali |
49 |
|
| 21285 |
kshitij.so |
50 |
@Autowired
|
|
|
51 |
SimpleCORSInterceptor simpleCORSInterceptor;
|
|
|
52 |
|
| 21302 |
ashik.ali |
53 |
@Autowired
|
|
|
54 |
CreateRetailerRequestInterceptor createRetailerRequestInterceptor;
|
|
|
55 |
|
| 21309 |
ashik.ali |
56 |
@Autowired
|
|
|
57 |
CreateShopRequestInterceptor createShopRequestInterceptor;
|
| 21302 |
ashik.ali |
58 |
|
| 21272 |
kshitij.so |
59 |
@Bean
|
|
|
60 |
public Docket api() {
|
|
|
61 |
return new Docket(DocumentationType.SWAGGER_2).select()
|
|
|
62 |
.apis(RequestHandlerSelectors.any())
|
|
|
63 |
.paths(PathSelectors.any()).build()
|
|
|
64 |
.apiInfo(apiInfo());
|
|
|
65 |
}
|
|
|
66 |
|
| 21165 |
ashik.ali |
67 |
@Override
|
| 21272 |
kshitij.so |
68 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
69 |
registry.addResourceHandler("swagger-ui.html")
|
|
|
70 |
.addResourceLocations("classpath:/META-INF/resources/");
|
|
|
71 |
registry.addResourceHandler("/webjars/**")
|
|
|
72 |
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
73 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
|
|
74 |
}
|
| 21165 |
ashik.ali |
75 |
|
|
|
76 |
@Override
|
|
|
77 |
public void addInterceptors(InterceptorRegistry registry) {
|
| 21236 |
ashik.ali |
78 |
registry.addInterceptor(apiRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_API, ProfitMandiConstants.URL_API + "/");
|
|
|
79 |
registry.addInterceptor(roleRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_ROLE, ProfitMandiConstants.URL_ROLE + "/");
|
| 21277 |
ashik.ali |
80 |
registry.addInterceptor(googleLoginRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/");
|
| 21278 |
ashik.ali |
81 |
registry.addInterceptor(createUserRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_USER, ProfitMandiConstants.URL_USER + "/");
|
| 21285 |
kshitij.so |
82 |
registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html");
|
| 21302 |
ashik.ali |
83 |
registry.addInterceptor(createRetailerRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_RETAILER, ProfitMandiConstants.URL_RETAILER + "/");
|
| 21309 |
ashik.ali |
84 |
registry.addInterceptor(createShopRequestInterceptor).addPathPatterns(ProfitMandiConstants.URL_SHOP, ProfitMandiConstants.URL_SHOP + "/");
|
| 21165 |
ashik.ali |
85 |
}
|
| 21272 |
kshitij.so |
86 |
|
| 21285 |
kshitij.so |
87 |
@Override
|
|
|
88 |
public void addCorsMappings(CorsRegistry registry) {
|
|
|
89 |
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
|
|
|
90 |
allowedHeaders("*").allowCredentials(false);
|
|
|
91 |
}
|
|
|
92 |
|
| 21272 |
kshitij.so |
93 |
private ApiInfo apiInfo() {
|
|
|
94 |
@SuppressWarnings("deprecation")
|
|
|
95 |
ApiInfo apiInfo = new ApiInfo(
|
|
|
96 |
"ProfitMandi API",
|
|
|
97 |
"Api's for profitmandi app",
|
|
|
98 |
"API TOS",
|
|
|
99 |
"Terms of service",
|
|
|
100 |
"New Spice Solutions Pvt. Ltd.",
|
|
|
101 |
"License of API",
|
|
|
102 |
"API license URL");
|
|
|
103 |
return apiInfo;
|
|
|
104 |
}
|
| 21220 |
ashik.ali |
105 |
}
|