HTTP Service proxy sets body type

Closes gh-34793
This commit is contained in:
rstoyanchev
2025-04-25 14:31:37 +01:00
parent 190dabb8e1
commit c48ff357dc
8 changed files with 151 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,8 +98,8 @@ public final class WebClientAdapter extends AbstractReactorHttpExchangeAdapter {
return newRequest(requestValues).retrieve().toEntityFlux(bodyType);
}
@SuppressWarnings("ReactiveStreamsUnusedPublisher")
private WebClient.RequestBodySpec newRequest(HttpRequestValues values) {
@SuppressWarnings({"ReactiveStreamsUnusedPublisher", "unchecked"})
private <B> WebClient.RequestBodySpec newRequest(HttpRequestValues values) {
HttpMethod httpMethod = values.getHttpMethod();
Assert.notNull(httpMethod, "HttpMethod is required");
@@ -130,12 +130,18 @@ public final class WebClientAdapter extends AbstractReactorHttpExchangeAdapter {
bodySpec.attributes(attributes -> attributes.putAll(values.getAttributes()));
if (values.getBodyValue() != null) {
bodySpec.bodyValue(values.getBodyValue());
if (values.getBodyValueType() != null) {
B body = (B) values.getBodyValue();
bodySpec.bodyValue(body, (ParameterizedTypeReference<B>) values.getBodyValueType());
}
else {
bodySpec.bodyValue(values.getBodyValue());
}
}
else if (values instanceof ReactiveHttpRequestValues reactiveRequestValues) {
Publisher<?> body = reactiveRequestValues.getBodyPublisher();
else if (values instanceof ReactiveHttpRequestValues rhrv) {
Publisher<?> body = rhrv.getBodyPublisher();
if (body != null) {
ParameterizedTypeReference<?> elementType = reactiveRequestValues.getBodyPublisherElementType();
ParameterizedTypeReference<?> elementType = rhrv.getBodyPublisherElementType();
Assert.notNull(elementType, "Publisher body element type is required");
bodySpec.body(body, elementType);
}