Skip to content

Commit

Permalink
Removed changes from PR 863 since it requires a full release
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-krueger committed Feb 13, 2024
1 parent 4e712dc commit bfa7ba6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}

});
}
}
6 changes: 2 additions & 4 deletions jaxrs-api/src/main/java/jakarta/ws/rs/sse/SseEventSink.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,6 @@

package jakarta.ws.rs.sse;

import java.io.IOException;
import java.util.concurrent.CompletionStage;

/**
Expand Down Expand Up @@ -72,8 +71,7 @@ public interface SseEventSink extends AutoCloseable {
* <p>
* 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();
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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);
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,16 +16,13 @@

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;
import java.io.InputStreamReader;
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;
Expand All @@ -49,16 +46,14 @@
@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)
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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
}
}

Expand All @@ -67,8 +62,6 @@ public void sendJAXB(@Context SseEventSink sink, @Context Sse sse) {
JAXBElement<String> element = new JAXBElement<String>(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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -93,8 +84,6 @@ public void sendMap(@Context SseEventSink sink, @Context Sse sse) {
SinglevaluedMap<String, String> 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);
}
}
}
Loading

0 comments on commit bfa7ba6

Please sign in to comment.