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); } } }