Subversion Repositories SmartDukaan

Rev

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