Package org.glassfish.jersey.media.sse

Examples of org.glassfish.jersey.media.sse.EventInput


    @Test
    public void testSSE() throws IOException, InterruptedException, DeploymentException, ExecutionException {
        final Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
        Response resp = client.target("http://localhost:8080/ssechannel").request().get();
        NewCookie session = resp.getCookies().get(JSESSIONID);
        final EventInput eventInput = resp.readEntity(EventInput.class);
        final SettableFuture<String> res = new SettableFuture<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (!eventInput.isClosed() && !res.isDone()) {
                    final InboundEvent inboundEvent = eventInput.read();
                    if (inboundEvent == null)
                        break;
                    res.set(inboundEvent.readData(String.class));
                }
            }
View Full Code Here


            final Future<List<String>> futureMessages =
                    executor.submit(new Callable<List<String>>() {

                        @Override
                        public List<String> call() throws Exception {
                            final EventInput eventInput = target(App.ROOT_PATH).register(SseFeature.class)
                                    .request().get(EventInput.class);

                            startLatch.countDown();

                            final List<String> messages = new ArrayList<String>(MAX_MESSAGES);
                            try {
                                for (int i = 0; i < MAX_MESSAGES; i++) {
                                    InboundEvent event = eventInput.read();
                                    messages.add(event.readData());
                                }
                            } finally {
                                if (eventInput != null) {
                                    eventInput.close();
                                }
                            }

                            return messages;
                        }
View Full Code Here

        r = target().path("test/closed-single").request().header("Connection", "close").get();
        assertTrue(r.readEntity(String.class).contains("closed"));

        //

        EventInput input;
        input = target().path("test/closed-single").request().header("Connection", "close").get(EventInput.class);
        assertEquals("closed", input.read().readData());
        assertEquals(null, input.read());
        assertTrue(input.isClosed());

        input = target().path("test/closed-empty").request().header("Connection", "close").get(EventInput.class);
        assertEquals(null, input.read());
        assertTrue(input.isClosed());
    }
View Full Code Here

         * Thus setting the "Connection: close" HTTP header on all requests.
         */
        Response r;
        r = target().path("test/charset").request().header("Connection", "close").get();
        assertTrue(r.getMediaType().getParameters().get("charset").equalsIgnoreCase("utf-8"));
        final EventInput eventInput = r.readEntity(EventInput.class);
        String eventData = eventInput.read().readData();
        assertEquals("charset", eventData);
        eventInput.close();
    }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.media.sse.EventInput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.