//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.chushang.common.feign.registrar;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.Filter;

import com.chushang.common.feign.filter.MdcFilter;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MdcFilterRegistrar implements ImportBeanDefinitionRegistrar {
    public MdcFilterRegistrar() {
    }

    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        Filter filter = new MdcFilter();
        List<String> patter = new ArrayList<>();
        patter.add("/*");
        BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(FilterRegistrationBean.class);
        beanDefinitionBuilder.addPropertyValue("filter", filter);
        beanDefinitionBuilder.addPropertyValue("order", 3);
        beanDefinitionBuilder.addPropertyValue("urlPatterns", patter);
        AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
        beanDefinition.setBeanClass(FilterRegistrationBean.class);
        beanDefinition.setScope("singleton");
        registry.registerBeanDefinition(filter.getClass().getName(), beanDefinition);
    }
}
