package com.hzs.common.core.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * description: 用于去除前后空格的过滤器
 * @author: sui q
 * @time: 2023/4/3 14:10
 * @classname: TrimFilter
 * @package_name: com.hzs.gateway.config
 * version 1.0.0
 */
@Component
@WebFilter(urlPatterns = "/**", filterName = "paramsFilter", dispatcherTypes = DispatcherType.REQUEST)
@Slf4j
public class TrimFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
            throws IOException, ServletException {
        TrimRequestWrapper trimRequest = new TrimRequestWrapper((HttpServletRequest) request);
        filterChain.doFilter(trimRequest, response);
    }

    @Override
    public void destroy() {
        log.info("销毁");
    }

    @Override
    public void init(FilterConfig arg0) {
        log.info("创建");
    }

}
