package com.ssyf.common.web.filter;

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(-70)
public class RequestContextInitializationFilter implements Filter {


    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        RequestContextHolder.setContext(request ,response);

        filterChain.doFilter(servletRequest ,servletResponse);

        RequestContextHolder.clear();
    }

}
