[
https://issues.apache.org/jira/browse/CXF-7854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16634748#comment-16634748
]
ASF GitHub Bot commented on CXF-7854:
-------------------------------------
reta commented on a change in pull request #451: CXF-7854: Refactor RxJava2
Flowable and Observable Rx Invokers to not…
URL: https://github.com/apache/cxf/pull/451#discussion_r221783683
##########
File path:
rt/rs/extensions/rx2/src/main/java/org/apache/cxf/jaxrs/rx2/client/FlowableRxInvokerImpl.java
##########
@@ -147,34 +150,90 @@ public FlowableRxInvokerImpl(WebClient wc,
ExecutorService ex) {
@Override
public <T> Flowable<T> method(String name, Entity<?> entity, Class<T>
responseType) {
+
+ Flowable<T> flowable = Flowable.create(new FlowableOnSubscribe<T>() {
+ @Override
+ public void subscribe(FlowableEmitter<T> emitter) throws Exception
{
+ try {
+ T response = syncInvoker.method(name, entity,
responseType);
+ emitter.onNext(response);
+ emitter.onComplete();
+ } catch (Throwable e) {
+ emitter.onError(e);
+ }
+ }
+ }, BackpressureStrategy.DROP);
+
if (sc == null) {
- return Flowable.fromFuture(wc.async().method(name, entity,
responseType));
+ return flowable;
}
- return Flowable.fromFuture(wc.async().method(name, entity,
responseType), sc);
+ return flowable.subscribeOn(sc).observeOn(sc);
}
@Override
public <T> Flowable<T> method(String name, Entity<?> entity,
GenericType<T> responseType) {
+
+ Flowable<T> flowable = Flowable.create(new FlowableOnSubscribe<T>() {
+ @Override
+ public void subscribe(FlowableEmitter<T> emitter) throws Exception
{
Review comment:
We may generalize code a bit, too many repetition I think:
```
private <T> Flowable<T> create(Supplier<T> supplier) {
Flowable<T> flowable = Flowable.create(new FlowableOnSubscribe<T>() {
@Override
public void subscribe(FlowableEmitter<T> emitter) throws
Exception {
try {
T response = supplier.get();
if (!emitter.isCancelled()) {
emitter.onNext(response);
}
if (!emitter.isCancelled()) {
emitter.onComplete();
}
} catch (Throwable e) {
if (!emitter.isCancelled()) {
emitter.onError(e);
}
}
}
}, BackpressureStrategy.DROP);
if (sc == null) {
return flowable;
}
return flowable.subscribeOn(sc).observeOn(sc);
}
```
Then the implementation is just needs a supplier:
```
@Override
public <T> Flowable<T> method(String name, Entity<?> entity,
GenericType<T> responseType) {
return create(() -> syncInvoker.method(name, entity, responseType));
}
@Override
public <T> Flowable<T> method(String name, Class<T> responseType) {
return create(() -> syncInvoker.method(name, responseType));
}
@Override
public <T> Flowable<T> method(String name, GenericType<T> responseType) {
return create(() -> syncInvoker.method(name, responseType));
}
```
What do you think?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Refactor RxJava2 Flowable and Observable Rx Invokers to not use internal APIs.
> ------------------------------------------------------------------------------
>
> Key: CXF-7854
> URL: https://issues.apache.org/jira/browse/CXF-7854
> Project: CXF
> Issue Type: Bug
> Components: JAX-RS
> Affects Versions: 3.2.6
> Reporter: John Koehler
> Priority: Major
>
> Customers wanting to use reactive extensions may want to package their own
> version of RxJava2 with their application. The use of internal APIs may
> cause class loading problems.
> Caused by: java.lang.NoClassDefFoundError:
> org/apache/cxf/jaxrs/client/SyncInvokerImpl
> at
> org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider.getRxInvoker(FlowableRxInvokerProvider.java:37)
> at
> org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider.getRxInvoker(FlowableRxInvokerProvider.java:29)
> at org.apache.cxf.jaxrs.client.WebClient.rx(WebClient.java:1286)
> at
> org.apache.cxf.jaxrs.client.spec.InvocationBuilderImpl.rx(InvocationBuilderImpl.java:402)
>
> FlowableRxInvokerProvider uses org.apache.cxf.jaxrs.client.SyncInvokerImpl.
> FlowableRxInvokerImpl uses org.apache.cxf.jaxrs.client.WebClient.
> ObservableRxInvokerProvider uses org.apache.cxf.jaxrs.client.SyncInvokerImpl.
> ObservableRxInvokerImpl uses org.apache.cxf.jaxrs.client.WebClient.
> These classes need to be refactored.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)