From 4e712dcb431a372dcf67e18cb570cfc14b60c4a2 Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Tue, 13 Feb 2024 15:00:08 -0600 Subject: [PATCH 1/9] Add changes from release-3.1.x TCK to release-3.2 --- jaxrs-tck-docs/TCK-Exclude-List.txt | 11 ++++++++++- jaxrs-tck-docs/tckbundle.sh | 11 +++++++++-- .../rs/container/responsecontext/JAXRSClientIT.java | 7 +++++-- .../tck/ws/rs/ee/rs/core/uriinfo/JAXRSClientIT.java | 4 +++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/jaxrs-tck-docs/TCK-Exclude-List.txt b/jaxrs-tck-docs/TCK-Exclude-List.txt index c1c1b0587..3d77d18f3 100644 --- a/jaxrs-tck-docs/TCK-Exclude-List.txt +++ b/jaxrs-tck-docs/TCK-Exclude-List.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2021, 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 @@ -76,6 +76,9 @@ ee/jakarta/tck/ws/rs/jaxrs21/ee/client/executor/async/JAXRSClientIT.java#traceWi ee/jakarta/tck/ws/rs/jaxrs21/ee/client/executor/async/JAXRSClientIT.java#traceWithStringCallbackWhileServerWaitTest ee/jakarta/tck/ws/rs/jaxrs21/ee/client/executor/async/JAXRSClientIT.java#traceWithStringClassWhileServerWaitTest +# https://github.com/jakartaee/rest/issues/1162 +ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java#sseBroadcastTest + # # ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/JAXRSClientIT.java#connectionLostForDefault500msTest @@ -152,3 +155,9 @@ ee/jakarta/tck/ws/rs/jaxrs21/ee/client/rxinvoker/JAXRSClientIT.java#traceWithStr ee/jakarta/tck/ws/rs/jaxrs21/ee/client/rxinvoker/JAXRSClientIT.java#traceWithResponseClassTest ee/jakarta/tck/ws/rs/jaxrs21/ee/client/rxinvoker/JAXRSClientIT.java#traceWithGenericTypeStringTest ee/jakarta/tck/ws/rs/jaxrs21/ee/client/rxinvoker/JAXRSClientIT.java#traceWithGenericTypeResponseTest + +https://github.com/jakartaee/rest/issues/1138 +ee/jakarta/tck/ws/rs/ee/rs/core/uriinfo/JAXRSClientIT#getNormalizedUriTest + +https://github.com/jakartaee/rest/issues/1163 +ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT#setEntityStreamTest \ No newline at end of file diff --git a/jaxrs-tck-docs/tckbundle.sh b/jaxrs-tck-docs/tckbundle.sh index d7cb70b6c..fa2c70ed2 100644 --- a/jaxrs-tck-docs/tckbundle.sh +++ b/jaxrs-tck-docs/tckbundle.sh @@ -1,6 +1,6 @@ #!/bin/bash -xe -# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. +# 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 @@ -40,6 +40,7 @@ mvn rm -rf $WORKSPACE/bundle +mkdir -p $WORKSPACE/bundle mkdir -p $WORKSPACE/bundle/docs mkdir -p $WORKSPACE/bundle/docs/html-usersguide mkdir -p $WORKSPACE/bundle/docs/pdf-usersguide @@ -51,17 +52,23 @@ cp $WORKSPACE/jaxrs-tck-docs/*.html $WORKSPACE/bundle/docs/ cp $WORKSPACE/jaxrs-tck-docs/*.txt $WORKSPACE/bundle/docs/ cp -r $WORKSPACE/jaxrs-tck-docs/assertions $WORKSPACE/bundle/docs/ -mkdir -p $WORKSPACE/bundle cp $WORKSPACE/jaxrs-tck/target/*.jar $WORKSPACE/bundle/ cd $WORKSPACE/bundle +mkdir -p $WORKSPACE/bundle/META-INF if [[ "$1" == "epl" || "$1" == "EPL" ]]; then cp $WORKSPACE/LICENSE.md $WORKSPACE/bundle/LICENSE.md + cp $WORKSPACE/LICENSE.md $WORKSPACE/bundle/META-INF/LICENSE.md cp $WORKSPACE/jaxrs-tck/pom.epl.xml $WORKSPACE/bundle/restful-ws-tck-"$VERSION".pom + jar -uvf restful-ws-tck-"$VERSION".jar META-INF/LICENSE.md + rm -rf $WORKSPACE/bundle/META-INF zip -r restful-ws-tck-"$VERSION".zip * else cp $WORKSPACE/jaxrs-tck-docs/LICENSE_EFTL.md $WORKSPACE/bundle/LICENSE.md + cp $WORKSPACE/jaxrs-tck-docs/LICENSE_EFTL.md $WORKSPACE/bundle/META-INF/LICENSE.md cp $WORKSPACE/jaxrs-tck/pom.xml $WORKSPACE/bundle/jakarta-restful-ws-tck-"$VERSION".pom + jar -uvf jakarta-restful-ws-tck-"$VERSION".jar META-INF/LICENSE.md + rm -rf $WORKSPACE/bundle/META-INF zip -r jakarta-restful-ws-tck-"$VERSION".zip * fi diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java index c40db3fbc..e2dfd3706 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020 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 @@ -53,7 +53,7 @@ import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.AfterEach; - +import org.junit.jupiter.api.Disabled; /* * @class.setup_props: webServerHost; * webServerPort; @@ -1103,6 +1103,7 @@ public void setEntityTest() throws Fault { * Throws IOException. */ @Test + @Disabled public void setEntityStreamTest() throws Fault { setProperty(Property.SEARCH_STRING, ResponseFilter.ENTITY); setProperty(Property.SEARCH_STRING, "OK"); @@ -1121,6 +1122,7 @@ public void setEntityStreamTest() throws Fault { * Throws IOException. */ @Test + @Disabled public void setStatusTest() throws Fault { for (Response.Status status : Response.Status.values()) { String content = String.valueOf(status.getStatusCode()); @@ -1142,6 +1144,7 @@ public void setStatusTest() throws Fault { * Throws IOException. */ @Test + @Disabled public void setStatusInfoTest() throws Fault { for (Response.Status status : Response.Status.values()) { String content = String.valueOf(status.getStatusCode()); diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/uriinfo/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/uriinfo/JAXRSClientIT.java index 3fbaaa58c..52a001c55 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/uriinfo/JAXRSClientIT.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/uriinfo/JAXRSClientIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -34,6 +34,7 @@ import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; /* * @class.setup_props: webServerHost; @@ -414,6 +415,7 @@ public void getMatchedURIsTest2() throws Fault { * obtained from an injected UriInfo */ @Test + @Disabled public void getNormalizedUriTest() throws Fault { setProperty(Property.REQUEST, buildRequest(GET, URIInfoTest.DECODED)); invoke(); From bfa7ba6a889c228bd37b59725c209f118499d476 Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Tue, 13 Feb 2024 17:39:37 -0600 Subject: [PATCH 2/9] Removed changes from PR 863 since it requires a full release --- .../sse/ServerSentEventsResource.java | 5 +-- .../java/jakarta/ws/rs/sse/SseEventSink.java | 6 ++-- .../ee/sse/sseeventsink/CloseResource.java | 33 ++++++----------- .../ee/sse/sseeventsink/MBWCheckResource.java | 35 ++----------------- .../sseeventsink/StageCheckerResource.java | 7 ++-- .../sse/sseeventsource/MediaTypeResource.java | 17 ++------- .../ServiceUnavailableResource.java | 21 ++--------- 7 files changed, 22 insertions(+), 102 deletions(-) diff --git a/examples/src/main/java/jaxrs/examples/sse/ServerSentEventsResource.java b/examples/src/main/java/jaxrs/examples/sse/ServerSentEventsResource.java index dc19a685a..a4c08184a 100644 --- a/examples/src/main/java/jaxrs/examples/sse/ServerSentEventsResource.java +++ b/examples/src/main/java/jaxrs/examples/sse/ServerSentEventsResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020 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 Distribution License v. 1.0, which is available at @@ -98,10 +98,7 @@ public void startDomain(@PathParam("id") final String id, sseEventSink.close(); } catch (final InterruptedException e) { e.printStackTrace(); - } catch (IOException ioe) { - //handle I/O error } - }); } } diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java b/jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java index b24543530..6513a9250 100644 --- a/jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java +++ b/jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019 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,7 +16,6 @@ package jakarta.ws.rs.sse; -import java.io.IOException; import java.util.concurrent.CompletionStage; /** @@ -72,8 +71,7 @@ public interface SseEventSink extends AutoCloseable { *

