From 851a045e61580f6ee471213f591ac65a01d15bb5 Mon Sep 17 00:00:00 2001 From: jansupol Date: Mon, 2 Sep 2024 16:58:13 +0200 Subject: [PATCH 1/2] Created FlushedCloseable interface to be passed to Context#setOutputStream Signed-off-by: jansupol --- .../org/glassfish/jersey/io/package-info.java | 20 +++++++ .../jersey/io/spi/FlushedCloseable.java | 55 +++++++++++++++++++ .../glassfish/jersey/io/spi/package-info.java | 20 +++++++ .../internal/OutboundMessageContext.java | 18 ++---- .../internal/OutboundMessageContextTest.java | 42 +++++++++++++- 5 files changed, 141 insertions(+), 14 deletions(-) create mode 100644 core-common/src/main/java/org/glassfish/jersey/io/package-info.java create mode 100644 core-common/src/main/java/org/glassfish/jersey/io/spi/FlushedCloseable.java create mode 100644 core-common/src/main/java/org/glassfish/jersey/io/spi/package-info.java diff --git a/core-common/src/main/java/org/glassfish/jersey/io/package-info.java b/core-common/src/main/java/org/glassfish/jersey/io/package-info.java new file mode 100644 index 0000000000..f913ae650d --- /dev/null +++ b/core-common/src/main/java/org/glassfish/jersey/io/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * Common Jersey core io classes. + */ +package org.glassfish.jersey.io; diff --git a/core-common/src/main/java/org/glassfish/jersey/io/spi/FlushedCloseable.java b/core-common/src/main/java/org/glassfish/jersey/io/spi/FlushedCloseable.java new file mode 100644 index 0000000000..12aa7144d8 --- /dev/null +++ b/core-common/src/main/java/org/glassfish/jersey/io/spi/FlushedCloseable.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.io.spi; + +import java.io.Closeable; +import java.io.Flushable; +import java.io.IOException; +import java.io.OutputStream; + +/** + * A marker interface that the stream provided to Jersey can implement, + * noting that the stream does not need to call {@link #flush()} prior to {@link #close()}. + * That way, {@link #flush()} method is not called twice. + * + *

