package com.ssyf.common.security.filter;

import com.ssyf.common.security.helper.ClientContextHelper;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* 客户信息上下文初始化过滤器
* @author huwei
* @date 2022/7/17 15:53
*/
@Component
@Order(-7000)
public class ClientContextInitializationFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //设置客户端上下文
        ClientContextHolder.init(request ,response);
        //请求继续
        filterChain.doFilter(servletRequest ,servletResponse);
        //清理客户端上下文
        ClientContextHolder.clear();
    }

}
