Support path parameter such as /user/{userId} #432
This commit is contained in:
@@ -160,6 +160,7 @@ public class AggregateFilter implements WebFilter {
|
||||
clientInput.put("headers", headers);
|
||||
clientInput.put("params", MapUtil.toHashMap(request.getQueryParams()));
|
||||
clientInput.put("contentType", request.getHeaders().getFirst(CommonConstants.HEADER_CONTENT_TYPE));
|
||||
clientInput.put("pathParams", com.fizzgate.util.ThreadContext.get("pathParams"));
|
||||
|
||||
Mono<AggregateResult> result = null;
|
||||
MediaType contentType = request.getHeaders().getContentType();
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.fizzgate.fizz.input.InputType;
|
||||
import com.fizzgate.util.Consts;
|
||||
import com.fizzgate.util.ReactorUtils;
|
||||
|
||||
import com.fizzgate.util.UrlTransformUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.ThreadContext;
|
||||
import org.noear.snack.ONode;
|
||||
@@ -50,6 +51,7 @@ import java.lang.ref.SoftReference;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.fizzgate.config.AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE;
|
||||
import static com.fizzgate.util.Consts.S.FORWARD_SLASH;
|
||||
@@ -388,6 +390,47 @@ public class ConfigLoader {
|
||||
ClientInputConfig cfg = (ClientInputConfig) input.getConfig();
|
||||
return new AggregateResource(pipeline, input);
|
||||
}
|
||||
} else {
|
||||
|
||||
String aggrMethodPath = null;
|
||||
try {
|
||||
for (Map.Entry<String, String> entry : aggregateResources.entrySet()) {
|
||||
aggrMethodPath = entry.getKey();
|
||||
boolean match = UrlTransformUtils.ANT_PATH_MATCHER.match(aggrMethodPath, key);
|
||||
if (match) {
|
||||
String configStr = aggregateResources.get(aggrMethodPath);
|
||||
Input input = createInput(configStr);
|
||||
Pipeline pipeline = createPipeline(configStr);
|
||||
if (pipeline != null && input != null) {
|
||||
Map<String, String> pathVariables = UrlTransformUtils.ANT_PATH_MATCHER.extractUriTemplateVariables(aggrMethodPath, key);
|
||||
Map<String, Object> map = Collections.emptyMap();
|
||||
if (!CollectionUtils.isEmpty(pathVariables)) {
|
||||
map = pathVariables.entrySet().stream().filter(
|
||||
e -> {
|
||||
return e.getKey().indexOf('$') == -1;
|
||||
}
|
||||
)
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
e -> {
|
||||
return (Object) e.getValue();
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
com.fizzgate.util.ThreadContext.set("pathParams", map);
|
||||
return new AggregateResource(pipeline, input);
|
||||
} else {
|
||||
LOGGER.warn("request {} match {}, input {} pipeline {}", key, aggrMethodPath, input, pipeline);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("request {} match {}, create input or pipeline error", key, aggrMethodPath, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -242,6 +242,7 @@ public class Pipeline {
|
||||
inputRequest.put("method", clientInput.get("method"));
|
||||
inputRequest.put("headers", clientInput.get("headers"));
|
||||
inputRequest.put("params", clientInput.get("params"));
|
||||
inputRequest.put("pathParams", clientInput.get("pathParams"));
|
||||
stepContext.addFilePartMap((Map<String, FilePart>) clientInput.get("filePartMap"));
|
||||
|
||||
if (CONTENT_TYPE_XML.equals(config.getContentType()) || (StringUtils.isEmpty(config.getContentType())
|
||||
|
||||
Reference in New Issue
Block a user