Merge branch '4.1.x'
This commit is contained in:
@@ -28,6 +28,8 @@ import org.springframework.cloud.gateway.server.mvc.invoke.OperationParameter;
|
||||
import org.springframework.cloud.gateway.server.mvc.invoke.OperationParameters;
|
||||
import org.springframework.cloud.gateway.server.mvc.invoke.reflect.DefaultOperationMethod;
|
||||
import org.springframework.cloud.gateway.server.mvc.invoke.reflect.OperationMethod;
|
||||
import org.springframework.core.annotation.MergedAnnotation;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -52,8 +54,9 @@ public class NormalizedOperationMethod implements OperationMethod {
|
||||
}
|
||||
|
||||
public boolean isConfigurable() {
|
||||
Configurable annotation = delegate.getMethod().getAnnotation(Configurable.class);
|
||||
return annotation != null && delegate.getParameters().getParameterCount() == 1;
|
||||
MergedAnnotation<Configurable> configurable = MergedAnnotations.from(delegate.getMethod())
|
||||
.get(Configurable.class);
|
||||
return configurable.isPresent() && delegate.getParameters().getParameterCount() == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,8 +75,10 @@ public class NormalizedOperationMethod implements OperationMethod {
|
||||
|
||||
private Map<String, Object> normalizeArgs(Map<String, Object> operationArgs) {
|
||||
if (hasGeneratedKey(operationArgs)) {
|
||||
Shortcut shortcut = getMethod().getAnnotation(Shortcut.class);
|
||||
if (shortcut != null) {
|
||||
MergedAnnotation<Shortcut> shortcutMergedAnnotation = MergedAnnotations.from(delegate.getMethod())
|
||||
.get(Shortcut.class);
|
||||
if (shortcutMergedAnnotation.isPresent()) {
|
||||
Shortcut shortcut = shortcutMergedAnnotation.synthesize();
|
||||
String[] fieldOrder = getFieldOrder(shortcut);
|
||||
return switch (shortcut.type()) {
|
||||
case DEFAULT -> {
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.springframework.cloud.gateway.server.mvc.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -233,6 +235,11 @@ public class RouterFunctionHolderFactory {
|
||||
if (handlerFilterFunction != null) {
|
||||
operationHandler.accept(handlerFilterFunction);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(LogMessage.format("Yaml Properties matched Operations name: %s, args: %s, params: %s",
|
||||
normalizedName, opMethod.getNormalizedArgs().toString(),
|
||||
Arrays.toString(opMethod.getParameters().stream().toArray())));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(String.format("Unable to find operation %s for %s with args %s",
|
||||
@@ -244,6 +251,7 @@ public class RouterFunctionHolderFactory {
|
||||
String operationName, Map<String, Object> operationArgs) {
|
||||
return operations.getOrDefault(operationName, Collections.emptyList())
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(OperationMethod::isConfigurable))
|
||||
.map(operationMethod -> new NormalizedOperationMethod(operationMethod, operationArgs))
|
||||
.filter(opeMethod -> matchOperation(opeMethod, operationArgs))
|
||||
.findFirst();
|
||||
@@ -272,7 +280,7 @@ public class RouterFunctionHolderFactory {
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
if (operationMethod.isConfigurable()) {
|
||||
OperationParameter operationParameter = operationMethod.getParameters().get(0);
|
||||
Object config = bindConfigurable(operationMethod, args, operationParameter);
|
||||
Object config = bindConfigurable(operationMethod, operationArgs, operationParameter);
|
||||
args.put(operationParameter.getName(), config);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -68,7 +68,7 @@ public abstract class CircuitBreakerFilterFunctions {
|
||||
return circuitBreaker(config);
|
||||
}
|
||||
|
||||
@Shortcut
|
||||
@Shortcut("id")
|
||||
@Configurable
|
||||
public static HandlerFilterFunction<ServerResponse, ServerResponse> circuitBreaker(CircuitBreakerConfig config) {
|
||||
Set<HttpStatusCode> failureStatuses = config.getStatusCodes()
|
||||
|
||||
@@ -48,6 +48,7 @@ public abstract class RetryFilterFunctions {
|
||||
private RetryFilterFunctions() {
|
||||
}
|
||||
|
||||
@Shortcut
|
||||
public static HandlerFilterFunction<ServerResponse, ServerResponse> retry(int retries) {
|
||||
return retry(config -> config.setRetries(retries));
|
||||
}
|
||||
@@ -58,7 +59,7 @@ public abstract class RetryFilterFunctions {
|
||||
return retry(config);
|
||||
}
|
||||
|
||||
@Shortcut
|
||||
@Shortcut({ "retries", "series", "methods" })
|
||||
@Configurable
|
||||
public static HandlerFilterFunction<ServerResponse, ServerResponse> retry(RetryConfig config) {
|
||||
RetryTemplateBuilder retryTemplateBuilder = RetryTemplate.builder();
|
||||
|
||||
@@ -34,6 +34,7 @@ spring.cloud.gateway.mvc:
|
||||
- HttpbinUriResolver=
|
||||
- TokenRelay
|
||||
- AddRequestHeader=X-Test,listRoute2
|
||||
- Retry=3,SERVER_ERROR
|
||||
- id: listRoute3
|
||||
uri: lb://httpbin
|
||||
predicates:
|
||||
|
||||
Reference in New Issue
Block a user