This commit is contained in:
hongqiaowei
2022-07-26 15:16:08 +08:00
parent 13220d35b5
commit ebaee5b62b
14 changed files with 629 additions and 92 deletions

View File

@@ -83,6 +83,7 @@ public class AggregateFilter implements WebFilter {
String serviceId = WebUtils.getBackendService(exchange);
if (serviceId == null) {
return chain.filter(exchange);
} else if (WebUtils.ignorePlugin(exchange) && WebUtils.getRoute(exchange).type == ApiConfig.Type.SERVICE_AGGREGATE) {
} else {
byte act = WebUtils.getApiConfigType(exchange);
if (act == ApiConfig.Type.UNDEFINED) {

View File

@@ -44,6 +44,10 @@ public final class FizzPluginFilterChain {
}
public static Mono<Void> next(ServerWebExchange exchange) {
if (WebUtils.ignorePlugin(exchange)) {
WebFilterChain chain = exchange.getAttribute(WEB_FILTER_CHAIN);
return chain.filter(exchange);
}
Iterator<PluginConfig> it = exchange.getAttribute(pluginConfigsIt);
Route route = WebUtils.getRoute(exchange);
if (it == null || route.pluginConfigsChange) {

View File

@@ -47,6 +47,7 @@ public class ApiConfig {
static final byte REVERSE_PROXY = 3;
static final byte CALLBACK = 4;
static final byte DUBBO = 5;
static final byte DIRECT_RESPONSE = 6;
}
public static final String ALL_METHOD = "AM";
@@ -226,6 +227,7 @@ public class ApiConfig {
Route r = new Route().dedicatedLine( this.dedicatedLine)
.type( this.type)
.method( request.getMethod())
.path( this.path)
.registryCenter( this.registryCenter)
.backendService( this.backendService)
.backendPath( this.backendPath)

View File

@@ -18,6 +18,7 @@
package we.proxy;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import we.plugin.PluginConfig;
import we.util.Consts;
import we.util.JacksonUtils;
@@ -36,6 +37,8 @@ public class Route {
public HttpMethod method;
public String path;
public String registryCenter;
public String backendService;
@@ -68,6 +71,10 @@ public class Route {
public long retryInterval = 0;
public MediaType contentType;
public String body;
public Route dedicatedLine(boolean b) {
dedicatedLine = b;
return this;
@@ -83,6 +90,11 @@ public class Route {
return this;
}
public Route path(String p) {
path = p;
return this;
}
public Route registryCenter(String rc) {
registryCenter = rc;
return this;
@@ -150,6 +162,16 @@ public class Route {
return this;
}
public Route contentType(MediaType type) {
contentType = type;
return this;
}
public Route body(String b) {
body = b;
return this;
}
@Deprecated
public String getBackendPathQuery() {
if (query != null) {

View File

@@ -28,10 +28,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import we.config.AggregateRedisConfig;
import we.config.SystemConfig;
import we.util.Consts;
import we.util.JacksonUtils;
import we.util.Result;
import we.util.ThreadContext;
import we.util.*;
import javax.annotation.Resource;
import java.util.Collections;
@@ -182,7 +179,11 @@ public class RegistryCenterService implements ApplicationListener<ContextRefresh
}
public String getInstance(String registryCenter, String service) {
return registryCenterMap.get(registryCenter).getInstance(service);
RegistryCenter rc = registryCenterMap.get(registryCenter);
if (rc == null) {
throw Utils.runtimeExceptionWithoutStack(registryCenter + " not exists");
}
return rc.getInstance(service);
}
public static String getServiceNameSpace(String registryCenter, String service) {

View File

@@ -115,10 +115,16 @@ public abstract class WebUtils {
public static final String ORIGINAL_ERROR = "origerr@";
public static final String IGNORE_PLUGIN = "ignPlg@";
private WebUtils() {
}
public static boolean ignorePlugin(ServerWebExchange exchange) {
return exchange.getAttributes().containsKey(IGNORE_PLUGIN);
}
public static boolean isFavReq(ServerWebExchange exchange) {
return exchange.getAttribute(FAV_REQUEST) != null;
}