From 92ac562341115251fbcd5012f6e17e53a7cc5e30 Mon Sep 17 00:00:00 2001 From: caoyuan Date: Sat, 9 Sep 2023 17:10:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:SentinelInterceptor=20=E6=8D=95=E8=8E=B7?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=90=8E=EF=BC=8C=E6=B8=B2=E6=9F=93=E5=AE=8C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E8=A6=81=E5=85=B3=E9=97=AD=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jboot/support/sentinel/SentinelUtil.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/jboot/support/sentinel/SentinelUtil.java b/src/main/java/io/jboot/support/sentinel/SentinelUtil.java index 6b85d7e1..cbba0b82 100644 --- a/src/main/java/io/jboot/support/sentinel/SentinelUtil.java +++ b/src/main/java/io/jboot/support/sentinel/SentinelUtil.java @@ -15,16 +15,18 @@ */ package io.jboot.support.sentinel; -import com.alibaba.csp.sentinel.util.StringUtil; -import com.jfinal.kit.JsonKit; -import com.jfinal.kit.LogKit; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.alibaba.csp.sentinel.util.StringUtil; +import com.jfinal.kit.JsonKit; +import com.jfinal.kit.LogKit; +import com.jfinal.log.Log; + /** * @author michael yang (fuhai999@gmail.com) * @Date: 2020/3/22 @@ -172,13 +174,24 @@ public class SentinelUtil { resp.setContentType(contentType); PrintWriter out = resp.getWriter(); out.print(JsonKit.toJson(map)); + close(out); } + private static void close(AutoCloseable autoCloseable) { + if (autoCloseable != null) { + try { + autoCloseable.close(); + } catch (Exception e) { + Log.getLog(SentinelUtil.class).error(e.getMessage(), e); + } + } + } public static void writeDefaultBlockedPage(HttpServletResponse resp) throws IOException { resp.setStatus(200); PrintWriter out = resp.getWriter(); out.print("Blocked by Sentinel (flow limiting) in Jboot"); + close(out); } -- Gitee