//package com.elab.log.asepct;
//
//import com.dianping.cat.Cat;
//import com.elab.log.utils.CatMsgConstants;
//import feign.RequestInterceptor;
//import feign.RequestTemplate;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Enumeration;
//
///**
// * 暂时没有作用,目前该类已经迁移到elab-maketing-core核心中去了
// * @author : liukx
// * @create : 2018/7/10 13:55
// * @email  : liukx@elab-plus.com
// */
//@Deprecated
//@Component
//public class FeignInterceptor implements RequestInterceptor {
//
//    private Logger logger = LoggerFactory.getLogger(FeignInterceptor.class);
//
//    @Override
//    public void apply(RequestTemplate requestTemplate) {
//        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
//        requestAttributes.getAttribute(Cat.Context.ROOT, 0);
//        addHead(requestTemplate);
//        // cat 数据
//        String rootId = requestAttributes.getAttribute(Cat.Context.ROOT, 0) == null ? "" : requestAttributes.getAttribute(Cat.Context.ROOT, 0).toString();
//        String childId = requestAttributes.getAttribute(Cat.Context.CHILD, 0) == null ? "" : requestAttributes.getAttribute(Cat.Context.CHILD, 0).toString();
//        String parentId = requestAttributes.getAttribute(Cat.Context.PARENT, 0) == null ? "" : requestAttributes.getAttribute(Cat.Context.CHILD, 0).toString();
//        requestTemplate.header(Cat.Context.ROOT, rootId);
//        requestTemplate.header(Cat.Context.CHILD, childId);
//        requestTemplate.header(Cat.Context.PARENT, parentId);
//        requestTemplate.header(CatMsgConstants.APPLICATION_KEY, Cat.getManager().getDomain());
//        logger.debug(" 开始Feign远程调用 : 请求路径 : " + requestTemplate.url() + " 请求类型 : " + requestTemplate.method());
//    }
//
//
//    /**
//     * 将当前上下文的head带到feign的请求head中去
//     *
//     * @param requestTemplate
//     */
//    private void addHead(RequestTemplate requestTemplate) {
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        Enumeration<String> headerNames = request.getHeaderNames();
//        while (headerNames.hasMoreElements()) {
//            String key = headerNames.nextElement();
//            String value = request.getHeader(key);
//            requestTemplate.header(key, value);
//        }
//    }
//}