|
@@ -9,6 +9,7 @@ import java.util.Set;
|
|
|
import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.chelvc.framework.base.config.MultiserverMvcConfigurer;
|
|
|
import com.chelvc.framework.base.context.Session;
|
|
|
import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
import com.chelvc.framework.base.context.Using;
|
|
@@ -18,6 +19,7 @@ import com.chelvc.framework.common.model.Terminal;
|
|
|
import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
import com.chelvc.framework.common.util.StringUtils;
|
|
|
import com.chelvc.framework.feign.config.FeignProperties;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import feign.RequestInterceptor;
|
|
|
import feign.RequestTemplate;
|
|
|
import feign.Target;
|
|
@@ -41,15 +43,25 @@ public class FeignInvokeInterceptor implements RequestInterceptor {
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public FeignInvokeInterceptor(@NonNull ApplicationContext applicationContext) {
|
|
|
- Environment environment = applicationContext.getEnvironment();
|
|
|
RequestMappingHandlerMapping handlerMapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
|
|
|
Map<String, Predicate<Class<?>>> prefixes = handlerMapping.getPathPrefixes();
|
|
|
this.servers = ObjectUtils.isEmpty(prefixes) ? Collections.emptySet() : prefixes.keySet();
|
|
|
Object registry = ObjectUtils.getValue(handlerMapping, "mappingRegistry");
|
|
|
Map<?, ?> mappings = (Map<?, ?>) ObjectUtils.getValue(registry, "urlLookup");
|
|
|
this.mappings = ObjectUtils.isEmpty(mappings) ? Collections.emptyMap() : (Map<String, ?>) mappings;
|
|
|
+
|
|
|
+ // 初始化请求转发配置
|
|
|
+ Environment environment = applicationContext.getEnvironment();
|
|
|
FeignProperties properties = applicationContext.getBean(FeignProperties.class);
|
|
|
- this.forwards = ObjectUtils.ifEmpty(properties.getForwards(), forwards -> forwards.stream().map(forward -> {
|
|
|
+ List<FeignProperties.Forward> forwards = Lists.newArrayList(properties.getForwards());
|
|
|
+ if (applicationContext.containsBean(MultiserverMvcConfigurer.class.getName())
|
|
|
+ && forwards.stream().noneMatch(forward -> Objects.equals(forward.getSource(), "*"))) {
|
|
|
+ FeignProperties.Forward forward = new FeignProperties.Forward();
|
|
|
+ forward.setSource("*");
|
|
|
+ forward.setPrefixed(true);
|
|
|
+ forwards.add(forward);
|
|
|
+ }
|
|
|
+ this.forwards = forwards.isEmpty() ? Collections.emptyList() : forwards.stream().map(forward -> {
|
|
|
FeignProperties.Forward copy = new FeignProperties.Forward();
|
|
|
copy.setSource(forward.getSource());
|
|
|
copy.setTarget(forward.getTarget());
|
|
@@ -58,7 +70,7 @@ public class FeignInvokeInterceptor implements RequestInterceptor {
|
|
|
copy.setTarget(environment.resolvePlaceholders(copy.getTarget()));
|
|
|
}
|
|
|
return copy;
|
|
|
- }).collect(Collectors.toList()), Collections::emptyList);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
/**
|