| | |
| | | package com.ruoyi.gateway.filter; |
| | | |
| | | import com.ruoyi.gateway.config.properties.AntiShakeProperties; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | // 排除过滤的 uri 地址,nacos自行添加 |
| | | @Autowired |
| | | private IgnoreWhiteProperties ignoreWhite; |
| | | @Autowired |
| | | private AntiShakeProperties antiShakeProperties; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | |
| | | |
| | | |
| | |
| | | try { |
| | | antiShake(request); |
| | | }catch (Exception e){ |
| | | log.error("[重复提交]请求路径:{}", exchange.getRequest().getPath()); |
| | | log.error(e.getMessage()); |
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage(), HttpStatus.SUCCESS); |
| | | } |
| | | |
| | |
| | | */ |
| | | public void antiShake(ServerHttpRequest request) throws Exception{ |
| | | HttpMethod method = request.getMethod(); |
| | | if(HttpMethod.OPTIONS == method){ |
| | | if(HttpMethod.OPTIONS == method || !antiShakeProperties.getEnable()){ |
| | | return; |
| | | } |
| | | HttpHeaders headers = request.getHeaders(); |
| | |
| | | Long old_timestamp = Long.valueOf(o.toString()); |
| | | Long new_timestamp = Long.valueOf(timestamp); |
| | | //两个请求时间差小于1秒,判定为重复提交 |
| | | if((new_timestamp - old_timestamp) <= 500){ |
| | | throw new RuntimeException("重复提交"); |
| | | if((new_timestamp - old_timestamp) <= antiShakeProperties.getInterval()){ |
| | | throw new RuntimeException(url + "----->重复提交"); |
| | | }else{ |
| | | cacheMap.put(url, timestamp); |
| | | } |