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

package com.chushang.common.feign.filter;

import com.chushang.common.feign.interceptor.FeignHeaderInterceptor;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import org.springframework.util.ObjectUtils;

public class TransferFeginFilter implements Filter {
    private String[] attrName;

    public TransferFeginFilter() {
    }

    public TransferFeginFilter(String[] attrName) {
        this.attrName = attrName;
    }

    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)arg0;
        String[] var5 = this.attrName;
        for (String attr : var5) {
            Object value = this.getAttr(req, attr);
            if (!ObjectUtils.isEmpty(value)) {
                FeignHeaderInterceptor.add(attr, value);
            }
        }

        arg2.doFilter(arg0, arg1);
    }

    private Object getAttr(HttpServletRequest req, String key) {
        Object value = req.getParameter(key);
        if (!ObjectUtils.isEmpty(value)) {
            return value;
        } else {
            Object attribute = req.getAttribute(key);
            if (!ObjectUtils.isEmpty(attribute)) {
                return attribute;
            } else {
                attribute = req.getHeader(key);
                if (!ObjectUtils.isEmpty(attribute)) {
                    return attribute;
                } else {
                    Cookie[] cs = req.getCookies();
                    if (!ObjectUtils.isEmpty(cs)) {
                        for (Cookie c : cs) {
                            if (key.equals(c.getName())) {
                                attribute = c.getValue();
                                return attribute;
                            }
                        }
                    }
                    return null;
                }
            }
        }
    }
}
