Commit 02062f31e93c00d05a9f445183a45020b7585f06
1 parent
ab992f48
通用http工具类
Showing
2 changed files
with
59 additions
and
3 deletions
ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java
0 → 100644
| 1 | +package com.ruoyi.common.utils.http; | |
| 2 | + | |
| 3 | +import java.io.BufferedReader; | |
| 4 | +import java.io.IOException; | |
| 5 | +import java.io.InputStream; | |
| 6 | +import java.io.InputStreamReader; | |
| 7 | +import java.nio.charset.Charset; | |
| 8 | +import javax.servlet.ServletRequest; | |
| 9 | +import org.apache.commons.lang.exception.ExceptionUtils; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 通用http工具封装 | |
| 15 | + * | |
| 16 | + * @author ruoyi | |
| 17 | + */ | |
| 18 | +public class HttpHelper | |
| 19 | +{ | |
| 20 | + private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class); | |
| 21 | + | |
| 22 | + public static String getBodyString(ServletRequest request) | |
| 23 | + { | |
| 24 | + | |
| 25 | + StringBuilder sb = new StringBuilder(); | |
| 26 | + BufferedReader reader = null; | |
| 27 | + try (InputStream inputStream = request.getInputStream()) | |
| 28 | + { | |
| 29 | + reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); | |
| 30 | + String line = ""; | |
| 31 | + while ((line = reader.readLine()) != null) | |
| 32 | + { | |
| 33 | + sb.append(line); | |
| 34 | + } | |
| 35 | + } | |
| 36 | + catch (IOException e) | |
| 37 | + { | |
| 38 | + LOGGER.warn("getBodyString出现问题!"); | |
| 39 | + } | |
| 40 | + finally | |
| 41 | + { | |
| 42 | + if (reader != null) | |
| 43 | + { | |
| 44 | + try | |
| 45 | + { | |
| 46 | + reader.close(); | |
| 47 | + } | |
| 48 | + catch (IOException e) | |
| 49 | + { | |
| 50 | + LOGGER.error(ExceptionUtils.getFullStackTrace(e)); | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + return sb.toString(); | |
| 55 | + } | |
| 56 | +} | ... | ... |
ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
| ... | ... | @@ -26,7 +26,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
| 26 | 26 | |
| 27 | 27 | public final String REPEAT_TIME = "repeatTime"; |
| 28 | 28 | |
| 29 | - public final String SESSION_REPEAT_KEY = "repeatData"; | |
| 29 | + public final String CACHE_REPEAT_KEY = "repeatData"; | |
| 30 | 30 | |
| 31 | 31 | @Autowired |
| 32 | 32 | private RedisCache redisCache; |
| ... | ... | @@ -62,7 +62,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
| 62 | 62 | // 请求地址(作为存放session的key值) |
| 63 | 63 | String url = request.getRequestURI(); |
| 64 | 64 | |
| 65 | - Object sessionObj = redisCache.getCacheObject(SESSION_REPEAT_KEY); | |
| 65 | + Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY); | |
| 66 | 66 | if (sessionObj != null) |
| 67 | 67 | { |
| 68 | 68 | Map<String, Object> sessionMap = (Map<String, Object>) sessionObj; |
| ... | ... | @@ -77,7 +77,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor |
| 77 | 77 | } |
| 78 | 78 | Map<String, Object> cacheMap = new HashMap<String, Object>(); |
| 79 | 79 | cacheMap.put(url, nowDataMap); |
| 80 | - redisCache.setCacheObject(SESSION_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS); | |
| 80 | + redisCache.setCacheObject(CACHE_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS); | |
| 81 | 81 | return false; |
| 82 | 82 | } |
| 83 | 83 | ... | ... |