* Subsequent calls have no effect and are ignored. Once the {@link SseEventSink} is closed, invoking any method other * than this one and {@link #isClosed()} would result in an {@link IllegalStateException} being thrown. - * @throws IOException if an I/O error occurs. */ @Override - void close() throws IOException; + void close(); } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/CloseResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/CloseResource.java index 1aa1ad570..916bfff3f 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/CloseResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/CloseResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -25,9 +25,6 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.sse.Sse; import jakarta.ws.rs.sse.SseEventSink; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; @Path("close") public class CloseResource { @@ -36,8 +33,6 @@ public class CloseResource { private static volatile boolean isClosed = false; - private static final Logger LOG = Logger.getLogger(CloseResource.class.getName()); - @GET @Path("reset") @Produces(MediaType.SERVER_SENT_EVENTS) @@ -46,8 +41,6 @@ public void reset(@Context SseEventSink sink, @Context Sse sse) { isClosed = false; try (SseEventSink s = sink) { s.send(sse.newEvent("RESET")); - } catch (IOException e) { - throw new RuntimeException(e); } } @@ -59,19 +52,15 @@ public void send(@Context SseEventSink sink, @Context Sse sse) { public void run() { SseEventSink s = sink; s.send(sse.newEvent(SSEMessage.MESSAGE)); - try { - s.close(); - isClosed = s.isClosed(); - if (!isClosed) - return; - s.close(); - isClosed = s.isClosed(); - if (!isClosed) - return; - s.close(); - } catch (IOException e) { - //ignore this exception and isClosed will be checked later. - } + s.close(); + isClosed = s.isClosed(); + if (!isClosed) + return; + s.close(); + isClosed = s.isClosed(); + if (!isClosed) + return; + s.close(); isClosed = s.isClosed(); if (!isClosed) return; @@ -99,8 +88,6 @@ public void check(@Context SseEventSink sink, @Context Sse sse) { return; } s.send(sse.newEvent("CHECK")); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java index 5eca3f8e7..4e9c597b4 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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,7 +16,6 @@ package ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.sseeventsink; -import ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.sseeventsource.ServiceUnavailableResource; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; @@ -24,8 +23,6 @@ import java.nio.file.Files; import java.nio.file.StandardOpenOption; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.namespace.QName; import ee.jakarta.tck.ws.rs.common.impl.SinglevaluedMap; @@ -49,7 +46,7 @@ @Path("mbw") public class MBWCheckResource { static final String MESSAGE = SSEMessage.MESSAGE; - private static final Logger LOG = Logger.getLogger(MBWCheckResource.class.getName()); + @GET @Path("boolean") @Produces(MediaType.SERVER_SENT_EVENTS) @@ -57,8 +54,6 @@ public void sendBoolean(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(true) .mediaType(MediaType.TEXT_PLAIN_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -69,8 +64,6 @@ public void sendByteArray(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(MESSAGE.getBytes()) .mediaType(MediaType.WILDCARD_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -81,8 +74,6 @@ public void sendChar(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(MESSAGE.charAt(0)) .mediaType(MediaType.TEXT_PLAIN_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -94,8 +85,6 @@ public void sendDatasource(@Context SseEventSink sink, @Context Sse sse) { s.send(sse.newEventBuilder() .data(new StringDataSource(MESSAGE, MediaType.TEXT_PLAIN_TYPE)) .mediaType(MediaType.WILDCARD_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -106,8 +95,6 @@ public void sendDouble(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(Double.MAX_VALUE) .mediaType(MediaType.TEXT_PLAIN_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -128,8 +115,6 @@ public void sendFile(@Context SseEventSink sink, @Context Sse sse) { s.send(sse.newEvent(e.getMessage())); throw new RuntimeException(e); // log to server log } - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -141,8 +126,6 @@ public void sendInputStream(@Context SseEventSink sink, @Context Sse sse) { s.send(sse.newEventBuilder() .data(new ByteArrayInputStream(MESSAGE.getBytes())) .mediaType(MediaType.WILDCARD_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -153,8 +136,6 @@ public void sendInt(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(Integer.MIN_VALUE) .mediaType(MediaType.TEXT_PLAIN_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -167,8 +148,6 @@ public void sendJAXBElement(@Context SseEventSink sink, @Context Sse sse) { String.class, MESSAGE); s.send(sse.newEventBuilder().data(element) .mediaType(MediaType.APPLICATION_XML_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -181,8 +160,6 @@ public void sendMultivaluedMap(@Context SseEventSink sink, @Context Sse sse) { map.add("name", MESSAGE); s.send(sse.newEventBuilder().data(map) .mediaType(MediaType.APPLICATION_FORM_URLENCODED_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -195,8 +172,6 @@ public void sendReader(@Context SseEventSink sink, @Context Sse sse) { .data(new InputStreamReader( new ByteArrayInputStream(MESSAGE.getBytes()))) .mediaType(MediaType.WILDCARD_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -209,8 +184,6 @@ public void sendStreamingOutput(@Context SseEventSink sink, StringStreamingOutput output = new StringStreamingOutput(MESSAGE); s.send(sse.newEventBuilder().data(output) .mediaType(MediaType.WILDCARD_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -221,8 +194,6 @@ public void sendString(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(MESSAGE) .mediaType(MediaType.WILDCARD_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -234,8 +205,6 @@ public void sendTransformSource(@Context SseEventSink sink, try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(new StringSource(MESSAGE)) .mediaType(MediaType.TEXT_XML_TYPE).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/StageCheckerResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/StageCheckerResource.java index a40a3c5a6..dd51b8a01 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/StageCheckerResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/StageCheckerResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -18,7 +18,6 @@ import static ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.SSEJAXRSClient.MESSAGE; -import java.io.IOException; import java.util.concurrent.CompletableFuture; import jakarta.ws.rs.GET; @@ -35,7 +34,7 @@ public class StageCheckerResource { @GET @Produces(MediaType.SERVER_SENT_EVENTS) - public void send(@Context SseEventSink sink, @Context Sse sse) throws IOException{ + public void send(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { CompletableFuture stage = s.send(sse.newEvent(MESSAGE)) .toCompletableFuture(); @@ -49,8 +48,6 @@ public void send(@Context SseEventSink sink, @Context Sse sse) throws IOExceptio } } s.send(sse.newEvent(DONE)); - } catch (IOException e) { - e.printStackTrace(); } } } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/MediaTypeResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/MediaTypeResource.java index 982a94b9d..f8b6ff1b4 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/MediaTypeResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/MediaTypeResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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,9 +16,6 @@ package ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.sseeventsource; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.namespace.QName; import ee.jakarta.tck.ws.rs.common.impl.JaxbKeyValueBean; @@ -34,11 +31,11 @@ import jakarta.ws.rs.sse.Sse; import jakarta.ws.rs.sse.SseEventSink; import jakarta.xml.bind.JAXBElement; -import java.util.logging.Logger; + @Path("media") public class MediaTypeResource { private static MediaType mediaType = MediaType.WILDCARD_TYPE; - private static final Logger LOG = Logger.getLogger(MediaTypeResource.class.getName()); + @POST @Path("set") public String setMediaType(String media) { @@ -54,8 +51,6 @@ public void sendData(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(SSEMessage.MESSAGE).mediaType(mediaType) .build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -67,8 +62,6 @@ public void sendJAXB(@Context SseEventSink sink, @Context Sse sse) { JAXBElement element = new JAXBElement(new QName("name"), String.class, SSEMessage.MESSAGE); s.send(sse.newEventBuilder().data(element).mediaType(mediaType).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -80,8 +73,6 @@ public void sendXML(@Context SseEventSink sink, @Context Sse sse) { JaxbKeyValueBean bean = new JaxbKeyValueBean(); bean.set("key", SSEMessage.MESSAGE); s.send(sse.newEventBuilder().data(bean).mediaType(mediaType).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -93,8 +84,6 @@ public void sendMap(@Context SseEventSink sink, @Context Sse sse) { SinglevaluedMap map = new SinglevaluedMap<>(); map.add("key", SSEMessage.MESSAGE); s.send(sse.newEventBuilder().data(map).mediaType(mediaType).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/ServiceUnavailableResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/ServiceUnavailableResource.java index 55aba3519..4b1cb8546 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/ServiceUnavailableResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/ServiceUnavailableResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -31,9 +31,6 @@ import jakarta.ws.rs.sse.OutboundSseEvent; import jakarta.ws.rs.sse.Sse; import jakarta.ws.rs.sse.SseEventSink; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; @Path("su") public class ServiceUnavailableResource { @@ -47,8 +44,6 @@ public class ServiceUnavailableResource { static final String MESSAGE = SSEMessage.MESSAGE; - private static final Logger LOG = Logger.getLogger(ServiceUnavailableResource.class.getName()); - @GET @Path("reset") public String reset() { @@ -110,8 +105,6 @@ public void sendMessage(@Context SseEventSink sink, @Context Sse sse) { } else { try (SseEventSink s = sink) { s.send(sse.newEvent(MESSAGE)); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } @@ -125,11 +118,7 @@ public void sseLost(@Context SseEventSink sink, @Context Sse sse) { count++; if (isConnectionLost != 0) { isConnectionLost--; - try { - sink.close(); - } catch (IOException e) { - e.printStackTrace(); - } + sink.close(); /* * To cancel a stream from the server, respond with a non * "text/event-stream" Content-Type or return an HTTP status other than @@ -138,8 +127,6 @@ public void sseLost(@Context SseEventSink sink, @Context Sse sse) { } else { try (SseEventSink s = sink) { s.send(sse.newEvent(MESSAGE)); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } @@ -151,8 +138,6 @@ public void sseLost(@Context SseEventSink sink, @Context Sse sse) { public void sendRetry(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(MESSAGE).reconnectDelay(3000L).build()); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -163,8 +148,6 @@ public void sendUserRetry(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send( (OutboundSseEvent) new OutboundSSEEventImpl(MESSAGE).setDelay(20000)); - } catch (IOException e) { - LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } From 4a45c411d4b1fa2f138444ddece0a06e7fee25c7 Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Tue, 13 Feb 2024 17:47:38 -0600 Subject: [PATCH 3/9] Missed change from PR 1173 --- .../ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java index 2a6e1dd92..0df09ad51 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -46,6 +46,7 @@ import org.jboss.shrinkwrap.api.spec.WebArchive; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.TestInfo; @@ -143,6 +144,7 @@ public void cleanup() throws Fault { * @test_Strategy: */ @Test + @Disabled public void sseBroadcastTest() throws Fault { int MSG_MAX = 7; int wait = 25; From 1638122fd75e05985c7ec7f7d9c70f63b0408adf Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Thu, 15 Feb 2024 16:12:28 -0600 Subject: [PATCH 4/9] Remove excludes from issue 1199 --- jaxrs-tck-docs/TCK-Exclude-List.txt | 4 ++-- .../rs/ee/rs/container/responsecontext/JAXRSClientIT.java | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/jaxrs-tck-docs/TCK-Exclude-List.txt b/jaxrs-tck-docs/TCK-Exclude-List.txt index 3d77d18f3..db5d32412 100644 --- a/jaxrs-tck-docs/TCK-Exclude-List.txt +++ b/jaxrs-tck-docs/TCK-Exclude-List.txt @@ -156,8 +156,8 @@ ee/jakarta/tck/ws/rs/jaxrs21/ee/client/rxinvoker/JAXRSClientIT.java#traceWithRes ee/jakarta/tck/ws/rs/jaxrs21/ee/client/rxinvoker/JAXRSClientIT.java#traceWithGenericTypeStringTest ee/jakarta/tck/ws/rs/jaxrs21/ee/client/rxinvoker/JAXRSClientIT.java#traceWithGenericTypeResponseTest -https://github.com/jakartaee/rest/issues/1138 +# https://github.com/jakartaee/rest/issues/1138 ee/jakarta/tck/ws/rs/ee/rs/core/uriinfo/JAXRSClientIT#getNormalizedUriTest -https://github.com/jakartaee/rest/issues/1163 +# https://github.com/jakartaee/rest/issues/1163 ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT#setEntityStreamTest \ No newline at end of file diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java index e2dfd3706..c40db3fbc 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020 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 @@ -53,7 +53,7 @@ import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Disabled; + /* * @class.setup_props: webServerHost; * webServerPort; @@ -1103,7 +1103,6 @@ public void setEntityTest() throws Fault { * Throws IOException. */ @Test - @Disabled public void setEntityStreamTest() throws Fault { setProperty(Property.SEARCH_STRING, ResponseFilter.ENTITY); setProperty(Property.SEARCH_STRING, "OK"); @@ -1122,7 +1121,6 @@ public void setEntityStreamTest() throws Fault { * Throws IOException. */ @Test - @Disabled public void setStatusTest() throws Fault { for (Response.Status status : Response.Status.values()) { String content = String.valueOf(status.getStatusCode()); @@ -1144,7 +1142,6 @@ public void setStatusTest() throws Fault { * Throws IOException. */ @Test - @Disabled public void setStatusInfoTest() throws Fault { for (Response.Status status : Response.Status.values()) { String content = String.valueOf(status.getStatusCode()); From c692a89c9823df28477aa82914ba7946ec0a54f8 Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Mon, 19 Feb 2024 14:09:03 -0600 Subject: [PATCH 5/9] Pull in 4.0 changes from PR 1146 --- .../tck/ws/rs/common/JAXRSCommonClient.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/common/JAXRSCommonClient.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/common/JAXRSCommonClient.java index e50a1f2b0..d5c06b142 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/common/JAXRSCommonClient.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/common/JAXRSCommonClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -715,29 +715,29 @@ protected void clearProperty(Property key) { assertEquals(T first, T second, Object... message) { if (first == null && second == null) return; - assertFalse(first == null && second != null, message.toString()); - assertFalse(first != null && second == null, message.toString()); + assertFalse(first == null && second != null, objectsToString(message)); + assertFalse(first != null && second == null, objectsToString(message)); if (first instanceof Comparable) - assertTrue(((Comparable) first).compareTo(second) == 0, message.toString()); + assertTrue(((Comparable) first).compareTo(second) == 0, objectsToString(message)); else - assertTrue(first.equals(second), message.toString()); + assertTrue(first.equals(second), objectsToString(message)); } public static void // assertEqualsInt(int first, int second, Object... message) { - assertTrue(first == second, message.toString()); + assertTrue(first == second, objectsToString(message)); } public static void // assertEqualsLong(long first, long second, Object... message) { - assertTrue(first == second, message.toString()); + assertTrue(first == second, objectsToString(message)); } public static void // assertEqualsBool(boolean first, boolean second, Object... message) { - assertTrue(first == second, message.toString()); + assertTrue(first == second, objectsToString(message)); } /** @@ -751,7 +751,7 @@ protected void clearProperty(Property key) { */ public static void // assertNull(Object object, Object... message) { - assertTrue(object == null, message.toString()); + assertTrue(object == null, objectsToString(message)); } /** @@ -765,7 +765,7 @@ protected void clearProperty(Property key) { */ public static void // assertNotNull(Object object, Object... message) { - assertTrue(object != null, message.toString()); + assertTrue(object != null, objectsToString(message)); } /** @@ -795,7 +795,7 @@ public static void fault(Object... objects) throws Fault { */ public static void assertContains(String string, String substring, Object... message) { - assertTrue(string.contains(substring), message.toString()); + assertTrue(string.contains(substring), objectsToString(message)); } /** @@ -812,7 +812,7 @@ public static void assertContains(String string, String substring, */ public static void assertContainsIgnoreCase(String string, String substring, Object... message) { - assertTrue(string.toLowerCase().contains(substring.toLowerCase()), message.toString()); + assertTrue(string.toLowerCase().contains(substring.toLowerCase()), objectsToString(message)); } /** @@ -828,7 +828,7 @@ public static void assertContainsIgnoreCase(String string, String substring, */ public static void assertContains(T text, T subtext, Object... message) { - assertContains(text.toString(), subtext.toString(), message.toString()); + assertContains(text.toString(), subtext.toString(), objectsToString(message)); } /** @@ -845,7 +845,7 @@ public static void assertContains(T text, T subtext, Object... message) */ public static void assertContainsIgnoreCase(T text, T subtext, Object... message) { - assertContainsIgnoreCase(text.toString(), subtext.toString(), message.toString()); + assertContainsIgnoreCase(text.toString(), subtext.toString(), objectsToString(message)); } /** From 56bf06b01efe43d5db491f63924165ed9beaaf46 Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Mon, 19 Feb 2024 14:26:40 -0600 Subject: [PATCH 6/9] Add 4.0 change from PR 1164 --- .../rs/ee/rs/container/responsecontext/ResponseFilter.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ResponseFilter.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ResponseFilter.java index 0bf416f1b..7c7c3c929 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ResponseFilter.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ResponseFilter.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 @@ -317,6 +317,11 @@ public synchronized void write(byte[] b, int off, int len) write(b); } + @Override + public void close() throws IOException { + stream.close(); + } + public final byte[] intToByteArray(int value) { return new byte[] { (byte) (value & 0xff) }; } From fb0a5646ce15a43d5c8ed53eb8ba024fa841ccb9 Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Mon, 19 Feb 2024 15:10:47 -0600 Subject: [PATCH 7/9] pull in changes from 4.0 for PR's 1172 and 1182 --- .../ee/sse/ssebroadcaster/JAXRSClientIT.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java index 0df09ad51..677e89514 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java @@ -17,6 +17,7 @@ package ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.ssebroadcaster; import java.util.List; +import java.util.ArrayList; import java.io.InputStream; import java.io.IOException; @@ -46,7 +47,6 @@ import org.jboss.shrinkwrap.api.spec.WebArchive; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.TestInfo; @@ -144,7 +144,6 @@ public void cleanup() throws Fault { * @test_Strategy: */ @Test - @Disabled public void sseBroadcastTest() throws Fault { int MSG_MAX = 7; int wait = 25; @@ -190,17 +189,20 @@ public void sseBroadcastTest() throws Fault { } } - for (int i = 0; i != CLIENTS; i++) { - List events = clients[i].getEvents(); - assertEquals(events.size(), MSG_MAX + 1, - "Received unexpected number of events", events.size()); - assertTrue(events.get(0).contains("WELCOME"), - "Received unexpected message"+ events.get(0)); - for (int j = 0; j != MSG_MAX; j++) - assertEquals(events.get(j + 1), SSEMessage.MESSAGE + j, - "Received unexpected message", events.get(j + 1)); + List expectedEvents = new ArrayList(); + for (int j = 0; j != MSG_MAX; j++) { + expectedEvents.add(SSEMessage.MESSAGE + j); } + for (int i = 0; i != CLIENTS; i++) { + List events = clients[i].getEvents(); + assertEquals(events.size(), MSG_MAX + 1, + "Received unexpected number of events", events.size()); + assertTrue(events.get(0).contains("WELCOME"), + "Received unexpected message"+ events.get(0)); + assertTrue(events.containsAll(expectedEvents), "An expected message was not received"); + } + setProperty(Property.REQUEST, buildRequest(Request.GET, "broadcast/check")); invoke(); String response = getResponseBody(); From 28597614828d927b7e3cb8e8b01edb69a410e557 Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Mon, 19 Feb 2024 15:40:04 -0600 Subject: [PATCH 8/9] Fix exclude list --- jaxrs-tck-docs/TCK-Exclude-List.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/jaxrs-tck-docs/TCK-Exclude-List.txt b/jaxrs-tck-docs/TCK-Exclude-List.txt index db5d32412..33f0b777e 100644 --- a/jaxrs-tck-docs/TCK-Exclude-List.txt +++ b/jaxrs-tck-docs/TCK-Exclude-List.txt @@ -76,9 +76,6 @@ ee/jakarta/tck/ws/rs/jaxrs21/ee/client/executor/async/JAXRSClientIT.java#traceWi ee/jakarta/tck/ws/rs/jaxrs21/ee/client/executor/async/JAXRSClientIT.java#traceWithStringCallbackWhileServerWaitTest ee/jakarta/tck/ws/rs/jaxrs21/ee/client/executor/async/JAXRSClientIT.java#traceWithStringClassWhileServerWaitTest -# https://github.com/jakartaee/rest/issues/1162 -ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/ssebroadcaster/JAXRSClientIT.java#sseBroadcastTest - # # ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/JAXRSClientIT.java#connectionLostForDefault500msTest @@ -158,6 +155,3 @@ ee/jakarta/tck/ws/rs/jaxrs21/ee/client/rxinvoker/JAXRSClientIT.java#traceWithGen # https://github.com/jakartaee/rest/issues/1138 ee/jakarta/tck/ws/rs/ee/rs/core/uriinfo/JAXRSClientIT#getNormalizedUriTest - -# https://github.com/jakartaee/rest/issues/1163 -ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT#setEntityStreamTest \ No newline at end of file From adc363b9ac53509b9e49bba434e660c1b07b6aac Mon Sep 17 00:00:00 2001 From: jim-krueger Date: Tue, 20 Feb 2024 13:29:10 -0600 Subject: [PATCH 9/9] Add changes from 4.0 PR 863 --- .../sse/ServerSentEventsResource.java | 3 ++ .../java/jakarta/ws/rs/sse/SseEventSink.java | 4 ++- .../ee/sse/sseeventsink/CloseResource.java | 31 ++++++++++++----- .../ee/sse/sseeventsink/MBWCheckResource.java | 33 ++++++++++++++++++- .../sseeventsink/StageCheckerResource.java | 5 ++- .../sse/sseeventsource/MediaTypeResource.java | 15 +++++++-- .../ServiceUnavailableResource.java | 19 ++++++++++- 7 files changed, 95 insertions(+), 15 deletions(-) diff --git a/examples/src/main/java/jaxrs/examples/sse/ServerSentEventsResource.java b/examples/src/main/java/jaxrs/examples/sse/ServerSentEventsResource.java index a4c08184a..de70e8d9a 100644 --- a/examples/src/main/java/jaxrs/examples/sse/ServerSentEventsResource.java +++ b/examples/src/main/java/jaxrs/examples/sse/ServerSentEventsResource.java @@ -98,7 +98,10 @@ public void startDomain(@PathParam("id") final String id, sseEventSink.close(); } catch (final InterruptedException e) { e.printStackTrace(); + } catch (IOException ioe) { + //handle I/O error } + }); } } diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java b/jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java index 6513a9250..cb214e624 100644 --- a/jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java +++ b/jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java @@ -16,6 +16,7 @@ package jakarta.ws.rs.sse; +import java.io.IOException; import java.util.concurrent.CompletionStage; /** @@ -71,7 +72,8 @@ public interface SseEventSink extends AutoCloseable { *

* Subsequent calls have no effect and are ignored. Once the {@link SseEventSink} is closed, invoking any method other * than this one and {@link #isClosed()} would result in an {@link IllegalStateException} being thrown. + * @throws IOException if an I/O error occurs. */ @Override - void close(); + void close() throws IOException; } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/CloseResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/CloseResource.java index 916bfff3f..55e3f68b9 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/CloseResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/CloseResource.java @@ -25,6 +25,9 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.sse.Sse; import jakarta.ws.rs.sse.SseEventSink; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; @Path("close") public class CloseResource { @@ -33,6 +36,8 @@ public class CloseResource { private static volatile boolean isClosed = false; + private static final Logger LOG = Logger.getLogger(CloseResource.class.getName()); + @GET @Path("reset") @Produces(MediaType.SERVER_SENT_EVENTS) @@ -41,6 +46,8 @@ public void reset(@Context SseEventSink sink, @Context Sse sse) { isClosed = false; try (SseEventSink s = sink) { s.send(sse.newEvent("RESET")); + } catch (IOException e) { + throw new RuntimeException(e); } } @@ -52,15 +59,19 @@ public void send(@Context SseEventSink sink, @Context Sse sse) { public void run() { SseEventSink s = sink; s.send(sse.newEvent(SSEMessage.MESSAGE)); - s.close(); - isClosed = s.isClosed(); - if (!isClosed) - return; - s.close(); - isClosed = s.isClosed(); - if (!isClosed) - return; - s.close(); + try { + s.close(); + isClosed = s.isClosed(); + if (!isClosed) + return; + s.close(); + isClosed = s.isClosed(); + if (!isClosed) + return; + s.close(); + } catch (IOException e) { + //ignore this exception and isClosed will be checked later. + } isClosed = s.isClosed(); if (!isClosed) return; @@ -88,6 +99,8 @@ public void check(@Context SseEventSink sink, @Context Sse sse) { return; } s.send(sse.newEvent("CHECK")); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java index 4e9c597b4..b6461840e 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java @@ -16,6 +16,7 @@ package ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.sseeventsink; +import ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.sseeventsource.ServiceUnavailableResource; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; @@ -23,6 +24,8 @@ import java.nio.file.Files; import java.nio.file.StandardOpenOption; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.xml.namespace.QName; import ee.jakarta.tck.ws.rs.common.impl.SinglevaluedMap; @@ -46,7 +49,7 @@ @Path("mbw") public class MBWCheckResource { static final String MESSAGE = SSEMessage.MESSAGE; - + private static final Logger LOG = Logger.getLogger(MBWCheckResource.class.getName()); @GET @Path("boolean") @Produces(MediaType.SERVER_SENT_EVENTS) @@ -54,6 +57,8 @@ public void sendBoolean(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(true) .mediaType(MediaType.TEXT_PLAIN_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -64,6 +69,8 @@ public void sendByteArray(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(MESSAGE.getBytes()) .mediaType(MediaType.WILDCARD_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -74,6 +81,8 @@ public void sendChar(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(MESSAGE.charAt(0)) .mediaType(MediaType.TEXT_PLAIN_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -85,6 +94,8 @@ public void sendDatasource(@Context SseEventSink sink, @Context Sse sse) { s.send(sse.newEventBuilder() .data(new StringDataSource(MESSAGE, MediaType.TEXT_PLAIN_TYPE)) .mediaType(MediaType.WILDCARD_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -95,6 +106,8 @@ public void sendDouble(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(Double.MAX_VALUE) .mediaType(MediaType.TEXT_PLAIN_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -115,6 +128,8 @@ public void sendFile(@Context SseEventSink sink, @Context Sse sse) { s.send(sse.newEvent(e.getMessage())); throw new RuntimeException(e); // log to server log } + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -126,6 +141,8 @@ public void sendInputStream(@Context SseEventSink sink, @Context Sse sse) { s.send(sse.newEventBuilder() .data(new ByteArrayInputStream(MESSAGE.getBytes())) .mediaType(MediaType.WILDCARD_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -136,6 +153,8 @@ public void sendInt(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(Integer.MIN_VALUE) .mediaType(MediaType.TEXT_PLAIN_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -148,6 +167,8 @@ public void sendJAXBElement(@Context SseEventSink sink, @Context Sse sse) { String.class, MESSAGE); s.send(sse.newEventBuilder().data(element) .mediaType(MediaType.APPLICATION_XML_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -160,6 +181,8 @@ public void sendMultivaluedMap(@Context SseEventSink sink, @Context Sse sse) { map.add("name", MESSAGE); s.send(sse.newEventBuilder().data(map) .mediaType(MediaType.APPLICATION_FORM_URLENCODED_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -172,6 +195,8 @@ public void sendReader(@Context SseEventSink sink, @Context Sse sse) { .data(new InputStreamReader( new ByteArrayInputStream(MESSAGE.getBytes()))) .mediaType(MediaType.WILDCARD_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -184,6 +209,8 @@ public void sendStreamingOutput(@Context SseEventSink sink, StringStreamingOutput output = new StringStreamingOutput(MESSAGE); s.send(sse.newEventBuilder().data(output) .mediaType(MediaType.WILDCARD_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -194,6 +221,8 @@ public void sendString(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(MESSAGE) .mediaType(MediaType.WILDCARD_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -205,6 +234,8 @@ public void sendTransformSource(@Context SseEventSink sink, try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(new StringSource(MESSAGE)) .mediaType(MediaType.TEXT_XML_TYPE).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/StageCheckerResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/StageCheckerResource.java index dd51b8a01..3753fc39b 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/StageCheckerResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/StageCheckerResource.java @@ -18,6 +18,7 @@ import static ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.SSEJAXRSClient.MESSAGE; +import java.io.IOException; import java.util.concurrent.CompletableFuture; import jakarta.ws.rs.GET; @@ -34,7 +35,7 @@ public class StageCheckerResource { @GET @Produces(MediaType.SERVER_SENT_EVENTS) - public void send(@Context SseEventSink sink, @Context Sse sse) { + public void send(@Context SseEventSink sink, @Context Sse sse) throws IOException{ try (SseEventSink s = sink) { CompletableFuture stage = s.send(sse.newEvent(MESSAGE)) .toCompletableFuture(); @@ -48,6 +49,8 @@ public void send(@Context SseEventSink sink, @Context Sse sse) { } } s.send(sse.newEvent(DONE)); + } catch (IOException e) { + e.printStackTrace(); } } } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/MediaTypeResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/MediaTypeResource.java index f8b6ff1b4..1db501027 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/MediaTypeResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/MediaTypeResource.java @@ -16,6 +16,9 @@ package ee.jakarta.tck.ws.rs.jaxrs21.ee.sse.sseeventsource; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.xml.namespace.QName; import ee.jakarta.tck.ws.rs.common.impl.JaxbKeyValueBean; @@ -31,11 +34,11 @@ import jakarta.ws.rs.sse.Sse; import jakarta.ws.rs.sse.SseEventSink; import jakarta.xml.bind.JAXBElement; - +import java.util.logging.Logger; @Path("media") public class MediaTypeResource { private static MediaType mediaType = MediaType.WILDCARD_TYPE; - + private static final Logger LOG = Logger.getLogger(MediaTypeResource.class.getName()); @POST @Path("set") public String setMediaType(String media) { @@ -51,6 +54,8 @@ public void sendData(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(SSEMessage.MESSAGE).mediaType(mediaType) .build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -62,6 +67,8 @@ public void sendJAXB(@Context SseEventSink sink, @Context Sse sse) { JAXBElement element = new JAXBElement(new QName("name"), String.class, SSEMessage.MESSAGE); s.send(sse.newEventBuilder().data(element).mediaType(mediaType).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -73,6 +80,8 @@ public void sendXML(@Context SseEventSink sink, @Context Sse sse) { JaxbKeyValueBean bean = new JaxbKeyValueBean(); bean.set("key", SSEMessage.MESSAGE); s.send(sse.newEventBuilder().data(bean).mediaType(mediaType).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -84,6 +93,8 @@ public void sendMap(@Context SseEventSink sink, @Context Sse sse) { SinglevaluedMap map = new SinglevaluedMap<>(); map.add("key", SSEMessage.MESSAGE); s.send(sse.newEventBuilder().data(map).mediaType(mediaType).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/ServiceUnavailableResource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/ServiceUnavailableResource.java index 4b1cb8546..cc03d2b32 100644 --- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/ServiceUnavailableResource.java +++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsource/ServiceUnavailableResource.java @@ -31,6 +31,9 @@ import jakarta.ws.rs.sse.OutboundSseEvent; import jakarta.ws.rs.sse.Sse; import jakarta.ws.rs.sse.SseEventSink; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; @Path("su") public class ServiceUnavailableResource { @@ -44,6 +47,8 @@ public class ServiceUnavailableResource { static final String MESSAGE = SSEMessage.MESSAGE; + private static final Logger LOG = Logger.getLogger(ServiceUnavailableResource.class.getName()); + @GET @Path("reset") public String reset() { @@ -105,6 +110,8 @@ public void sendMessage(@Context SseEventSink sink, @Context Sse sse) { } else { try (SseEventSink s = sink) { s.send(sse.newEvent(MESSAGE)); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } @@ -118,7 +125,11 @@ public void sseLost(@Context SseEventSink sink, @Context Sse sse) { count++; if (isConnectionLost != 0) { isConnectionLost--; - sink.close(); + try { + sink.close(); + } catch (IOException e) { + e.printStackTrace(); + } /* * To cancel a stream from the server, respond with a non * "text/event-stream" Content-Type or return an HTTP status other than @@ -127,6 +138,8 @@ public void sseLost(@Context SseEventSink sink, @Context Sse sse) { } else { try (SseEventSink s = sink) { s.send(sse.newEvent(MESSAGE)); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } } @@ -138,6 +151,8 @@ public void sseLost(@Context SseEventSink sink, @Context Sse sse) { public void sendRetry(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send(sse.newEventBuilder().data(MESSAGE).reconnectDelay(3000L).build()); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } @@ -148,6 +163,8 @@ public void sendUserRetry(@Context SseEventSink sink, @Context Sse sse) { try (SseEventSink s = sink) { s.send( (OutboundSseEvent) new OutboundSSEEventImpl(MESSAGE).setDelay(20000)); + } catch (IOException e) { + LOG.log(Level.WARNING, "Failed to close SseEventSink", e); } } }