package org.ta.pddserver.config;

import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
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();
        }
    }
}
