Subversion Repositories SmartDukaan

Rev

Rev 23949 | Rev 23965 | 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
 
23947 tejbeer 3
import java.util.List;
23691 tejbeer 4
 
23954 tejbeer 5
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.Logger;
21220 ashik.ali 7
import org.springframework.beans.factory.annotation.Autowired;
21272 kshitij.so 8
import org.springframework.context.annotation.Bean;
21165 ashik.ali 9
import org.springframework.context.annotation.ComponentScan;
10
import org.springframework.context.annotation.Configuration;
23947 tejbeer 11
import org.springframework.http.converter.HttpMessageConverter;
12
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
21285 kshitij.so 13
import org.springframework.web.servlet.config.annotation.CorsRegistry;
21165 ashik.ali 14
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
15
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
16
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
17
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
23947 tejbeer 18
import com.fasterxml.jackson.databind.ObjectMapper;
23954 tejbeer 19
import com.fasterxml.jackson.databind.SerializationFeature;
23947 tejbeer 20
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
21236 ashik.ali 21
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21743 ashik.ali 22
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
21812 amit.gupta 23
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
21272 kshitij.so 24
import springfox.documentation.builders.PathSelectors;
25
import springfox.documentation.builders.RequestHandlerSelectors;
26
import springfox.documentation.service.ApiInfo;
27
import springfox.documentation.spi.DocumentationType;
28
import springfox.documentation.spring.web.plugins.Docket;
29
import springfox.documentation.swagger2.annotations.EnableSwagger2;
30
 
21165 ashik.ali 31
@Configuration
32
@EnableWebMvc
21272 kshitij.so 33
@EnableSwagger2
21220 ashik.ali 34
@ComponentScan("com.spice.profitmandi.*")
21165 ashik.ali 35
public class WebMVCConfig extends WebMvcConfigurerAdapter{
36
 
37
	private static final String RESOURCES_PATTERN="/resources/**";
38
	private static final String RESOURCES_LOCATION="/resources/";
39
 
23954 tejbeer 40
 
41
	private static final Logger log = LogManager.getLogger(WebMVCConfig.class);
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
 
23954 tejbeer 94
 
23947 tejbeer 95
	@Override
23954 tejbeer 96
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
97
 
23947 tejbeer 98
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
23954 tejbeer 99
        super.configureMessageConverters(converters);
23947 tejbeer 100
    }
23949 amit.gupta 101
	@Bean
102
	public ObjectMapper objectMapper() {
23954 tejbeer 103
	    ObjectMapper objectMapper = new ObjectMapper();
104
	    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
105
	    JavaTimeModule javaTimeModule = new JavaTimeModule();
106
	    objectMapper.registerModule(javaTimeModule);
107
	    return objectMapper;
23947 tejbeer 108
	}
23954 tejbeer 109
 
21220 ashik.ali 110
}