Subversion Repositories SmartDukaan

Rev

Rev 26611 | Rev 27014 | 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) {
26863 amit.gupta 71
		registry.addInterceptor(simpleCORSInterceptor)
72
			.addPathPatterns("/**")
73
			.excludePathPatterns("/swagger-ui.html", 
74
					ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, 
75
					ProfitMandiConstants.URL_PAYU_PAY_CANCELLED, 
76
					ProfitMandiConstants.URL_CCAVENUE_PAY_RESPONSE,
77
					ProfitMandiConstants.URL_CCAVENUE_PAY_CANCELLED);
78
 
79
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**")
80
		.excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
22812 amit.gupta 81
		.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**").excludePathPatterns("/document")
26522 amit.gupta 82
		.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP)
26611 amit.gupta 83
		.excludePathPatterns("/store/token")
26522 amit.gupta 84
		.excludePathPatterns("/gc/**");
85
 
21469 amit.gupta 86
		//registry to check api access on basis of UserInfo
21165 ashik.ali 87
	}
21272 kshitij.so 88
 
21285 kshitij.so 89
	@Override
90
	public void addCorsMappings(CorsRegistry registry) {
91
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
92
		allowedHeaders("*").allowCredentials(false);
93
	}
94
 
21272 kshitij.so 95
	private ApiInfo apiInfo() {
96
	    @SuppressWarnings("deprecation")
97
		ApiInfo apiInfo = new ApiInfo(
98
	      "ProfitMandi API",
99
	      "Api's for profitmandi app",
100
	      "API TOS",
101
	      "Terms of service",
102
	      "New Spice Solutions Pvt. Ltd.",
103
	      "License of API",
104
	      "API license URL");
105
	    return apiInfo;
106
	}
23947 tejbeer 107
 
23954 tejbeer 108
 
23947 tejbeer 109
	@Override
23954 tejbeer 110
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
111
 
23947 tejbeer 112
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
23954 tejbeer 113
        super.configureMessageConverters(converters);
23947 tejbeer 114
    }
23949 amit.gupta 115
	@Bean
116
	public ObjectMapper objectMapper() {
23954 tejbeer 117
	    ObjectMapper objectMapper = new ObjectMapper();
23965 amit.gupta 118
	    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
23954 tejbeer 119
	    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
120
	    JavaTimeModule javaTimeModule = new JavaTimeModule();
121
	    objectMapper.registerModule(javaTimeModule);
122
	    return objectMapper;
23947 tejbeer 123
	}
23954 tejbeer 124
 
21220 ashik.ali 125
}