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