johnament commented on a change in pull request #331: [CXF-7535] Adding client & server support for Project Reactor URL: https://github.com/apache/cxf/pull/331#discussion_r148977058
########## File path: rt/rs/extensions/reactor/src/main/java/org/apache/cxf/jaxrs/reactor/client/FluxRxInvokerImpl.java ########## @@ -0,0 +1,178 @@ +/** + * 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.jaxrs.reactor.client; + +import org.apache.cxf.jaxrs.client.WebClient; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Scheduler; +import reactor.core.scheduler.Schedulers; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import static org.apache.cxf.jaxrs.reactor.client.ReactorUtils.toCompletableFuture; + +public class FluxRxInvokerImpl implements FluxRxInvoker { + private static final String TRACE = "TRACE"; + private final WebClient webClient; + private final Scheduler scheduler; + + FluxRxInvokerImpl(WebClient webClient, ExecutorService executorService) { + this.webClient = webClient; + this.scheduler = executorService == null ? null : Schedulers.fromExecutorService(executorService); + } + + @Override + public Flux get() { + return method(HttpMethod.GET); + } + + @Override + public <R> Flux<R> get(Class<R> responseType) { + return method(HttpMethod.GET, responseType); + } + + @Override + public <R> Flux<R> get(GenericType<R> genericType) { + return method(HttpMethod.GET, genericType); + } + + @Override + public Flux<Response> put(Entity<?> entity) { + return method(HttpMethod.PUT, entity); + } + + @Override + public <R> Flux<R> put(Entity<?> entity, Class<R> responseType) { + return method(HttpMethod.PUT, responseType); + } + + @Override + public <R> Flux<R> put(Entity<?> entity, GenericType<R> genericType) { + return method(HttpMethod.PUT, entity, genericType); + } + + @Override + public Flux<Response> post(Entity<?> entity) { + return method(HttpMethod.POST, entity); + } + + @Override + public <R> Flux<R> post(Entity<?> entity, Class<R> responseType) { + return method(HttpMethod.POST, entity, responseType); + } + + @Override + public <R> Flux<R> post(Entity<?> entity, GenericType<R> genericType) { + return method(HttpMethod.POST, entity, genericType); + } + + @Override + public Flux<Response> delete() { + return method(HttpMethod.DELETE); + } + + @Override + public <R> Flux<R> delete(Class<R> responseType) { + return method(HttpMethod.DELETE, responseType); + } + + @Override + public <R> Flux<R> delete(GenericType<R> genericType) { + return method(HttpMethod.DELETE, genericType); + } + + @Override + public Flux<Response> head() { + return method(HttpMethod.HEAD); + } + + @Override + public Flux<Response> options() { + return method(HttpMethod.OPTIONS); + } + + @Override + public <R> Flux<R> options(Class<R> responseType) { + return method(HttpMethod.OPTIONS, responseType); + } + + @Override + public <R> Flux<R> options(GenericType<R> genericType) { + return method(HttpMethod.OPTIONS, genericType); + } + + @Override + public Flux<Response> trace() { + return method(TRACE); + } + + @Override + public <R> Flux<R> trace(Class<R> responseType) { + return method(TRACE, responseType); + } + + @Override + public <R> Flux<R> trace(GenericType<R> genericType) { + return method(TRACE, genericType); + } + + @Override + public Flux<Response> method(String name) { + return method(name, Response.class); + } + + @Override + public <R> Flux<R> method(String name, Class<R> responseType) { + return flux(webClient.async().method(name, responseType)); + } + + @Override + public <R> Flux<R> method(String name, GenericType<R> genericType) { + return flux(webClient.async().method(name, genericType)); + } + + @Override + public Flux<Response> method(String name, Entity<?> entity) { + return method(name, entity, Response.class); + } + + @Override + public <R> Flux<R> method(String name, Entity<?> entity, Class<R> responseType) { + return flux(webClient.async().method(name, entity, responseType)); + } + + @Override + public <R> Flux<R> method(String name, Entity<?> entity, GenericType<R> genericType) { + return flux(webClient.async().method(name, entity, genericType)); + } + + private <R> Flux<R> flux(Future<R> future) { + Flux<R> flux = Flux.from(Mono.fromFuture(toCompletableFuture(future))); Review comment: Ok, the executor part is fixed. If there's an executor passed in we use that. However, there's an interesting conundrum. I'm not sure how `rx()` is meant to work this way. For a `Mono` object its pretty clear, I had to tweak the test to use a version of the json processor that didn't treat the result as an array. Which makes sense, its meant to be a single object. However, I need to figure out a way to check if the opening character when reading the result is a single or multiple result. Effectively I need the `MessageBodyReader` equivalent of `StreamingResponseProvider`. I'm kind of wondering how this works for the RxJava versions (but then again, there's no tests for this method, so I wonder if you guys ran into that issue already). ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services