use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class StageCheckerResource method send.
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public void send(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
CompletableFuture<?> stage = s.send(sse.newEvent(MESSAGE)).toCompletableFuture();
while (!stage.isDone()) {
try {
Thread.sleep(200L);
} catch (InterruptedException e) {
e.printStackTrace();
sse.newEvent(e.getMessage());
return;
}
}
s.send(sse.newEvent(DONE));
}
}
use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class CloseResource method reset.
@GET
@Path("reset")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void reset(@Context SseEventSink sink, @Context Sse sse) {
exception = false;
isClosed = false;
try (SseEventSink s = sink) {
s.send(sse.newEvent("RESET"));
}
}
use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class MBWCheckResource method sendMultivaluedMap.
@GET
@Path("multivaluedmap")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendMultivaluedMap(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
SinglevaluedMap<String, String> map = new SinglevaluedMap<>();
map.add("name", MESSAGE);
s.send(sse.newEventBuilder().data(map).mediaType(MediaType.APPLICATION_FORM_URLENCODED_TYPE).build());
}
}
use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class MBWCheckResource method sendFile.
@GET
@Path("file")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendFile(@Context SseEventSink sink, @Context Sse sse) {
File f;
try (SseEventSink s = sink) {
try {
f = File.createTempFile("tck", "tempfile");
Files.write(f.toPath(), MESSAGE.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
f.deleteOnExit();
s.send(sse.newEventBuilder().data(f).mediaType(MediaType.WILDCARD_TYPE).build());
} catch (IOException e) {
s.send(sse.newEvent(e.getMessage()));
// log to server log
throw new RuntimeException(e);
}
}
}
use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class MediaTypeResource method sendXML.
@GET
@Path("xml")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendXML(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
JaxbKeyValueBean bean = new JaxbKeyValueBean();
bean.set("key", SSEMessage.MESSAGE);
s.send(sse.newEventBuilder().data(bean).mediaType(mediaType).build());
}
}
Aggregations