Subversion Repositories SmartDukaan

Rev

Rev 23705 | Rev 23949 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21165 ashik.ali 1
package com.spice.profitmandi.web.config;
2
 
23691 tejbeer 3
import java.time.format.DateTimeFormatter;
23947 tejbeer 4
import java.util.List;
23691 tejbeer 5
 
21220 ashik.ali 6
import org.springframework.beans.factory.annotation.Autowired;
21272 kshitij.so 7
import org.springframework.context.annotation.Bean;
21165 ashik.ali 8
import org.springframework.context.annotation.ComponentScan;
9
import org.springframework.context.annotation.Configuration;
23947 tejbeer 10
import org.springframework.http.converter.HttpMessageConverter;
11
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
21285 kshitij.so 12
import org.springframework.web.servlet.config.annotation.CorsRegistry;
21165 ashik.ali 13
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
14
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
15
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
16
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
17
 
23947 tejbeer 18
import com.fasterxml.jackson.databind.ObjectMapper;
19
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
20
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
21
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
21236 ashik.ali 22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21743 ashik.ali 23
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
21812 amit.gupta 24
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
21220 ashik.ali 25
 
21272 kshitij.so 26
import springfox.documentation.builders.PathSelectors;
27
import springfox.documentation.builders.RequestHandlerSelectors;
28
import springfox.documentation.service.ApiInfo;
29
import springfox.documentation.spi.DocumentationType;
30
import springfox.documentation.spring.web.plugins.Docket;
31
import springfox.documentation.swagger2.annotations.EnableSwagger2;
32
 
21165 ashik.ali 33
@Configuration
34
@EnableWebMvc
21272 kshitij.so 35
@EnableSwagger2
21220 ashik.ali 36
@ComponentScan("com.spice.profitmandi.*")
21165 ashik.ali 37
public class WebMVCConfig extends WebMvcConfigurerAdapter{
38
 
39
	private static final String RESOURCES_PATTERN="/resources/**";
40
	private static final String RESOURCES_LOCATION="/resources/";
23691 tejbeer 41
	public static final DateTimeFormatter FORMATTER =DateTimeFormatter.ofPattern("dd::MM::yyyy");
21165 ashik.ali 42
 
21220 ashik.ali 43
	@Autowired
21285 kshitij.so 44
	SimpleCORSInterceptor simpleCORSInterceptor;
21452 amit.gupta 45
 
46
	@Autowired
47
	AuthenticationInterceptor authenticationInterceptor;
21302 ashik.ali 48
 
21272 kshitij.so 49
	@Bean
50
	public Docket api() {
51
		return new Docket(DocumentationType.SWAGGER_2).select()
52
				.apis(RequestHandlerSelectors.any())
53
				.paths(PathSelectors.any()).build()
54
				.apiInfo(apiInfo());
55
	}
56
 
21165 ashik.ali 57
	@Override
21272 kshitij.so 58
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
59
	    registry.addResourceHandler("swagger-ui.html")
60
	      .addResourceLocations("classpath:/META-INF/resources/");
61
	    registry.addResourceHandler("/webjars/**")
62
	      .addResourceLocations("classpath:/META-INF/resources/webjars/");
63
	    registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
64
	}
21165 ashik.ali 65
 
66
	@Override
67
	public void addInterceptors(InterceptorRegistry registry) {
21473 amit.gupta 68
		registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html", ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED);
21469 amit.gupta 69
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
22812 amit.gupta 70
		.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**").excludePathPatterns("/document")
21471 amit.gupta 71
		.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP);
21469 amit.gupta 72
		//registry to check api access on basis of UserInfo
21165 ashik.ali 73
	}
21272 kshitij.so 74
 
21285 kshitij.so 75
	@Override
76
	public void addCorsMappings(CorsRegistry registry) {
77
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
78
		allowedHeaders("*").allowCredentials(false);
79
	}
80
 
21272 kshitij.so 81
	private ApiInfo apiInfo() {
82
	    @SuppressWarnings("deprecation")
83
		ApiInfo apiInfo = new ApiInfo(
84
	      "ProfitMandi API",
85
	      "Api's for profitmandi app",
86
	      "API TOS",
87
	      "Terms of service",
88
	      "New Spice Solutions Pvt. Ltd.",
89
	      "License of API",
90
	      "API license URL");
91
	    return apiInfo;
92
	}
23947 tejbeer 93
 
94
	@Override
95
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
96
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
97
    }
98
 
99
	private ObjectMapper objectMapper() {
100
		ObjectMapper mapper = new ObjectMapper()
101
				   .registerModule(new ParameterNamesModule())
102
				   .registerModule(new   Jdk8Module())
103
				   .registerModule(new JavaTimeModule()); // new module, NOT JSR310Module
104
		return mapper;
105
	}
21220 ashik.ali 106
}