|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -24,6 +24,7 @@ import java.util.function.Function; |
|
|
|
import org.eclipse.jetty.client.api.Request; |
|
|
|
import org.eclipse.jetty.client.api.Request; |
|
|
|
import org.eclipse.jetty.reactive.client.ContentChunk; |
|
|
|
import org.eclipse.jetty.reactive.client.ContentChunk; |
|
|
|
import org.eclipse.jetty.reactive.client.ReactiveRequest; |
|
|
|
import org.eclipse.jetty.reactive.client.ReactiveRequest; |
|
|
|
|
|
|
|
import org.eclipse.jetty.reactive.client.internal.PublisherContentProvider; |
|
|
|
import org.eclipse.jetty.util.Callback; |
|
|
|
import org.eclipse.jetty.util.Callback; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import reactor.core.Exceptions; |
|
|
|
import reactor.core.Exceptions; |
|
|
|
@ -37,7 +38,6 @@ import org.springframework.core.io.buffer.PooledDataBuffer; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -53,9 +53,6 @@ class JettyClientHttpRequest extends AbstractClientHttpRequest { |
|
|
|
|
|
|
|
|
|
|
|
private final DataBufferFactory bufferFactory; |
|
|
|
private final DataBufferFactory bufferFactory; |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
private ReactiveRequest reactiveRequest; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JettyClientHttpRequest(Request jettyRequest, DataBufferFactory bufferFactory) { |
|
|
|
public JettyClientHttpRequest(Request jettyRequest, DataBufferFactory bufferFactory) { |
|
|
|
this.jettyRequest = jettyRequest; |
|
|
|
this.jettyRequest = jettyRequest; |
|
|
|
@ -87,20 +84,21 @@ class JettyClientHttpRequest extends AbstractClientHttpRequest { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { |
|
|
|
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) { |
|
|
|
Flux<ContentChunk> chunks = Flux.from(body).map(this::toContentChunk); |
|
|
|
ReactiveRequest.Content content = Flux.from(body) |
|
|
|
ReactiveRequest.Content content = ReactiveRequest.Content.fromPublisher(chunks, getContentType()); |
|
|
|
.map(this::toContentChunk) |
|
|
|
this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).content(content).build(); |
|
|
|
.as(chunks -> ReactiveRequest.Content.fromPublisher(chunks, getContentType())); |
|
|
|
|
|
|
|
this.jettyRequest.content(new PublisherContentProvider(content)); |
|
|
|
return doCommit(this::completes); |
|
|
|
return doCommit(this::completes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) { |
|
|
|
public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) { |
|
|
|
Flux<ContentChunk> chunks = Flux.from(body) |
|
|
|
ReactiveRequest.Content content = Flux.from(body) |
|
|
|
.flatMap(Function.identity()) |
|
|
|
.flatMap(Function.identity()) |
|
|
|
.doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release) |
|
|
|
.doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release) |
|
|
|
.map(this::toContentChunk); |
|
|
|
.map(this::toContentChunk) |
|
|
|
ReactiveRequest.Content content = ReactiveRequest.Content.fromPublisher(chunks, getContentType()); |
|
|
|
.as(chunks -> ReactiveRequest.Content.fromPublisher(chunks, getContentType())); |
|
|
|
this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).content(content).build(); |
|
|
|
this.jettyRequest.content(new PublisherContentProvider(content)); |
|
|
|
return doCommit(this::completes); |
|
|
|
return doCommit(this::completes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -145,11 +143,4 @@ class JettyClientHttpRequest extends AbstractClientHttpRequest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ReactiveRequest getReactiveRequest() { |
|
|
|
|
|
|
|
if (this.reactiveRequest == null) { |
|
|
|
|
|
|
|
this.reactiveRequest = ReactiveRequest.newBuilder(this.jettyRequest).build(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.reactiveRequest; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|