| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.config;
|
1 |
package com.spice.profitmandi.web.config;
|
| 2 |
|
2 |
|
| - |
|
3 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
4 |
import org.springframework.context.annotation.Bean;
|
| 3 |
import org.springframework.context.annotation.ComponentScan;
|
5 |
import org.springframework.context.annotation.ComponentScan;
|
| 4 |
import org.springframework.context.annotation.Configuration;
|
6 |
import org.springframework.context.annotation.Configuration;
|
| - |
|
7 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
| 5 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
8 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
| - |
|
9 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
| 6 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
10 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
| 7 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
11 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
| 8 |
|
12 |
|
| - |
|
13 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
14 |
import com.spice.profitmandi.common.web.interceptor.AuthenticationInterceptor;
|
| - |
|
15 |
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
|
| - |
|
16 |
|
| - |
|
17 |
import springfox.documentation.builders.PathSelectors;
|
| - |
|
18 |
import springfox.documentation.builders.RequestHandlerSelectors;
|
| 9 |
@EnableWebMvc
|
19 |
import springfox.documentation.service.ApiInfo;
|
| - |
|
20 |
import springfox.documentation.spi.DocumentationType;
|
| - |
|
21 |
import springfox.documentation.spring.web.plugins.Docket;
|
| - |
|
22 |
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
| - |
|
23 |
|
| 10 |
@Configuration
|
24 |
@Configuration
|
| - |
|
25 |
@EnableWebMvc
|
| - |
|
26 |
@EnableSwagger2
|
| 11 |
@ComponentScan({"com.spice.profitmandi.*"})
|
27 |
@ComponentScan("com.spice.profitmandi.*")
|
| 12 |
public class WebConfig extends WebMvcConfigurerAdapter{
|
28 |
public class WebConfig extends WebMvcConfigurerAdapter{
|
| 13 |
|
29 |
|
| 14 |
private static final String RESOURCES_PATTERN="/resources/**";
|
30 |
private static final String RESOURCES_PATTERN="/resources/**";
|
| 15 |
private static final String RESOURCES_LOCATION="/resources/";
|
31 |
private static final String RESOURCES_LOCATION="/resources/";
|
| 16 |
|
32 |
|
| - |
|
33 |
@Autowired
|
| - |
|
34 |
SimpleCORSInterceptor simpleCORSInterceptor;
|
| - |
|
35 |
|
| - |
|
36 |
@Autowired
|
| - |
|
37 |
AuthenticationInterceptor authenticationInterceptor;
|
| - |
|
38 |
@Bean
|
| - |
|
39 |
public Docket api() {
|
| - |
|
40 |
return new Docket(DocumentationType.SWAGGER_2).select()
|
| - |
|
41 |
.apis(RequestHandlerSelectors.any())
|
| - |
|
42 |
.paths(PathSelectors.any()).build()
|
| - |
|
43 |
.apiInfo(apiInfo());
|
| - |
|
44 |
}
|
| - |
|
45 |
|
| 17 |
@Override
|
46 |
@Override
|
| 18 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
47 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
| - |
|
48 |
registry.addResourceHandler("swagger-ui.html")
|
| - |
|
49 |
.addResourceLocations("classpath:/META-INF/resources/");
|
| - |
|
50 |
registry.addResourceHandler("/webjars/**")
|
| - |
|
51 |
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
| 19 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
52 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
| - |
|
53 |
}
|
| - |
|
54 |
|
| - |
|
55 |
@Override
|
| - |
|
56 |
public void addInterceptors(InterceptorRegistry registry) {
|
| - |
|
57 |
registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html", ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED);
|
| - |
|
58 |
registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
|
| - |
|
59 |
.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**")
|
| - |
|
60 |
.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP);
|
| - |
|
61 |
}
|
| - |
|
62 |
|
| - |
|
63 |
@Override
|
| - |
|
64 |
public void addCorsMappings(CorsRegistry registry) {
|
| - |
|
65 |
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
|
| - |
|
66 |
allowedHeaders("*").allowCredentials(false);
|
| - |
|
67 |
}
|
| - |
|
68 |
|
| - |
|
69 |
private ApiInfo apiInfo() {
|
| - |
|
70 |
@SuppressWarnings("deprecation")
|
| - |
|
71 |
ApiInfo apiInfo = new ApiInfo(
|
| - |
|
72 |
"ProfitMandi API",
|
| - |
|
73 |
"Api's for profitmandi app",
|
| - |
|
74 |
"API TOS",
|
| - |
|
75 |
"Terms of service",
|
| - |
|
76 |
"New Spice Solutions Pvt. Ltd.",
|
| - |
|
77 |
"License of API",
|
| - |
|
78 |
"API license URL");
|
| - |
|
79 |
return apiInfo;
|
| 20 |
}
|
80 |
}
|
| 21 |
}
|
81 |
}
|