[CXF-6833] Adding a HelloWorld async server test
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4786e832 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4786e832 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4786e832 Branch: refs/heads/master-jaxrs-2.1 Commit: 4786e832573f1fcc07ed190ab21fdb2820348e4d Parents: 6c32442 Author: Sergey Beryozkin <[email protected]> Authored: Fri Apr 29 14:21:39 2016 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Fri Apr 29 14:21:39 2016 +0100 ---------------------------------------------------------------------- .../jaxrs/reactive/JAXRSReactiveTest.java | 7 ++++ .../systest/jaxrs/reactive/ReactiveService.java | 36 ++++++++++++++++++++ 2 files changed, 43 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/4786e832/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSReactiveTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSReactiveTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSReactiveTest.java index 0241fed..c92e8fa 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSReactiveTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSReactiveTest.java @@ -42,6 +42,13 @@ public class JAXRSReactiveTest extends AbstractBusClientServerTestBase { String text = wc.accept("text/plain").get(String.class); assertEquals("Hello, world!", text); } + @Test + public void testGetHelloWorldAsyncText() throws Exception { + String address = "http://localhost:" + PORT + "/reactive/textAsync"; + WebClient wc = WebClient.create(address); + String text = wc.accept("text/plain").get(String.class); + assertEquals("Hello, world!", text); + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/4786e832/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ReactiveService.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ReactiveService.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ReactiveService.java index 87ab35a..7127214 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ReactiveService.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ReactiveService.java @@ -23,8 +23,11 @@ package org.apache.cxf.systest.jaxrs.reactive; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; import rx.Observable; +import rx.Subscriber; @Path("/reactive") @@ -37,6 +40,39 @@ public class ReactiveService { return Observable.just("Hello, world!"); } + @GET + @Produces("text/plain") + @Path("textAsync") + public void getTextAsync(@Suspended final AsyncResponse ar) { + Observable.just("Hello, ").map(s -> s + "world!") + .subscribe(new AsyncResponseSubscriber(ar)); + + } + + private class AsyncResponseSubscriber extends Subscriber<String> { + + private StringBuilder sb = new StringBuilder(); + private AsyncResponse ar; + + AsyncResponseSubscriber(AsyncResponse ar) { + this.ar = ar; + } + @Override + public void onCompleted() { + ar.resume(sb.toString()); + } + + @Override + public void onError(Throwable arg0) { + // TODO Auto-generated method stub + } + + @Override + public void onNext(String s) { + sb.append(s); + } + + } }
