Subversion Repositories SmartDukaan

Rev

Rev 28577 | Rev 28579 | 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;
28577 amit.gupta 4
import java.util.stream.Collectors;
23691 tejbeer 5
 
23954 tejbeer 6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
21220 ashik.ali 8
import org.springframework.beans.factory.annotation.Autowired;
21272 kshitij.so 9
import org.springframework.context.annotation.Bean;
21165 ashik.ali 10
import org.springframework.context.annotation.ComponentScan;
11
import org.springframework.context.annotation.Configuration;
27014 amit.gupta 12
import org.springframework.http.MediaType;
23947 tejbeer 13
import org.springframework.http.converter.HttpMessageConverter;
14
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
27014 amit.gupta 15
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
21285 kshitij.so 16
import org.springframework.web.servlet.config.annotation.CorsRegistry;
21165 ashik.ali 17
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
18
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
19
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
20
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
23965 amit.gupta 21
 
22
import com.fasterxml.jackson.databind.DeserializationFeature;
23947 tejbeer 23
import com.fasterxml.jackson.databind.ObjectMapper;
23954 tejbeer 24
import com.fasterxml.jackson.databind.SerializationFeature;
23947 tejbeer 25
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
21236 ashik.ali 26
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21743 ashik.ali 27
import com.spice.profitmandi.common.web.interceptor.SimpleCORSInterceptor;
21812 amit.gupta 28
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
23965 amit.gupta 29
 
21272 kshitij.so 30
import springfox.documentation.builders.PathSelectors;
31
import springfox.documentation.builders.RequestHandlerSelectors;
32
import springfox.documentation.service.ApiInfo;
33
import springfox.documentation.spi.DocumentationType;
34
import springfox.documentation.spring.web.plugins.Docket;
35
import springfox.documentation.swagger2.annotations.EnableSwagger2;
36
 
21165 ashik.ali 37
@Configuration
38
@EnableWebMvc
21272 kshitij.so 39
@EnableSwagger2
21220 ashik.ali 40
@ComponentScan("com.spice.profitmandi.*")
27119 tejbeer 41
public class WebMVCConfig extends WebMvcConfigurerAdapter {
42
 
43
	private static final String RESOURCES_PATTERN = "/resources/**";
44
	private static final String RESOURCES_LOCATION = "/resources/";
45
 
23954 tejbeer 46
	private static final Logger log = LogManager.getLogger(WebMVCConfig.class);
27119 tejbeer 47
 
21220 ashik.ali 48
	@Autowired
21285 kshitij.so 49
	SimpleCORSInterceptor simpleCORSInterceptor;
21452 amit.gupta 50
 
51
	@Autowired
52
	AuthenticationInterceptor authenticationInterceptor;
27119 tejbeer 53
 
21272 kshitij.so 54
	@Bean
55
	public Docket api() {
27119 tejbeer 56
		return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
57
				.paths(PathSelectors.any()).build().apiInfo(apiInfo());
21272 kshitij.so 58
	}
27119 tejbeer 59
 
21165 ashik.ali 60
	@Override
21272 kshitij.so 61
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
27119 tejbeer 62
		registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
63
		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
64
		registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
21272 kshitij.so 65
	}
27119 tejbeer 66
 
21165 ashik.ali 67
	@Override
68
	public void addInterceptors(InterceptorRegistry registry) {
27113 tejbeer 69
		registry.addInterceptor(simpleCORSInterceptor).addPathPatterns("/**").excludePathPatterns("/swagger-ui.html",
70
				ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, ProfitMandiConstants.URL_PAYU_PAY_CANCELLED,
71
				ProfitMandiConstants.URL_CCAVENUE_PAY_RESPONSE, ProfitMandiConstants.URL_CCAVENUE_PAY_CANCELLED,
28570 amit.gupta 72
				ProfitMandiConstants.URL_PINELABS_PAY_RESPONSE, ProfitMandiConstants.URL_LOAN_CCAVENUE_PAY_CANCELLED,
28566 tejbeer 73
				ProfitMandiConstants.URL_LOAN_CCAVENUE_PAY_RESPONSE, ProfitMandiConstants.URL_POST_OFFICE,
74
				ProfitMandiConstants.URL_NEW_LEAD);
27113 tejbeer 75
 
26863 amit.gupta 76
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**")
27119 tejbeer 77
				.excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN).excludePathPatterns("/**/swagger*/**")
78
				.excludePathPatterns("/v2/**").excludePathPatterns("/document")
79
				.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN,
80
						ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP)
28570 amit.gupta 81
				.excludePathPatterns("/store/token").excludePathPatterns("/gc/**").excludePathPatterns("/stores/**");
27119 tejbeer 82
 
83
		// registry to check api access on basis of UserInfo
21165 ashik.ali 84
	}
27119 tejbeer 85
 
21285 kshitij.so 86
	@Override
87
	public void addCorsMappings(CorsRegistry registry) {
27119 tejbeer 88
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*").allowCredentials(false);
21285 kshitij.so 89
	}
27119 tejbeer 90
 
21272 kshitij.so 91
	private ApiInfo apiInfo() {
27119 tejbeer 92
		@SuppressWarnings("deprecation")
93
		ApiInfo apiInfo = new ApiInfo("ProfitMandi API", "Api's for profitmandi app", "API TOS", "Terms of service",
94
				"New Spice Solutions Pvt. Ltd.", "License of API", "API license URL");
95
		return apiInfo;
21272 kshitij.so 96
	}
27119 tejbeer 97
 
23947 tejbeer 98
	@Override
28574 amit.gupta 99
	public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
28575 amit.gupta 100
		log.info("Converters {}", converters);
28578 amit.gupta 101
		converters = converters.stream().filter(x -> !x.getClass().equals(MappingJackson2HttpMessageConverter.class)).collect(Collectors.toList());
28574 amit.gupta 102
		converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
103
		super.extendMessageConverters(converters);
27119 tejbeer 104
	}
105
 
23949 amit.gupta 106
	@Bean
107
	public ObjectMapper objectMapper() {
27119 tejbeer 108
		ObjectMapper objectMapper = new ObjectMapper();
109
		objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
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
 
27014 amit.gupta 116
	@Override
117
	public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
118
		configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
119
	}
120
 
21220 ashik.ali 121
}