mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Merge branch '7.0.x'
This commit is contained in:
+3
-1
@@ -99,7 +99,9 @@ public final class RestClientAdapter implements HttpExchangeAdapter {
|
||||
RestClient.RequestBodySpec spec = setUri(uriSpec, values);
|
||||
spec.headers(headers -> headers.putAll(values.getHeaders()));
|
||||
setCookieHeader(spec, values);
|
||||
spec.apiVersion(values.getApiVersion());
|
||||
if (values.getApiVersion() != null) {
|
||||
spec.apiVersion(values.getApiVersion());
|
||||
}
|
||||
spec.attributes(attributes -> attributes.putAll(values.getAttributes()));
|
||||
setBody(spec, values);
|
||||
return spec;
|
||||
|
||||
+20
@@ -200,6 +200,26 @@ class RestClientAdapterTests {
|
||||
assertThat(actualResponse).isEqualTo("Hello Spring 2!");
|
||||
}
|
||||
|
||||
@Test // gh-36514
|
||||
void greetingWithDefaultApiVersion() throws Exception {
|
||||
prepareResponse(builder ->
|
||||
builder.setHeader("Content-Type", "text/plain").body("Hello Spring 2!"));
|
||||
|
||||
RestClient restClient = RestClient.builder()
|
||||
.baseUrl(anotherServer.url("/").toString())
|
||||
.defaultApiVersion("1.0")
|
||||
.apiVersionInserter(ApiVersionInserter.useHeader("X-Version"))
|
||||
.build();
|
||||
|
||||
String actualResponse =
|
||||
HttpServiceProxyFactory.builderFor(RestClientAdapter.create(restClient)).build()
|
||||
.createClient(Service.class).getGreeting();
|
||||
|
||||
RecordedRequest request = anotherServer.takeRequest();
|
||||
assertThat(request.getHeaders().get("X-Version")).isEqualTo("1.0");
|
||||
assertThat(actualResponse).isEqualTo("Hello Spring 2!");
|
||||
}
|
||||
|
||||
@Test // see gh-36326
|
||||
void getBodyWithGenericReturnType() {
|
||||
prepareResponse(r -> r.setHeader("Content-Type", "application/json").body("{\"name\":\"Karl\"}"));
|
||||
|
||||
+4
-2
@@ -108,14 +108,16 @@ public abstract class ExchangeFunctions {
|
||||
String logPrefix = getLogPrefix(clientRequest, httpResponse);
|
||||
logResponse(httpResponse, logPrefix);
|
||||
return new DefaultClientResponse(
|
||||
httpResponse, this.strategies, logPrefix, httpMethod.name() + " " + url,
|
||||
httpResponse, this.strategies, logPrefix,
|
||||
WebClientUtils.getRequestDescription(httpMethod, url),
|
||||
() -> createRequest(clientRequest));
|
||||
});
|
||||
}
|
||||
|
||||
private void logRequest(ClientRequest request) {
|
||||
LogFormatUtils.traceDebug(logger, traceOn ->
|
||||
request.logPrefix() + "HTTP " + request.method() + " " + request.url() +
|
||||
request.logPrefix() + "HTTP " +
|
||||
WebClientUtils.getRequestDescription(request.method(), request.url()) +
|
||||
(traceOn ? ", headers=" + formatHeaders(request.headers()) : "")
|
||||
);
|
||||
}
|
||||
|
||||
+3
-1
@@ -111,7 +111,9 @@ public final class WebClientAdapter extends AbstractReactorHttpExchangeAdapter {
|
||||
WebClient.RequestBodySpec bodySpec = setUri(uriSpec, values);
|
||||
bodySpec.headers(headers -> headers.putAll(values.getHeaders()));
|
||||
bodySpec.cookies(cookies -> cookies.putAll(values.getCookies()));
|
||||
bodySpec.apiVersion(values.getApiVersion());
|
||||
if (values.getApiVersion() != null) {
|
||||
bodySpec.apiVersion(values.getApiVersion());
|
||||
}
|
||||
bodySpec.attributes(attributes -> attributes.putAll(values.getAttributes()));
|
||||
setBody(bodySpec, values);
|
||||
return bodySpec;
|
||||
|
||||
+20
@@ -48,6 +48,7 @@ import org.springframework.web.bind.annotation.RequestAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.client.ApiVersionInserter;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
@@ -129,6 +130,25 @@ class WebClientAdapterTests {
|
||||
assertThat(attributes).containsEntry("myAttribute", "myAttributeValue");
|
||||
}
|
||||
|
||||
@Test // gh-36514
|
||||
void greetingWithDefaultApiVersion() throws InterruptedException {
|
||||
prepareResponse(builder -> builder.setHeader("Content-Type", "text/plain").body("Hello Spring 2!"));
|
||||
|
||||
WebClient webClient = WebClient.builder()
|
||||
.baseUrl(this.server.url("/").toString())
|
||||
.defaultApiVersion("1.0")
|
||||
.apiVersionInserter(ApiVersionInserter.useHeader("X-Version"))
|
||||
.build();
|
||||
|
||||
StepVerifier.create(initService(webClient, Service.class).getGreeting())
|
||||
.expectNext("Hello Spring 2!")
|
||||
.expectComplete()
|
||||
.verify(Duration.ofSeconds(5));
|
||||
|
||||
RecordedRequest request = this.server.takeRequest();
|
||||
assertThat(request.getHeaders().get("X-Version")).isEqualTo("1.0");
|
||||
}
|
||||
|
||||
@Test // see gh-36326
|
||||
void getBodyWithGenericReturnType() {
|
||||
prepareResponse(r -> r.setHeader("Content-Type", "application/json").body("{\"name\":\"Karl\"}"));
|
||||
|
||||
Reference in New Issue
Block a user