admin
2024-10-15 6d313a4a6f9f9d7ea65ec50ab0d4491e595edb97
提交 | 用户 | 时间
e57a89 1 package com.jcdm.common.filter;
2
3 import java.io.IOException;
4 import javax.servlet.Filter;
5 import javax.servlet.FilterChain;
6 import javax.servlet.FilterConfig;
7 import javax.servlet.ServletException;
8 import javax.servlet.ServletRequest;
9 import javax.servlet.ServletResponse;
10 import javax.servlet.http.HttpServletRequest;
11 import org.springframework.http.MediaType;
12 import com.jcdm.common.utils.StringUtils;
13
14 /**
15  * Repeatable 过滤器
16  * 
17  * @author jc
18  */
19 public class RepeatableFilter implements Filter
20 {
21     @Override
22     public void init(FilterConfig filterConfig) throws ServletException
23     {
24
25     }
26
27     @Override
28     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
29             throws IOException, ServletException
30     {
31         ServletRequest requestWrapper = null;
32         if (request instanceof HttpServletRequest
33                 && StringUtils.startsWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE))
34         {
35             requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response);
36         }
37         if (null == requestWrapper)
38         {
39             chain.doFilter(request, response);
40         }
41         else
42         {
43             chain.doFilter(requestWrapper, response);
44         }
45     }
46
47     @Override
48     public void destroy()
49     {
50
51     }
52 }