+ * Usable by {@link javax.ws.rs.client.ClientRequestContext#setEntityStream(OutputStream)}. + * Usable by {@link javax.ws.rs.container.ContainerResponseContext#setEntityStream(OutputStream)}. + *

+ * + *

+ * This marker interface can be useful for the customer OutputStream to know the {@code flush} did not come from + * Jersey before close. By default, when the entity stream is to be closed by Jersey, {@code flush} is called first. + *

+ */ +public interface FlushedCloseable extends Flushable, Closeable { + /** + * Flushes this stream by writing any buffered output to the underlying stream. + * Then closes this stream and releases any system resources associated + * with it. If the stream is already closed then invoking this + * method has no effect. + * + *

As noted in {@link AutoCloseable#close()}, cases where the + * close may fail require careful attention. It is strongly advised + * to relinquish the underlying resources and to internally + * mark the {@code Closeable} as closed, prior to throwing + * the {@code IOException}. + * + * @throws IOException if an I/O error occurs + */ + public void close() throws IOException; +} diff --git a/core-common/src/main/java/org/glassfish/jersey/io/spi/package-info.java b/core-common/src/main/java/org/glassfish/jersey/io/spi/package-info.java new file mode 100644 index 0000000000..7a70945f25 --- /dev/null +++ b/core-common/src/main/java/org/glassfish/jersey/io/spi/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * Common Jersey core io SPI classes. + */ +package org.glassfish.jersey.io.spi; 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 dd5816f0a3..3265a96340 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 @@ -20,43 +20,33 @@ import java.io.OutputStream; import java.lang.annotation.Annotation; import java.lang.reflect.Type; -import java.net.URI; -import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Set; import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; -import javax.ws.rs.ProcessingException; import javax.ws.rs.core.Configuration; -import javax.ws.rs.core.Cookie; -import javax.ws.rs.core.EntityTag; import javax.ws.rs.core.GenericEntity; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Link; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.NewCookie; -import javax.ws.rs.ext.RuntimeDelegate; import org.glassfish.jersey.CommonProperties; import org.glassfish.jersey.internal.RuntimeDelegateDecorator; -import org.glassfish.jersey.internal.LocalizationMessages; import org.glassfish.jersey.internal.util.ReflectionHelper; import org.glassfish.jersey.internal.util.collection.GuardianStringKeyMultivaluedMap; import org.glassfish.jersey.internal.util.collection.LazyValue; import org.glassfish.jersey.internal.util.collection.Value; import org.glassfish.jersey.internal.util.collection.Values; +import org.glassfish.jersey.io.spi.FlushedCloseable; /** * Base outbound message context implementation. @@ -572,11 +562,13 @@ public void close() { if (hasEntity()) { try { final OutputStream es = getEntityStream(); - es.flush(); + if (!FlushedCloseable.class.isInstance(es)) { + es.flush(); + } es.close(); } catch (IOException e) { // Happens when the client closed connection before receiving the full response. - // This is OK and not interesting in vast majority of the cases + // This is OK and not interesting in the vast majority of the cases // hence the log level set to FINE to make sure it does not flood the log unnecessarily // (especially for clients disconnecting from SSE listening, which is very common). Logger.getLogger(OutboundMessageContext.class.getName()).log(Level.FINE, e.getMessage(), e); diff --git a/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/message/internal/OutboundMessageContextTest.java b/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/message/internal/OutboundMessageContextTest.java index 1327edd53d..a909dfaac7 100644 --- a/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/message/internal/OutboundMessageContextTest.java +++ b/tests/e2e-core-common/src/test/java/org/glassfish/jersey/tests/e2e/common/message/internal/OutboundMessageContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -16,6 +16,9 @@ package org.glassfish.jersey.tests.e2e.common.message.internal; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; import java.text.ParseException; @@ -33,10 +36,13 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.ext.RuntimeDelegate; +import org.glassfish.jersey.io.spi.FlushedCloseable; import org.glassfish.jersey.message.internal.CookieProvider; import org.glassfish.jersey.message.internal.OutboundMessageContext; import org.glassfish.jersey.tests.e2e.common.TestRuntimeDelegate; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.contains; @@ -271,4 +277,38 @@ public void testCopyConstructor() { newCtx.setMediaType(MediaType.APPLICATION_XML_TYPE); // new value Assertions.assertEquals(MediaType.APPLICATION_XML_TYPE, newCtx.getMediaType()); } + + @Test + public void OutboundMessageContextFlushTest() throws IOException { + FlushCountOutputStream os = new FlushCountOutputStream(); + OutboundMessageContext ctx = new OutboundMessageContext((Configuration) null); + ctx.setEntity("Anything"); + ctx.setEntityStream(os); + os.flush(); + ctx.close(); + MatcherAssert.assertThat(os.flushedCnt, Matchers.is(2)); + + os = new FlushedClosableOutputStream(); + ctx = new OutboundMessageContext((Configuration) null); + ctx.setEntity("Anything2"); + ctx.setEntityStream(os); + os.flush(); + ctx.close(); + MatcherAssert.assertThat(os.flushedCnt, Matchers.is(1)); + } + + private static class FlushCountOutputStream extends ByteArrayOutputStream { + private int flushedCnt = 0; + + @Override + public void flush() throws IOException { + flushedCnt++; + super.flush(); + } + } + + private static class FlushedClosableOutputStream extends FlushCountOutputStream implements FlushedCloseable { + + } } + From 2fd3e28a206f02a4d31331092fd6546d6d4d770f Mon Sep 17 00:00:00 2001 From: Maxim Nesen Date: Wed, 21 Aug 2024 14:25:49 +0200 Subject: [PATCH 2/2] Non-jakarta versions update Signed-off-by: Maxim Nesen --- NOTICE.md | 2 +- examples/NOTICE.md | 2 +- examples/extended-wadl-webapp/pom.xml | 4 +- .../osgi-http-service/functional-test/pom.xml | 4 +- examples/servlet3-webapp/pom.xml | 9 +++ .../jackson/jaxrs/json/PackageVersion.java | 2 +- .../main/resources/META-INF/NOTICE.markdown | 2 +- pom.xml | 65 ++++++++++--------- 8 files changed, 50 insertions(+), 40 deletions(-) diff --git a/NOTICE.md b/NOTICE.md index 56231f8752..a677353a1c 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -70,7 +70,7 @@ Javassist Version 3.30.2-GA * Project: http://www.javassist.org/ * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. -Jackson JAX-RS Providers Version 2.17.1 +Jackson JAX-RS Providers Version 2.17.2 * License: Apache License, 2.0 * Project: https://github.com/FasterXML/jackson-jaxrs-providers * Copyright: (c) 2009-2024 FasterXML, LLC. All rights reserved unless otherwise indicated. diff --git a/examples/NOTICE.md b/examples/NOTICE.md index 5724485fbf..9901b179f3 100644 --- a/examples/NOTICE.md +++ b/examples/NOTICE.md @@ -66,7 +66,7 @@ Javassist Version 3.30.2-GA * Project: http://www.javassist.org/ * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. -Jackson JAX-RS Providers Version 2.17.1 +Jackson JAX-RS Providers Version 2.17.2 * License: Apache License, 2.0 * Project: https://github.com/FasterXML/jackson-jaxrs-providers * Copyright: (c) 2009-2023 FasterXML, LLC. All rights reserved unless otherwise indicated. diff --git a/examples/extended-wadl-webapp/pom.xml b/examples/extended-wadl-webapp/pom.xml index 896643a83a..86dd152666 100644 --- a/examples/extended-wadl-webapp/pom.xml +++ b/examples/extended-wadl-webapp/pom.xml @@ -108,8 +108,8 @@ org.slf4j - slf4j-log4j12 - 2.0.13 + slf4j-reload4j + ${slf4j.version} test diff --git a/examples/osgi-http-service/functional-test/pom.xml b/examples/osgi-http-service/functional-test/pom.xml index 7c8c55e6b2..b84d3366f6 100644 --- a/examples/osgi-http-service/functional-test/pom.xml +++ b/examples/osgi-http-service/functional-test/pom.xml @@ -144,8 +144,8 @@ org.slf4j - slf4j-log4j12 - 2.0.13 + slf4j-reload4j + ${slf4j.version} test diff --git a/examples/servlet3-webapp/pom.xml b/examples/servlet3-webapp/pom.xml index 995907fd49..5fcebbf424 100644 --- a/examples/servlet3-webapp/pom.xml +++ b/examples/servlet3-webapp/pom.xml @@ -107,6 +107,15 @@ + + jdk8_tests + + 1.8 + + + ${junit5.jdk8.version} + + pre-release diff --git a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/jackson/jaxrs/json/PackageVersion.java b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/jackson/jaxrs/json/PackageVersion.java index 5d328da992..56b1bf6480 100644 --- a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/jackson/jaxrs/json/PackageVersion.java +++ b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/jackson/jaxrs/json/PackageVersion.java @@ -11,7 +11,7 @@ */ public final class PackageVersion implements Versioned { public final static Version VERSION = VersionUtil.parseVersion( - "2.17.1", "com.fasterxml.jackson.jaxrs", "jackson-jaxrs-json-provider"); + "2.17.2", "com.fasterxml.jackson.jaxrs", "jackson-jaxrs-json-provider"); @Override public Version version() { diff --git a/media/json-jackson/src/main/resources/META-INF/NOTICE.markdown b/media/json-jackson/src/main/resources/META-INF/NOTICE.markdown index 4edecfc595..9440229038 100644 --- a/media/json-jackson/src/main/resources/META-INF/NOTICE.markdown +++ b/media/json-jackson/src/main/resources/META-INF/NOTICE.markdown @@ -31,7 +31,7 @@ The project maintains the following source code repositories: ## Third-party Content -Jackson JAX-RS Providers version 2.17.1 +Jackson JAX-RS Providers version 2.17.2 * License: Apache License, 2.0 * Project: https://github.com/FasterXML/jackson-jaxrs-providers * Copyright: (c) 2009-2023 FasterXML, LLC. All rights reserved unless otherwise indicated. diff --git a/pom.xml b/pom.xml index 77adab9060..e43d05907e 100644 --- a/pom.xml +++ b/pom.xml @@ -2150,13 +2150,13 @@ 3.1.0 1.10.14 3.7.1 - 3.3.2 - 3.4.1 - 3.2.0 - 3.5.0 + 3.4.0 + 3.5.0 + 3.4.1 + 3.6.0 3.2.0 - 3.3.1 - 10.16.0 + 3.4.0 + 10.17.0 3.13.0 3.9.0 - 2.8.0 - 3.6.1 + 2.8.1 + 3.7.1 3.1.2 3.3.0 - 3.2.5 + 3.3.1 5.1.9 3.0.5 5.1 3.1.2 4.2.0 - 3.4.1 - 3.6.3 - 3.3.2 + 3.4.2 + 3.8.0 + 3.4.0 1.2.4 - 3.5.0 + 3.6.2 3.3.1 - 3.5.3 + 3.6.0 3.3.1 - 3.2.5 + 3.3.1 3.4.0 2.11.0 1.1.0 @@ -2197,28 +2197,28 @@ 9.7 - 1.9.22 + 1.9.22.1 2.16.1 - 1.3.1 + 1.3.3 1.7.0 1.6.4 2.8.4 7.0.5 1.7 - 2.3.32 - 2.0.26 - 4.0.21 - 2.10.1 - 33.1.0-jre - 2.2 + 2.3.33 + 2.0.29 + 4.0.22 + 2.11.0 + 33.3.0-jre + 3.0 1.4.14 2.2.1 2.10.0 4.5.14 5.3.1 - 2.17.1 + 2.17.2 1.9.13 3.30.2-GA 1.19.3 @@ -2230,12 +2230,13 @@ 1.37 1.49 4.13.2 - 5.10.2 - 1.10.2 + 5.11.0 + 5.10.3 + 1.11.0 4.0.3 4.11.0 - 0.9.12 - 4.1.109.Final + 0.9.14 + 4.1.112.Final 0.33.0 6.0.0 1.10.0 @@ -2246,12 +2247,12 @@ 1.3.8 2.2.21 6.0.1 - 2.0.13 + 2.0.16 1.3.11 4.3.30.RELEASE 5.3.34 7.10.2 - 6.9.13.6 + 6.14.3 6.2.5.Final 3.1.9.Final @@ -2259,7 +2260,7 @@ 2.12.2 - 20.3.14 + 20.3.15 2.0.SP1 @@ -2288,7 +2289,7 @@ 2.1.6 6.1.26 org.eclipse.jetty.*;version="[9.4,11)" - 9.4.54.v20240208 + 9.4.55.v20240627 6.1.14 1.0.2 1.1.6