Subversion Repositories SmartDukaan

Rev

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