diff --git a/src/main/java/cn/soul2/jyjc/admin/filter/ShaoduoRequestWrapper.java b/src/main/java/cn/soul2/jyjc/admin/filter/ShaoduoRequestWrapper.java index 1de493e..935de92 100644 --- a/src/main/java/cn/soul2/jyjc/admin/filter/ShaoduoRequestWrapper.java +++ b/src/main/java/cn/soul2/jyjc/admin/filter/ShaoduoRequestWrapper.java @@ -51,7 +51,7 @@ public class ShaoduoRequestWrapper extends HttpServletRequestWrapper { * * @return String */ - public String getBodyString() { + public String getBodyString() throws IOException { InputStream inputStream = new ByteArrayInputStream(body); return inputStream2String(inputStream); @@ -73,11 +73,12 @@ public class ShaoduoRequestWrapper extends HttpServletRequestWrapper { * @param inputStream inputStream * @return String */ - private String inputStream2String(InputStream inputStream) { + private String inputStream2String(InputStream inputStream) throws IOException { StringBuilder sb = new StringBuilder(); BufferedReader reader = null; try { + System.out.println("发生流读取"); reader = new BufferedReader(new InputStreamReader(inputStream, Charset.defaultCharset())); String line; while ((line = reader.readLine()) != null) { @@ -93,6 +94,7 @@ public class ShaoduoRequestWrapper extends HttpServletRequestWrapper { } catch (IOException e) { log.error("", e); } + inputStream.close(); } } diff --git a/src/main/java/cn/soul2/jyjc/admin/interceptor/FinallyInterceptor.java b/src/main/java/cn/soul2/jyjc/admin/interceptor/FinallyInterceptor.java index 5d0c3f4..1f64eae 100644 --- a/src/main/java/cn/soul2/jyjc/admin/interceptor/FinallyInterceptor.java +++ b/src/main/java/cn/soul2/jyjc/admin/interceptor/FinallyInterceptor.java @@ -8,9 +8,6 @@ import cn.soul2.jyjc.admin.utils.EncryptUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Lazy; import org.springframework.http.MediaType; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; @@ -29,16 +26,13 @@ import java.lang.reflect.Method; @Slf4j public class FinallyInterceptor implements HandlerInterceptor { - @Autowired - @Lazy - private ApplicationContext context; @Resource - @Lazy private UserLoginStatusBean userLoginStatusBean; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { boolean pass = false; + System.out.println("拦截器触发"); // 允许OPTIONS请求通过 if ("OPTIONS".equals(request.getMethod()) && request.getHeader("Origin") != null) { return true; @@ -104,16 +98,13 @@ public class FinallyInterceptor implements HandlerInterceptor { pass = true; } else { // 验证token - if (userLoginStatusBean == null) { - userLoginStatusBean = context.getBean(UserLoginStatusBean.class); - } // 检查 token 是否存在并且有效 if (token == null) { // 没有Token,拒绝请求 response.setStatus(40401); pass = false; } else if (userLoginStatusBean != null && !userLoginStatusBean.containsToken(token)) { - // Token 无效,拒绝请求,可以返回特定的响应状态码,例如 401 Unauthorized + // Token 无效,拒绝请求 response.setStatus(40401); pass = false; }