From 039ba66db63ef5a30231247dd83efe40504de6bc Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Wed, 6 Nov 2024 12:36:35 +0100 Subject: [PATCH] Review comments Signed-off-by: Jorge Bescos Gascon --- .../message/internal/OutboundJaxrsResponse.java | 3 +-- .../message/internal/OutboundMessageContext.java | 12 +++++++++--- .../jersey/tests/e2e/server/Issue5783Test.java | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundJaxrsResponse.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundJaxrsResponse.java index 61ba445a60..d63e0a90e7 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundJaxrsResponse.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundJaxrsResponse.java @@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.UncheckedIOException; import java.lang.annotation.Annotation; import java.net.URI; import java.util.Arrays; @@ -205,7 +204,7 @@ public void close() throws ProcessingException { closed = true; try { context.close(); - } catch (IOException | UncheckedIOException e) { + } catch (Exception e) { // Just log the exception Logger.getLogger(OutboundJaxrsResponse.class.getName()).log(Level.FINE, e.getMessage(), e); } diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundMessageContext.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundMessageContext.java index ee441ab34f..efadde6fc7 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundMessageContext.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundMessageContext.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.io.UncheckedIOException; import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.ArrayList; @@ -555,9 +556,9 @@ public boolean isCommitted() { /** * Closes the context. Flushes and closes the entity stream. - * @throws IOException if errors + * @throws UncheckedIOException if IO errors */ - public void close() throws IOException { + public void close() { if (hasEntity()) { try { final OutputStream es = getEntityStream(); @@ -565,12 +566,17 @@ public void close() throws IOException { es.flush(); } es.close(); + } catch (IOException e) { + throw new UncheckedIOException(e); } finally { // In case some of the output stream wrapper does not delegate close() call we // close the root stream manually to make sure it commits the data. if (!committingOutputStream.isClosed()) { - // It is possible that es.flush() or es.close() threw one exception already and we throw a new one here. + try { committingOutputStream.close(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } } } diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/Issue5783Test.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/Issue5783Test.java index e084f4d13f..cc1c873b13 100644 --- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/Issue5783Test.java +++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/Issue5783Test.java @@ -69,7 +69,7 @@ public Response closeException(@Context ContainerRequest request) { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("failure".equals(method.getName())) { - exceptionMessage = ((Throwable) args[0]).getMessage(); + exceptionMessage = ((Throwable) args[0]).getCause().getMessage(); } return method.invoke(writer, args); }