You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/04/29 20:34:16 UTC
cxf git commit: [CXF-6833] Observable MBR
Repository: cxf
Updated Branches:
refs/heads/master 2fb1ccf60 -> 699f4c03d
[CXF-6833] Observable MBR
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/699f4c03
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/699f4c03
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/699f4c03
Branch: refs/heads/master
Commit: 699f4c03de1acb1cf9eb95ad2db792dba5a56ead
Parents: 2fb1ccf
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Fri Apr 29 19:33:58 2016 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Fri Apr 29 19:33:58 2016 +0100
----------------------------------------------------------------------
.../jaxrs/reactive/JAXRSReactiveTest.java | 15 +++++
.../jaxrs/reactive/ObservableReader.java | 61 ++++++++++++++++++++
.../jaxrs/reactive/ObservableWriter.java | 3 +-
3 files changed, 78 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/699f4c03/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 808c722..4a0e708 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
@@ -21,6 +21,8 @@ package org.apache.cxf.systest.jaxrs.reactive;
import java.util.concurrent.Future;
+import javax.ws.rs.core.GenericType;
+
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -28,6 +30,7 @@ import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.junit.BeforeClass;
import org.junit.Test;
+import edu.emory.mathcs.backport.java.util.Collections;
import rx.Observable;
public class JAXRSReactiveTest extends AbstractBusClientServerTestBase {
@@ -55,6 +58,18 @@ public class JAXRSReactiveTest extends AbstractBusClientServerTestBase {
}
@Test
+ public void testGetHelloWorldTextObservableSync() throws Exception {
+ String address = "http://localhost:" + PORT + "/reactive/text";
+ WebClient wc = WebClient.create(address, Collections.singletonList(
+ new ObservableReader<Object>()));
+ GenericType<Observable<String>> genericResponseType =
+ new GenericType<Observable<String>>() {
+ };
+ Observable<String> obs = wc.accept("text/plain").get(genericResponseType);
+ obs.subscribe(s -> assertResponse(s));
+ }
+
+ @Test
public void testGetHelloWorldAsyncObservable() throws Exception {
String address = "http://localhost:" + PORT + "/reactive/textAsync";
WebClient wc = WebClient.create(address);
http://git-wip-us.apache.org/repos/asf/cxf/blob/699f4c03/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableReader.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableReader.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableReader.java
new file mode 100644
index 0000000..fada83f
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableReader.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs.reactive;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Providers;
+
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
+
+import rx.Observable;
+
+public class ObservableReader<T> implements MessageBodyReader<Observable<T>> {
+
+ @Context
+ private Providers providers;
+
+ @Override
+ public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ return true;
+ }
+
+ @Override
+ public Observable<T> readFrom(Class<Observable<T>> cls, Type t, Annotation[] anns, MediaType mt,
+ MultivaluedMap<String, String> headers, InputStream is)
+ throws IOException, WebApplicationException {
+ @SuppressWarnings("unchecked")
+ Class<T> actualCls = (Class<T>)InjectionUtils.getActualType(t);
+ final MessageBodyReader<T> mbr =
+ (MessageBodyReader<T>)providers.getMessageBodyReader(actualCls, actualCls, anns, mt);
+ if (mbr == null) {
+ throw new ProcessingException("MBR is null");
+ }
+ return Observable.just(mbr.readFrom(actualCls, actualCls, anns, mt, headers, is));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/699f4c03/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableWriter.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableWriter.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableWriter.java
index 198f9b7..b6fc869 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableWriter.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/ObservableWriter.java
@@ -35,7 +35,7 @@ import org.apache.cxf.jaxrs.utils.ExceptionUtils;
import rx.Observable;
public class ObservableWriter<T> implements MessageBodyWriter<Observable<T>> {
-
+
@Context
private Providers providers;
@@ -80,4 +80,5 @@ public class ObservableWriter<T> implements MessageBodyWriter<Observable<T>> {
private static void throwError(Throwable cause) {
throw ExceptionUtils.toInternalServerErrorException(cause, null);
}
+
}