Subversion Repositories SmartDukaan

Rev

Rev 23965 | Rev 26590 | 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;
23965 amit.gupta 18
 
19
import com.fasterxml.jackson.databind.DeserializationFeature;
23947 tejbeer 20
import com.fasterxml.jackson.databind.ObjectMapper;
23954 tejbeer 21
import com.fasterxml.jackson.databind.SerializationFeature;
23947 tejbeer 22
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
21236 ashik.ali 23
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21743 ashik.ali 24
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
21812 amit.gupta 25
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
23965 amit.gupta 26
 
21272 kshitij.so 27
import springfox.documentation.builders.PathSelectors;
28
import springfox.documentation.builders.RequestHandlerSelectors;
29
import springfox.documentation.service.ApiInfo;
30
import springfox.documentation.spi.DocumentationType;
31
import springfox.documentation.spring.web.plugins.Docket;
32
import springfox.documentation.swagger2.annotations.EnableSwagger2;
33
 
21165 ashik.ali 34
@Configuration
35
@EnableWebMvc
21272 kshitij.so 36
@EnableSwagger2
21220 ashik.ali 37
@ComponentScan("com.spice.profitmandi.*")
21165 ashik.ali 38
public class WebMVCConfig extends WebMvcConfigurerAdapter{
39
 
40
	private static final String RESOURCES_PATTERN="/resources/**";
41
	private static final String RESOURCES_LOCATION="/resources/";
42
 
23954 tejbeer 43
 
44
	private static final Logger log = LogManager.getLogger(WebMVCConfig.class);
45
 
21220 ashik.ali 46
	@Autowired
21285 kshitij.so 47
	SimpleCORSInterceptor simpleCORSInterceptor;
21452 amit.gupta 48
 
49
	@Autowired
50
	AuthenticationInterceptor authenticationInterceptor;
21302 ashik.ali 51
 
21272 kshitij.so 52
	@Bean
53
	public Docket api() {
54
		return new Docket(DocumentationType.SWAGGER_2).select()
55
				.apis(RequestHandlerSelectors.any())
56
				.paths(PathSelectors.any()).build()
57
				.apiInfo(apiInfo());
58
	}
59
 
21165 ashik.ali 60
	@Override
21272 kshitij.so 61
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
62
	    registry.addResourceHandler("swagger-ui.html")
63
	      .addResourceLocations("classpath:/META-INF/resources/");
64
	    registry.addResourceHandler("/webjars/**")
65
	      .addResourceLocations("classpath:/META-INF/resources/webjars/");
66
	    registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
67
	}
21165 ashik.ali 68
 
69
	@Override
70
	public void addInterceptors(InterceptorRegistry registry) {
21473 amit.gupta 71
		registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html", ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED);
21469 amit.gupta 72
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
22812 amit.gupta 73
		.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**").excludePathPatterns("/document")
26522 amit.gupta 74
		.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP)
75
		.excludePathPatterns("/gc/**");
76
 
21469 amit.gupta 77
		//registry to check api access on basis of UserInfo
21165 ashik.ali 78
	}
21272 kshitij.so 79
 
21285 kshitij.so 80
	@Override
81
	public void addCorsMappings(CorsRegistry registry) {
82
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
83
		allowedHeaders("*").allowCredentials(false);
84
	}
85
 
21272 kshitij.so 86
	private ApiInfo apiInfo() {
87
	    @SuppressWarnings("deprecation")
88
		ApiInfo apiInfo = new ApiInfo(
89
	      "ProfitMandi API",
90
	      "Api's for profitmandi app",
91
	      "API TOS",
92
	      "Terms of service",
93
	      "New Spice Solutions Pvt. Ltd.",
94
	      "License of API",
95
	      "API license URL");
96
	    return apiInfo;
97
	}
23947 tejbeer 98
 
23954 tejbeer 99
 
23947 tejbeer 100
	@Override
23954 tejbeer 101
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
102
 
23947 tejbeer 103
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
23954 tejbeer 104
        super.configureMessageConverters(converters);
23947 tejbeer 105
    }
23949 amit.gupta 106
	@Bean
107
	public ObjectMapper objectMapper() {
23954 tejbeer 108
	    ObjectMapper objectMapper = new ObjectMapper();
23965 amit.gupta 109
	    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
23954 tejbeer 110
	    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
111
	    JavaTimeModule javaTimeModule = new JavaTimeModule();
112
	    objectMapper.registerModule(javaTimeModule);
113
	    return objectMapper;
23947 tejbeer 114
	}
23954 tejbeer 115
 
21220 ashik.ali 116
}