From 4ecc44cc495a090038ffffdceb4fe03680e5eb2f Mon Sep 17 00:00:00 2001 From: "Nicolas NESMON (NicoNes)" Date: Tue, 10 Aug 2021 14:18:54 -0400 Subject: [PATCH] Introduce Response.isClosed() method with default impl. Signed-off-by: Nicolas NESMON (NicoNes) --- .../main/java/jakarta/ws/rs/core/Response.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/core/Response.java b/jaxrs-api/src/main/java/jakarta/ws/rs/core/Response.java index 82e85d704..5d3c1b987 100644 --- a/jaxrs-api/src/main/java/jakarta/ws/rs/core/Response.java +++ b/jaxrs-api/src/main/java/jakarta/ws/rs/core/Response.java @@ -463,6 +463,22 @@ public MultivaluedMap getHeaders() { */ public abstract String getHeaderString(String name); + /** + * Check if the response is closed. The method returns {@code true} if the response is closed, + * returns {@code false} otherwise. + * + * @return {@code true} if the response has been {@link #close() closed}, {@code false} otherwise. + * @since 3.1 + */ + public boolean isClosed() { + try { + hasEntity(); + return false; + } catch (IllegalStateException ignored) { + return true; + } + } + /** * Create a new ResponseBuilder by performing a shallow copy of an existing Response. *