From 02062f31e93c00d05a9f445183a45020b7585f06 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期五, 13 三月 2020 21:18:41 +0800
Subject: [PATCH] 通用http工具类

---
 ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java                      |   56 ++++++++++++++++++++++++++++
 ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java |    6 +-
 2 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java b/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java
new file mode 100644
index 0000000..e7f50b7
--- /dev/null
+++ b/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java
@@ -0,0 +1,56 @@
+package com.ruoyi.common.utils.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import javax.servlet.ServletRequest;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 通用http工具封装
+ * 
+ * @author ruoyi
+ */
+public class HttpHelper
+{
+    private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class);
+
+    public static String getBodyString(ServletRequest request)
+    {
+
+        StringBuilder sb = new StringBuilder();
+        BufferedReader reader = null;
+        try (InputStream inputStream = request.getInputStream())
+        {
+            reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
+            String line = "";
+            while ((line = reader.readLine()) != null)
+            {
+                sb.append(line);
+            }
+        }
+        catch (IOException e)
+        {
+            LOGGER.warn("getBodyString出现问题!");
+        }
+        finally
+        {
+            if (reader != null)
+            {
+                try
+                {
+                    reader.close();
+                }
+                catch (IOException e)
+                {
+                    LOGGER.error(ExceptionUtils.getFullStackTrace(e));
+                }
+            }
+        }
+        return sb.toString();
+    }
+}
diff --git a/ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java b/ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
index 2c3e14e..fd5fa19 100644
--- a/ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
+++ b/ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
@@ -26,7 +26,7 @@
 
     public final String REPEAT_TIME = "repeatTime";
 
-    public final String SESSION_REPEAT_KEY = "repeatData";
+    public final String CACHE_REPEAT_KEY = "repeatData";
 
     @Autowired
     private RedisCache redisCache;
@@ -62,7 +62,7 @@
         // 请求地址(作为存放session的key值)
         String url = request.getRequestURI();
 
-        Object sessionObj = redisCache.getCacheObject(SESSION_REPEAT_KEY);
+        Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY);
         if (sessionObj != null)
         {
             Map<String, Object> sessionMap = (Map<String, Object>) sessionObj;
@@ -77,7 +77,7 @@
         }
         Map<String, Object> cacheMap = new HashMap<String, Object>();
         cacheMap.put(url, nowDataMap);
-        redisCache.setCacheObject(SESSION_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS);
+        redisCache.setCacheObject(CACHE_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS);
         return false;
     }
 

--
Gitblit v1.9.2