Repository: cxf Updated Branches: refs/heads/master 122d1f64f -> 584df3ae1
CXF-5855: Minor fixes in closing the SSE output Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/584df3ae Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/584df3ae Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/584df3ae Branch: refs/heads/master Commit: 584df3ae111595da1b44ccd9db9567c2172bbb2e Parents: 122d1f6 Author: reta <drr...@gmail.com> Authored: Tue Sep 20 20:26:57 2016 -0400 Committer: reta <drr...@gmail.com> Committed: Tue Sep 20 20:26:57 2016 -0400 ---------------------------------------------------------------------- .../jaxrs/sse/atmosphere/SseAtmosphereEventOutputImpl.java | 8 ++++++-- .../sse/atmosphere/AtmosphereSseServletDestination.java | 2 ++ .../org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/584df3ae/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/atmosphere/SseAtmosphereEventOutputImpl.java ---------------------------------------------------------------------- diff --git a/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/atmosphere/SseAtmosphereEventOutputImpl.java b/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/atmosphere/SseAtmosphereEventOutputImpl.java index 3896ec6..0a85d3f 100644 --- a/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/atmosphere/SseAtmosphereEventOutputImpl.java +++ b/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/atmosphere/SseAtmosphereEventOutputImpl.java @@ -34,6 +34,7 @@ import javax.ws.rs.sse.SseEventOutput; import org.apache.cxf.common.logging.LogUtils; import org.atmosphere.cpr.AtmosphereResource; +import org.atmosphere.cpr.AtmosphereResponse; import org.atmosphere.cpr.Broadcaster; public class SseAtmosphereEventOutputImpl implements SseEventOutput { @@ -69,10 +70,13 @@ public class SseAtmosphereEventOutputImpl implements SseEventOutput { resource.removeFromAllBroadcasters(); try { - if (!resource.getResponse().isCommitted()) { + final AtmosphereResponse response = resource.getResponse(); + if (!response.isCommitted()) { LOG.fine("Response is not committed, flushing buffer"); - resource.getResponse().flushBuffer(); + response.flushBuffer(); } + + response.closeStreamOrWriter(); } finally { resource.close(); broadcaster.destroy(); http://git-wip-us.apache.org/repos/asf/cxf/blob/584df3ae/rt/rs/sse/src/main/java/org/apache/cxf/transport/sse/atmosphere/AtmosphereSseServletDestination.java ---------------------------------------------------------------------- diff --git a/rt/rs/sse/src/main/java/org/apache/cxf/transport/sse/atmosphere/AtmosphereSseServletDestination.java b/rt/rs/sse/src/main/java/org/apache/cxf/transport/sse/atmosphere/AtmosphereSseServletDestination.java index 15e5c9f..37cfc5e 100644 --- a/rt/rs/sse/src/main/java/org/apache/cxf/transport/sse/atmosphere/AtmosphereSseServletDestination.java +++ b/rt/rs/sse/src/main/java/org/apache/cxf/transport/sse/atmosphere/AtmosphereSseServletDestination.java @@ -36,6 +36,7 @@ import org.apache.cxf.jaxrs.sse.atmosphere.SseAtmosphereInterceptor; import org.apache.cxf.service.model.EndpointInfo; import org.apache.cxf.transport.http.DestinationRegistry; import org.apache.cxf.transport.servlet.ServletDestination; +import org.atmosphere.cache.UUIDBroadcasterCache; import org.atmosphere.cpr.ApplicationConfig; import org.atmosphere.cpr.AtmosphereFramework; import org.atmosphere.cpr.AtmosphereRequestImpl; @@ -58,6 +59,7 @@ public class AtmosphereSseServletDestination extends ServletDestination { framework.addInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT, "true"); framework.addInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, "true"); framework.addInitParameter(ApplicationConfig.CLOSE_STREAM_ON_CANCEL, "true"); + framework.setBroadcasterCacheClassName(UUIDBroadcasterCache.class.getName()); framework.addAtmosphereHandler("/", new DestinationHandler()); framework.init(); http://git-wip-us.apache.org/repos/asf/cxf/blob/584df3ae/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java ---------------------------------------------------------------------- diff --git a/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java index 0cf3087..bf93da6 100644 --- a/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java +++ b/systests/rs-sse/src/test/java/org/apache/cxf/systest/jaxrs/sse/AbstractSseTest.java @@ -61,6 +61,8 @@ public abstract class AbstractSseTest extends AbstractBusClientServerTestBase { assertThat(response, containsString("id: 4")); assertThat(response, containsString("data: " + toJson("New Book #4", 4))); + + r.close(); } @Test @@ -82,6 +84,8 @@ public abstract class AbstractSseTest extends AbstractBusClientServerTestBase { assertThat(response, containsString("id: 152")); assertThat(response, containsString("data: " + toJson("New Book #154", 154))); + + r.close(); } @Test @@ -91,6 +95,8 @@ public abstract class AbstractSseTest extends AbstractBusClientServerTestBase { final Book[] books = r.readEntity(Book[].class); assertThat(Arrays.asList(books), hasItems(new Book("New Book #1", 1), new Book("New Book #2", 2))); + + r.close(); } @Test