|
|
|
@ -20,9 +20,7 @@ import java.io.IOException; |
|
|
|
import java.io.UncheckedIOException; |
|
|
|
import java.io.UncheckedIOException; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
|
import java.time.Duration; |
|
|
|
import java.time.Duration; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
import java.util.concurrent.Executor; |
|
|
|
import java.util.concurrent.Executor; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf; |
|
|
|
import io.netty.buffer.ByteBuf; |
|
|
|
import io.netty.buffer.ByteBufAllocator; |
|
|
|
import io.netty.buffer.ByteBufAllocator; |
|
|
|
@ -30,6 +28,7 @@ import org.jspecify.annotations.Nullable; |
|
|
|
import org.reactivestreams.FlowAdapters; |
|
|
|
import org.reactivestreams.FlowAdapters; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
|
|
|
|
import reactor.core.scheduler.Schedulers; |
|
|
|
import reactor.netty.NettyOutbound; |
|
|
|
import reactor.netty.NettyOutbound; |
|
|
|
import reactor.netty.http.client.HttpClient; |
|
|
|
import reactor.netty.http.client.HttpClient; |
|
|
|
import reactor.netty.http.client.HttpClientRequest; |
|
|
|
import reactor.netty.http.client.HttpClientRequest; |
|
|
|
@ -44,6 +43,7 @@ import org.springframework.util.StreamUtils; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
|
|
|
|
* @author Brian Clozel |
|
|
|
* @since 6.1 |
|
|
|
* @since 6.1 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
final class ReactorClientHttpRequest extends AbstractStreamingClientHttpRequest { |
|
|
|
final class ReactorClientHttpRequest extends AbstractStreamingClientHttpRequest { |
|
|
|
@ -54,6 +54,8 @@ final class ReactorClientHttpRequest extends AbstractStreamingClientHttpRequest |
|
|
|
|
|
|
|
|
|
|
|
private final URI uri; |
|
|
|
private final URI uri; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Executor executor; |
|
|
|
|
|
|
|
|
|
|
|
private final @Nullable Duration exchangeTimeout; |
|
|
|
private final @Nullable Duration exchangeTimeout; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -65,19 +67,31 @@ final class ReactorClientHttpRequest extends AbstractStreamingClientHttpRequest |
|
|
|
* @since 6.2 |
|
|
|
* @since 6.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ReactorClientHttpRequest(HttpClient httpClient, HttpMethod method, URI uri) { |
|
|
|
public ReactorClientHttpRequest(HttpClient httpClient, HttpMethod method, URI uri) { |
|
|
|
this.httpClient = httpClient; |
|
|
|
this(httpClient, method, uri, null); |
|
|
|
this.method = method; |
|
|
|
} |
|
|
|
this.uri = uri; |
|
|
|
|
|
|
|
this.exchangeTimeout = null; |
|
|
|
/** |
|
|
|
|
|
|
|
* Create an instance. |
|
|
|
|
|
|
|
* <p>If no executor is provided, the request will use an {@link Schedulers#boundedElastic() elastic scheduler} |
|
|
|
|
|
|
|
* for performing blocking I/O operations. |
|
|
|
|
|
|
|
* @param httpClient the client to perform the request with |
|
|
|
|
|
|
|
* @param executor the executor to use |
|
|
|
|
|
|
|
* @param method the HTTP method |
|
|
|
|
|
|
|
* @param uri the URI for the request |
|
|
|
|
|
|
|
* @since 6.2.13 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public ReactorClientHttpRequest(HttpClient httpClient, HttpMethod method, URI uri, @Nullable Executor executor) { |
|
|
|
|
|
|
|
this(httpClient, method, uri, executor, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Package private constructor for use until exchangeTimeout is removed. |
|
|
|
* Package private constructor for use until exchangeTimeout is removed. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
ReactorClientHttpRequest(HttpClient httpClient, HttpMethod method, URI uri, @Nullable Duration exchangeTimeout) { |
|
|
|
ReactorClientHttpRequest(HttpClient httpClient, HttpMethod method, URI uri, @Nullable Executor executor, @Nullable Duration exchangeTimeout) { |
|
|
|
this.httpClient = httpClient; |
|
|
|
this.httpClient = httpClient; |
|
|
|
this.method = method; |
|
|
|
this.method = method; |
|
|
|
this.uri = uri; |
|
|
|
this.uri = uri; |
|
|
|
|
|
|
|
this.executor = (executor != null) ? executor : Schedulers.boundedElastic()::schedule; |
|
|
|
this.exchangeTimeout = exchangeTimeout; |
|
|
|
this.exchangeTimeout = exchangeTimeout; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -132,13 +146,10 @@ final class ReactorClientHttpRequest extends AbstractStreamingClientHttpRequest |
|
|
|
return Mono.empty(); |
|
|
|
return Mono.empty(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AtomicReference<@Nullable Executor> executorRef = new AtomicReference<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return outbound |
|
|
|
return outbound |
|
|
|
.withConnection(connection -> executorRef.set(connection.channel().eventLoop())) |
|
|
|
|
|
|
|
.send(FlowAdapters.toPublisher(new OutputStreamPublisher<>( |
|
|
|
.send(FlowAdapters.toPublisher(new OutputStreamPublisher<>( |
|
|
|
os -> body.writeTo(StreamUtils.nonClosing(os)), new ByteBufMapper(outbound), |
|
|
|
os -> body.writeTo(StreamUtils.nonClosing(os)), new ByteBufMapper(outbound), |
|
|
|
Objects.requireNonNull(executorRef.getAndSet(null)), null))); |
|
|
|
this.executor, null))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static IOException convertException(RuntimeException ex) { |
|
|
|
static IOException convertException(RuntimeException ex) { |
|
|
|
|