diff --git a/src/main/java/io/jboot/support/sentinel/SentinelUtil.java b/src/main/java/io/jboot/support/sentinel/SentinelUtil.java index 6b85d7e14f370bb700be020fda8743dc19af948f..cbba0b82100e70dad5b1928d5b86615ce748257b 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); }