use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class MBWCheckResource method sendJAXBElement.
@GET
@Path("jaxbelement")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendJAXBElement(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
JAXBElement<String> element = new JAXBElement<String>(new QName("name"), String.class, MESSAGE);
s.send(sse.newEventBuilder().data(element).mediaType(MediaType.APPLICATION_XML_TYPE).build());
}
}
use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class MBWCheckResource method sendStreamingOutput.
@GET
@Path("streamingoutput")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendStreamingOutput(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
StringStreamingOutput output = new StringStreamingOutput(MESSAGE);
s.send(sse.newEventBuilder().data(output).mediaType(MediaType.WILDCARD_TYPE).build());
}
}
use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class MediaTypeResource method sendMap.
@GET
@Path("map")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendMap(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
SinglevaluedMap<String, String> map = new SinglevaluedMap<>();
map.add("key", SSEMessage.MESSAGE);
s.send(sse.newEventBuilder().data(map).mediaType(mediaType).build());
}
}
use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class MediaTypeResource method sendJAXB.
@GET
@Path("jaxb")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendJAXB(@Context SseEventSink sink, @Context Sse sse) {
try (SseEventSink s = sink) {
JAXBElement<String> element = new JAXBElement<String>(new QName("name"), String.class, SSEMessage.MESSAGE);
s.send(sse.newEventBuilder().data(element).mediaType(mediaType).build());
}
}
use of jakarta.ws.rs.sse.SseEventSink in project jaxrs-api by eclipse-ee4j.
the class ServiceUnavailableResource method sseLost.
@GET
@Path("sselost")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sseLost(@Context SseEventSink sink, @Context Sse sse) {
synchronized (isServiceUnavailable) {
count++;
if (isConnectionLost != 0) {
isConnectionLost--;
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
* 200 OK and 503 Service Unavailable (e.g. 404 Not Found).
*/
} else {
try (SseEventSink s = sink) {
s.send(sse.newEvent(MESSAGE));
}
}
}
}
Aggregations