Java Code Examples for javax.ws.rs.sse.OutboundSseEvent#Builder
The following examples show how to use
javax.ws.rs.sse.OutboundSseEvent#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerSentEventResource.java From quarkus with Apache License 2.0 | 8 votes |
@GET @Path("/stream-xml") @SseElementType(MediaType.TEXT_XML) @Produces(MediaType.SERVER_SENT_EVENTS) public void sendXmlData(@Context SseEventSink sink) { // send a stream of few events try { for (int i = 0; i < 3; i++) { final OutboundSseEvent.Builder builder = this.sse.newEventBuilder(); builder.id(String.valueOf(i)).mediaType(MediaType.TEXT_XML_TYPE) .data("<settings><foo bar=\"" + i + "\"/></settings>") .name("stream of XML data"); sink.send(builder.build()); } } finally { sink.close(); } }
Example 2
Source File: TestResourceForConstructorProperties.java From quarkus with Apache License 2.0 | 6 votes |
@GET @Path("/sse") @SseElementType(MediaType.APPLICATION_JSON) @Produces(MediaType.SERVER_SENT_EVENTS) public void serverSentEvents(@Context SseEventSink sink) { VanillaJavaImmutableData data = new VanillaJavaImmutableData("sse", "ssevalue"); try { OutboundSseEvent.Builder builder = sse.newEventBuilder(); builder.id(String.valueOf(1)) .mediaType(MediaType.APPLICATION_JSON_TYPE) .data(data) .name("stream of json data"); sink.send(builder.build()); } finally { sink.close(); } }
Example 3
Source File: ServerSentEventResource.java From quarkus with Apache License 2.0 | 6 votes |
@GET @Path("/stream") @Produces(MediaType.SERVER_SENT_EVENTS) public void sendData(@Context SseEventSink sink) { // send a stream of few events try { for (int i = 0; i < 3; i++) { final OutboundSseEvent.Builder builder = this.sse.newEventBuilder(); builder.id(String.valueOf(i)).mediaType(MediaType.TEXT_PLAIN_TYPE) .data(Integer.class, i) .name("stream of numbers"); sink.send(builder.build()); } } finally { sink.close(); } }
Example 4
Source File: ServerSentEventResource.java From quarkus with Apache License 2.0 | 6 votes |
@GET @Path("/stream-html") @Produces(MediaType.SERVER_SENT_EVENTS) @SseElementType("text/html") public void sendHtmlData(@Context SseEventSink sink) { // send a stream of few events try { for (int i = 0; i < 3; i++) { final OutboundSseEvent.Builder builder = this.sse.newEventBuilder(); builder.id(String.valueOf(i)).mediaType(MediaType.TEXT_HTML_TYPE) .data("<html><body>" + i + "</body></html>") .name("stream of pages"); sink.send(builder.build()); } } finally { sink.close(); } }
Example 5
Source File: SseUtil.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
/** * Creates a new {@link OutboundSseEvent} object containing an {@link EventDTO} created for the given Eclipse * SmartHome {@link Event}. * * @param eventBuilder the builder that should be used * @param event the event data transfer object * @return a new OutboundEvent */ public static OutboundSseEvent buildEvent(OutboundSseEvent.Builder eventBuilder, EventDTO event) { final OutboundSseEvent sseEvent = eventBuilder.name("message") // .mediaType(MediaType.APPLICATION_JSON_TYPE) // .data(event) // .build(); return sseEvent; }
Example 6
Source File: StatsRestServiceImpl.java From cxf with Apache License 2.0 | 5 votes |
private static OutboundSseEvent createStatsEvent(final OutboundSseEvent.Builder builder, final long eventId) { return builder .id("" + eventId) .data(Stats.class, new Stats(new Date().getTime(), RANDOM.nextInt(100))) .mediaType(MediaType.APPLICATION_JSON_TYPE) .build(); }
Example 7
Source File: StatsRestServiceImpl.java From cxf with Apache License 2.0 | 5 votes |
private static OutboundSseEvent createStatsEvent(final OutboundSseEvent.Builder builder, final int eventId) { return builder .id("" + eventId) .mediaType(MediaType.APPLICATION_JSON_TYPE) .data(Stats.class, new Stats(new Date().getTime(), RANDOM.nextInt(100))) .build(); }
Example 8
Source File: StatsRestServiceImpl.java From cxf with Apache License 2.0 | 5 votes |
private static OutboundSseEvent createStatsEvent(final OutboundSseEvent.Builder builder, final int eventId) { return builder .id("" + eventId) .data(Stats.class, new Stats(new Date().getTime(), RANDOM.nextInt(100))) .mediaType(MediaType.APPLICATION_JSON_TYPE) .build(); }
Example 9
Source File: StatsRestServiceImpl.java From cxf with Apache License 2.0 | 5 votes |
private static OutboundSseEvent createStatsEvent(final OutboundSseEvent.Builder builder, final int eventId) { return builder .id("" + eventId) .data(Stats.class, new Stats(new Date().getTime(), RANDOM.nextInt(100))) .mediaType(MediaType.APPLICATION_JSON_TYPE) .build(); }
Example 10
Source File: StatsRestServiceImpl.java From cxf with Apache License 2.0 | 5 votes |
private static OutboundSseEvent createStatsEvent(final OutboundSseEvent.Builder builder, final int eventId) { return builder .id("" + eventId) .data(Stats.class, new Stats(new Date().getTime(), RANDOM.nextInt(100))) .mediaType(MediaType.APPLICATION_JSON_TYPE) .build(); }
Example 11
Source File: BookStoreClientCloseable.java From cxf with Apache License 2.0 | 5 votes |
protected static OutboundSseEvent createEvent(final OutboundSseEvent.Builder builder, final int eventId) { return builder .id(Integer.toString(eventId)) .data(Book.class, new Book("New Book #" + eventId, eventId)) .mediaType(MediaType.APPLICATION_JSON_TYPE) .build(); }
Example 12
Source File: BookStoreClientCloseable.java From cxf with Apache License 2.0 | 5 votes |
protected static OutboundSseEvent createRawEvent(final OutboundSseEvent.Builder builder, final int eventId) { return builder .id(Integer.toString(eventId)) .data("New Book #" + eventId) .mediaType(MediaType.TEXT_PLAIN_TYPE) .build(); }
Example 13
Source File: OutboundSseEventImplTest.java From cxf with Apache License 2.0 | 5 votes |
/** * A user should not need to specify the type of data being sent in an outbound * event. In that case the OutboundSseEvent should use the data object's type. Other * types may be specified, but the default (if not specified by the user) should be * the return value from the object's <code>getClass()</code> method. */ @Test public void testDefaultClass() { Sse sse = new SseImpl(); // test newEvent(string) OutboundSseEvent event = sse.newEvent("myData"); assertNull(event.getName()); assertEquals("myData", event.getData()); assertEquals(String.class, event.getType()); // test newEvent(name, data) event = sse.newEvent("myName", "myData2"); assertEquals("myName", event.getName()); assertEquals("myData2", event.getData()); assertEquals(String.class, event.getType()); // test newEventBuilder()...build() event = sse.newEventBuilder().comment("myComment").data("myData3").build(); assertEquals("myComment", event.getComment()); assertEquals("myData3", event.getData()); assertEquals(String.class, event.getType()); // test that object's class is re-enabled when calling different signatures of the data method OutboundSseEvent.Builder builder = sse.newEventBuilder(); builder.data(TestData.class, new TestDataImpl("1", "2")); event = builder.build(); assertEquals(TestData.class, event.getType()); builder.data("myString"); event = builder.build(); assertEquals(String.class, event.getType()); // same thing, but don't build in between calls to data event = sse.newEventBuilder().data(TestDataImpl.class, new TestDataImpl("3")).data("anotherString").build(); assertEquals(String.class, event.getType()); assertEquals("anotherString", event.getData()); }
Example 14
Source File: OutboundSseEventImplTest.java From cxf with Apache License 2.0 | 5 votes |
/** * Test that event built by the builder contains all of the data passed in * to it. */ @Test public void testBuilderAPIs() { SseImpl sse = new SseImpl(); OutboundSseEvent.Builder builder = sse.newEventBuilder(); builder.comment("myComment"); builder.data(new TestDataImpl("dataNoSpecifiedType")); builder.id("id"); builder.mediaType(MediaType.APPLICATION_JSON_TYPE); builder.name("name"); builder.reconnectDelay(5000); OutboundSseEvent event = builder.build(); assertEquals("myComment", event.getComment()); assertEquals(TestDataImpl.class, event.getType()); assertTrue(event.getData() instanceof TestDataImpl); assertEquals("dataNoSpecifiedType", ((TestDataImpl)event.getData()).getData().get(0)); assertEquals("id", event.getId()); assertEquals(MediaType.APPLICATION_JSON_TYPE, event.getMediaType()); assertEquals("name", event.getName()); assertEquals(5000, event.getReconnectDelay()); // now reuse the builder to build a new event builder.comment("myComment2"); builder.data(TestData.class, new TestDataImpl("data1", "data2")); builder.id("id2"); builder.mediaType(MediaType.TEXT_PLAIN_TYPE); builder.name("name2"); builder.reconnectDelay(9000); event = builder.build(); assertEquals("myComment2", event.getComment()); assertEquals(new TestDataImpl("data1", "data2"), event.getData()); assertEquals(TestData.class, event.getType()); assertEquals("id2", event.getId()); assertEquals(MediaType.TEXT_PLAIN_TYPE, event.getMediaType()); assertEquals("name2", event.getName()); assertEquals(9000, event.getReconnectDelay()); }
Example 15
Source File: SseEndpoint.java From hammock with Apache License 2.0 | 5 votes |
@GET @Path("/{uuid}") @Produces(SERVER_SENT_EVENTS) public void doSseCall(@PathParam("uuid") String uuid, @Context SseEventSink sink, @Context Sse sse) { final OutboundSseEvent.Builder builder = sse.newEventBuilder(); OutboundSseEvent event = builder.id(uuid) .data(SseModel.class, new SseModel("some model "+uuid)) .build(); sink.send(event); sink.close(); }
Example 16
Source File: SseEventHandler.java From hammock with Apache License 2.0 | 4 votes |
private static OutboundSseEvent createEvent(final OutboundSseEvent.Builder builder, final String id, final String body) { return builder.id(id).data(body).mediaType(MediaType.APPLICATION_JSON_TYPE).build(); }