Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhoon committed Jan 31, 2024
1 parent 725b0cc commit 6a8253c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
12 changes: 12 additions & 0 deletions spring/boot2-webflux-autoconfigure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,21 @@ task copyBoot3Sources(type: Copy) {
into "${project.ext.genSrcDir}/main/java"
}

task copySpring6Sources(type: Copy) {
from("${rootProject.projectDir}/spring/spring6/src/main/java") {
include '**/ArmeriaClientHttpRequest.java'
include '**/ArmeriaClientHttpResponse.java'
include '**/DataBufferFactoryWrapper.java'
}

into "${project.ext.genSrcDir}/main/java"
}


// Copy the main and test sources from ':spring:boot3-webflux-autoconfigure'.
task generateSources(type: Copy) {
dependsOn(tasks.copyBoot3Sources)
dependsOn(tasks.copySpring6Sources)
from("${"${rootProject.projectDir}/spring/boot3-webflux-autoconfigure"}/src") {
exclude '**/AbstractServerHttpResponseVersionSpecific.java'
exclude '**/AbstractServerHttpRequestVersionSpecific.java'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.web.service.invoker.AbstractReactorHttpExchangeAdapter;
import org.springframework.web.service.invoker.HttpRequestValues;
import org.springframework.web.service.invoker.ReactiveHttpRequestValues;
import org.springframework.web.service.invoker.ReactorHttpExchangeAdapter;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilderFactory;
import org.springframework.web.util.UriComponentsBuilder;
Expand All @@ -43,6 +44,7 @@

import com.linecorp.armeria.client.Clients;
import com.linecorp.armeria.client.WebClient;
import com.linecorp.armeria.common.HttpData;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.SplitHttpResponse;
import com.linecorp.armeria.spring.internal.client.ArmeriaClientHttpRequest;
Expand All @@ -52,13 +54,24 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
* A {@link ReactorHttpExchangeAdapter} implementation for the Armeria {@link WebClient}.
*/
public final class ArmeriaHttpExchangeAdapter extends AbstractReactorHttpExchangeAdapter {

/**
* Creates a new instance with the specified {@link WebClient}.
*/
public static ArmeriaHttpExchangeAdapter of(WebClient webClient) {
return of(webClient, ExchangeStrategies.withDefaults());
}

/**
* Creates a new instance with the specified {@link WebClient} and {@link ExchangeStrategies}.
*/
public static ArmeriaHttpExchangeAdapter of(WebClient webClient, ExchangeStrategies exchangeStrategies) {
requireNonNull(webClient, "webClient");
requireNonNull(exchangeStrategies, "exchangeStrategies");
return new ArmeriaHttpExchangeAdapter(webClient, exchangeStrategies);
}

Expand Down Expand Up @@ -127,8 +140,19 @@ public boolean supportsRequestAttributes() {
return false;
}

/**
* Sends the specified {@link HttpRequestValues} to the {@link WebClient} and returns the response.
*
* <p><h4>Implementation note</h4>
* In order to encode {@link HttpRequestValues#getBodyValue()} to {@link HttpData}, we
* need to convert the {@link HttpRequestValues} to {@link ClientRequest} first. The serialization process
* is delegated to the {@link ClientRequest}. After that, the request is written to
* {@link ArmeriaClientHttpRequest} to send the request via the {@link WebClient}.
*
* <p>The response handling has to be done in the reverse order. Armeria {@link HttpResponse} is converted into
* {@link ArmeriaClientHttpResponse} first and then converted into {@link ClientResponse}.
*/
private Mono<ClientResponse> execute(HttpRequestValues requestValues) {

final URI uri;
if (requestValues.getUri() != null) {
uri = requestValues.getUri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private Supplier<Mono<Void>> execute(Supplier<HttpRequest> supplier) {

@VisibleForTesting
@Nullable
HttpRequest request() {
public HttpRequest request() {
return request;
}

Expand Down

0 comments on commit 6a8253c

Please sign in to comment.