Subversion Repositories SmartDukaan

Rev

Rev 33760 | Rev 35033 | 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.PostInterceptor;
import com.spice.profitmandi.web.interceptor.RoleInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
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.LocaleResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.util.List;
import java.util.Locale;

@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;

    //This interceptor is to ensures only single POST Request is passed at a moment
    //based on idempotency key provided through client side
    @Autowired
    PostInterceptor postInterceptor;

    @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(localeChangeInterceptor());
        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/**",
                "/click2call/report-handler", "/click2call/report-handler/recording-url", "/wa-listen", "/upsellPayment/callback");
        registry.addInterceptor(roleInterceptor).excludePathPatterns("/hdfctest/**", "/hdfc/**", "/spicemoney/callback", "/upsellPayment/callback", "/click2call/report-handler/recording-url", "/click2call/report-handler",
                "/login", "/login/", "/register", "/register/", "/forgetPassword", "/forgetPassword/", "/", "",
                "/12dashboard34", "/mandii", "/imei/validate", "/fundfina/**", "/virtualaccount/push-credits", "/wa-invoice-send/**", "/wa-listen","/sendInvoiceOnWhatsApp");
        registry.addInterceptor(postInterceptor).addPathPatterns("/**").excludePathPatterns("/reports/**", "/hdfctest/**",
                "/hdfc/**", "/spicemoney/callback", "/login", "/login/", "/forgetPassword", "/forgetPassword/", "/", "/checkplans", "/12dashboard34", "/mandii", "/imei/validate", "/fundfina/**", "/virtualaccount/push-credits", "/wa-invoice-send/**",
                "/click2call/report-handler", "/click2call/report-handler/recording-url", "/wa-listen", "/upsellPayment/callback");
    }

    @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);
    }

    @Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver slr = new SessionLocaleResolver();
        slr.setDefaultLocale(Locale.US);
        return slr;
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
        lci.setParamName("lang");
        return lci;
    }


        /*@Override
        public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
                StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
                stringConverter.setSupportedMediaTypes(Arrays.asList(new MediaType("text", "plain", StandardCharsets.UTF_8)));
                converters.add(stringConverter);

                // Add other converters ...
        }
*/

}