Browse Source

HttpRequestValues.Processor exposes MethodParameter[]

Closes gh-35148
pull/35186/head
rstoyanchev 5 months ago
parent
commit
c23edae4db
  1. 4
      spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java
  2. 2
      spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java
  3. 8
      spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java
  4. 2
      spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java

4
spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java

@ -27,6 +27,7 @@ import java.util.function.Consumer; @@ -27,6 +27,7 @@ import java.util.function.Consumer;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@ -240,11 +241,12 @@ public class HttpRequestValues { @@ -240,11 +241,12 @@ public class HttpRequestValues {
* Invoked after argument resolvers have been called, and before the
* {@link HttpRequestValues} is built.
* @param method the {@code @HttpExchange} method
* @param parameters provides access to method parameter information
* @param arguments the raw argument values to the method
* @param builder the builder to add request values too; the builder
* also exposes method {@link Metadata} from the {@code HttpExchange} method.
*/
void process(Method method, @Nullable Object[] arguments, Builder builder);
void process(Method method, MethodParameter[] parameters, @Nullable Object[] arguments, Builder builder);
}

2
spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java

@ -133,7 +133,7 @@ final class HttpServiceMethod { @@ -133,7 +133,7 @@ final class HttpServiceMethod {
public @Nullable Object invoke(@Nullable Object[] arguments) {
HttpRequestValues.Builder requestValues = this.requestValuesInitializer.initializeRequestValuesBuilder();
applyArguments(requestValues, arguments);
this.requestValuesProcessor.process(this.method, arguments, requestValues);
this.requestValuesProcessor.process(this.method, this.parameters, arguments, requestValues);
return this.responseFunction.execute(requestValues.build());
}

8
spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java

@ -32,6 +32,7 @@ import org.springframework.aop.framework.ProxyFactory; @@ -32,6 +32,7 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.framework.ReflectiveMethodInvocation;
import org.springframework.core.KotlinDetector;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
@ -302,9 +303,12 @@ public final class HttpServiceProxyFactory { @@ -302,9 +303,12 @@ public final class HttpServiceProxyFactory {
implements HttpRequestValues.Processor {
@Override
public void process(Method method, @Nullable Object[] arguments, HttpRequestValues.Builder builder) {
public void process(
Method method, MethodParameter[] parameters, @Nullable Object[] arguments,
HttpRequestValues.Builder builder) {
for (HttpRequestValues.Processor processor : this.processors) {
processor.process(method, arguments, builder);
processor.process(method, parameters, arguments, builder);
}
}
}

2
spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java

@ -227,7 +227,7 @@ class HttpServiceMethodTests { @@ -227,7 +227,7 @@ class HttpServiceMethodTests {
HttpServiceProxyFactory.builder()
.exchangeAdapter(this.client)
.httpRequestValuesProcessor((m, a, builder) -> builder.addAttribute("foo", "a"))
.httpRequestValuesProcessor((m, p, a, builder) -> builder.addAttribute("foo", "a"))
.build()
.createClient(Service.class)
.execute();

Loading…
Cancel
Save