Subversion Repositories SmartDukaan

Rev

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