Subversion Repositories SmartDukaan

Rev

Rev 26863 | Rev 27113 | 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;
19
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
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.*")
21165 ashik.ali 40
public class WebMVCConfig extends WebMvcConfigurerAdapter{
41
 
42
	private static final String RESOURCES_PATTERN="/resources/**";
43
	private static final String RESOURCES_LOCATION="/resources/";
44
 
23954 tejbeer 45
 
46
	private static final Logger log = LogManager.getLogger(WebMVCConfig.class);
47
 
21220 ashik.ali 48
	@Autowired
21285 kshitij.so 49
	SimpleCORSInterceptor simpleCORSInterceptor;
21452 amit.gupta 50
 
51
	@Autowired
52
	AuthenticationInterceptor authenticationInterceptor;
21302 ashik.ali 53
 
21272 kshitij.so 54
	@Bean
55
	public Docket api() {
56
		return new Docket(DocumentationType.SWAGGER_2).select()
57
				.apis(RequestHandlerSelectors.any())
58
				.paths(PathSelectors.any()).build()
59
				.apiInfo(apiInfo());
60
	}
61
 
21165 ashik.ali 62
	@Override
21272 kshitij.so 63
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
64
	    registry.addResourceHandler("swagger-ui.html")
65
	      .addResourceLocations("classpath:/META-INF/resources/");
66
	    registry.addResourceHandler("/webjars/**")
67
	      .addResourceLocations("classpath:/META-INF/resources/webjars/");
68
	    registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
69
	}
21165 ashik.ali 70
 
71
	@Override
72
	public void addInterceptors(InterceptorRegistry registry) {
26863 amit.gupta 73
		registry.addInterceptor(simpleCORSInterceptor)
74
			.addPathPatterns("/**")
75
			.excludePathPatterns("/swagger-ui.html", 
76
					ProfitMandiConstants.URL_PAYU_PAY_RESPONSE, 
77
					ProfitMandiConstants.URL_PAYU_PAY_CANCELLED, 
78
					ProfitMandiConstants.URL_CCAVENUE_PAY_RESPONSE,
79
					ProfitMandiConstants.URL_CCAVENUE_PAY_CANCELLED);
80
 
81
		registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**")
82
		.excludePathPatterns(ProfitMandiConstants.URL_ADMIN_TOKEN)
22812 amit.gupta 83
		.excludePathPatterns("/**/swagger*/**").excludePathPatterns("/v2/**").excludePathPatterns("/document")
26522 amit.gupta 84
		.excludePathPatterns(ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, ProfitMandiConstants.URL_USER_GOOGLE_LOGIN + "/", ProfitMandiConstants.URL_VERIFY_OTP)
26611 amit.gupta 85
		.excludePathPatterns("/store/token")
26522 amit.gupta 86
		.excludePathPatterns("/gc/**");
87
 
21469 amit.gupta 88
		//registry to check api access on basis of UserInfo
21165 ashik.ali 89
	}
21272 kshitij.so 90
 
21285 kshitij.so 91
	@Override
92
	public void addCorsMappings(CorsRegistry registry) {
93
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").
94
		allowedHeaders("*").allowCredentials(false);
95
	}
96
 
21272 kshitij.so 97
	private ApiInfo apiInfo() {
98
	    @SuppressWarnings("deprecation")
99
		ApiInfo apiInfo = new ApiInfo(
100
	      "ProfitMandi API",
101
	      "Api's for profitmandi app",
102
	      "API TOS",
103
	      "Terms of service",
104
	      "New Spice Solutions Pvt. Ltd.",
105
	      "License of API",
106
	      "API license URL");
107
	    return apiInfo;
108
	}
23947 tejbeer 109
 
23954 tejbeer 110
 
23947 tejbeer 111
	@Override
23954 tejbeer 112
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
113
 
23947 tejbeer 114
        converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
23954 tejbeer 115
        super.configureMessageConverters(converters);
23947 tejbeer 116
    }
23949 amit.gupta 117
	@Bean
118
	public ObjectMapper objectMapper() {
23954 tejbeer 119
	    ObjectMapper objectMapper = new ObjectMapper();
23965 amit.gupta 120
	    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
23954 tejbeer 121
	    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
122
	    JavaTimeModule javaTimeModule = new JavaTimeModule();
123
	    objectMapper.registerModule(javaTimeModule);
124
	    return objectMapper;
23947 tejbeer 125
	}
27014 amit.gupta 126
 
23954 tejbeer 127
 
27014 amit.gupta 128
	@Override
129
	public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
130
		configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
131
	}
132
 
21220 ashik.ali 133
}