Subversion Repositories SmartDukaan

Rev

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