Subversion Repositories SmartDukaan

Rev

Rev 32238 | Rev 32793 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.spice.profitmandi.web.interceptor.AuthenticationInterceptor;
import com.spice.profitmandi.web.interceptor.RoleInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;

@EnableWebMvc
@Configuration
@ComponentScan({ "com.spice.profitmandi.*" })
public class WebConfig extends WebMvcConfigurerAdapter {

        private static final String RESOURCES_PATTERN = "/resources/**";
        private static final String RESOURCES_LOCATION = "/resources/";

        @Autowired
        AuthenticationInterceptor authenticationInterceptor;

        @Autowired
        RoleInterceptor roleInterceptor;

        @Autowired
        ObjectMapper objectMapper;

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler(RESOURCES_PATTERN).addResourceLocations(RESOURCES_LOCATION);
        }

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
                // registry.addInterceptor()
                registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**").excludePathPatterns("/hdfctest/**",
                                "/hdfc/**", "/spicemoney/callback", "/login", "/login/", "/forgetPassword", "/forgetPassword/", "/",
                                "/checkplans", "/12dashboard34", "/mandii", "/imei/validate", "/fundfina/**", "/virtualaccount/push-credits", "/wa-invoice-send/**", "/wa-listen");
                registry.addInterceptor(roleInterceptor).excludePathPatterns("/hdfctest/**", "/hdfc/**", "/spicemoney/callback",
                                "/login", "/login/", "/register", "/register/", "/forgetPassword", "/forgetPassword/", "/", "",
                                "/12dashboard34", "/mandii", "/imei/validate", "/fundfina/**", "/virtualaccount/push-credits", "/wa-invoice-send/**", "/wa-listen");
        }

        @Override
        public void addFormatters(FormatterRegistry registry) {
                DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
                registrar.setUseIsoFormat(true);
                registrar.registerFormatters(registry);
        }

        @Override
        public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
                converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
        }


        @Override
        public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
                configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
        }

}