| 21749 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
| 21541 |
ashik.ali |
2 |
|
| 21749 |
ashik.ali |
3 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
4 |
import org.springframework.context.annotation.Bean;
|
| 21541 |
ashik.ali |
5 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
6 |
import org.springframework.context.annotation.Configuration;
|
| 21749 |
ashik.ali |
7 |
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
| 21541 |
ashik.ali |
8 |
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
| 21749 |
ashik.ali |
9 |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
| 21541 |
ashik.ali |
10 |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
11 |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
12 |
|
| 21749 |
ashik.ali |
13 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
14 |
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
|
| 21812 |
amit.gupta |
15 |
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
|
| 21749 |
ashik.ali |
16 |
|
|
|
17 |
import springfox.documentation.builders.PathSelectors;
|
|
|
18 |
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
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 |
|
|
|
24 |
@Configuration
|
| 21541 |
ashik.ali |
25 |
@EnableWebMvc
|
| 21749 |
ashik.ali |
26 |
@EnableSwagger2
|
|
|
27 |
@ComponentScan("com.spice.profitmandi.*")
|
| 21541 |
ashik.ali |
28 |
public class WebConfig extends WebMvcConfigurerAdapter{
|
|
|
29 |
|
|
|
30 |
private static final String RESOURCES_PATTERN="/resources/**";
|
|
|
31 |
private static final String RESOURCES_LOCATION="/resources/";
|
|
|
32 |
|
| 21749 |
ashik.ali |
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 |
|
| 21541 |
ashik.ali |
46 |
@Override
|
|
|
47 |
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
| 21749 |
ashik.ali |
48 |
registry.addResourceHandler("swagger-ui.html")
|
|
|
49 |
.addResourceLocations("classpath:/META-INF/resources/");
|
|
|
50 |
registry.addResourceHandler("/webjars/**")
|
|
|
51 |
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
52 |
registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
|
| 21541 |
ashik.ali |
53 |
}
|
| 21749 |
ashik.ali |
54 |
|
|
|
55 |
@Override
|
|
|
56 |
public void addInterceptors(InterceptorRegistry registry) {
|
| 21812 |
amit.gupta |
57 |
registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**");
|
|
|
58 |
registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/login")
|
|
|
59 |
.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**");
|
| 21749 |
ashik.ali |
60 |
}
|
|
|
61 |
|
|
|
62 |
@Override
|
|
|
63 |
public void addCorsMappings(CorsRegistry registry) {
|
|
|
64 |
registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
|
|
|
65 |
allowedHeaders("*").allowCredentials(false);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
private ApiInfo apiInfo() {
|
|
|
69 |
@SuppressWarnings("deprecation")
|
|
|
70 |
ApiInfo apiInfo = new ApiInfo(
|
|
|
71 |
"ProfitMandi API",
|
|
|
72 |
"Api's for profitmandi app",
|
|
|
73 |
"API TOS",
|
|
|
74 |
"Terms of service",
|
|
|
75 |
"New Spice Solutions Pvt. Ltd.",
|
|
|
76 |
"License of API",
|
|
|
77 |
"API license URL");
|
|
|
78 |
return apiInfo;
|
|
|
79 |
}
|
| 21541 |
ashik.ali |
80 |
}
|