From 1a72d7a3720b2463b1ba2c51e5826620a512ec3d Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 26 Dec 2024 15:09:41 +0100 Subject: [PATCH] override com.sun.jersey.spi.container.servlet.WebComponent #1 --- .../spi/container/servlet/WebComponent.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/web/src/main/java/com/sun/jersey/spi/container/servlet/WebComponent.java b/web/src/main/java/com/sun/jersey/spi/container/servlet/WebComponent.java index 344866818d68..0f3a3d380294 100644 --- a/web/src/main/java/com/sun/jersey/spi/container/servlet/WebComponent.java +++ b/web/src/main/java/com/sun/jersey/spi/container/servlet/WebComponent.java @@ -44,6 +44,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.net.URI; @@ -245,11 +247,21 @@ public void finish() throws IOException { private void writeStatus() { Response.StatusType statusType = cResponse.getStatusType(); final String reasonPhrase = statusType.getReasonPhrase(); - //if (reasonPhrase != null) { - // response.setStatus(statusType.getStatusCode(), reasonPhrase); - //} else { - response.setStatus(statusType.getStatusCode()); - //} + if (reasonPhrase != null) { + try { + response.setStatus(statusType.getStatusCode(), reasonPhrase); + } catch (NoSuchMethodError e) { + try { + Method setError = response.getClass().getMethod("setError", int.class, String.class); + setError.invoke(response, statusType.getStatusCode(), reasonPhrase); + } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) { + //response.setStatus(statusType.getStatusCode()); + response.setStatus(statusType.getStatusCode(), reasonPhrase); + } + } + } else { + response.setStatus(statusType.getStatusCode()); + } } public void write(int b) throws IOException {