package org.ta.pddserver.config;

import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class RepeatedlyReadFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        ServletRequest wrapper = new RepeatedReadRequestWrapper(request);
        try{
            filterChain.doFilter(wrapper, servletResponse);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("RepeatedlyReadFilter doFilter ok");
    }

}
