Merge branch 'we-code' into develop
This commit is contained in:
@@ -9,11 +9,12 @@
|
||||
<version>2.2.13.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-bootstrap</artifactId>
|
||||
|
||||
<version>2.3.3-beta1</version>
|
||||
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-framework.version>5.2.13.RELEASE</spring-framework.version>
|
||||
|
||||
43
fizz-bootstrap/src/main/java/we/MyApiConfig.java
Normal file
43
fizz-bootstrap/src/main/java/we/MyApiConfig.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package we;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import we.config.ManualApiConfig;
|
||||
import we.plugin.PluginConfig;
|
||||
import we.plugin.auth.ApiConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定义 MyApiConfig 继承 ManualApiConfig, 并注解为 Configuration,
|
||||
* 然后实现 setApiConfigs 方法,在方法中添加路由配置
|
||||
*/
|
||||
@Configuration
|
||||
public class MyApiConfig extends ManualApiConfig {
|
||||
|
||||
@Override
|
||||
public List<ApiConfig> setApiConfigs() {
|
||||
|
||||
List<ApiConfig> apiConfigs = new ArrayList<>();
|
||||
|
||||
ApiConfig ac = new ApiConfig(); // 一个路由配置
|
||||
ac.id = 1000; // 路由 id,建议从 1000 开始
|
||||
ac.service = "xservice"; // 前端服务名
|
||||
ac.path = "/ypath"; // 前端路径
|
||||
ac.type = ApiConfig.Type.REVERSE_PROXY; // 路由类型,此处为反向代理
|
||||
ac.httpHostPorts = Collections.singletonList("http://127.0.0.1:9094"); // 被代理接口的地址
|
||||
// ac.httpHostPorts = Collections.singletonList("https://self-signed.badssl.com");
|
||||
ac.backendPath = "/@ypath"; // 被代理接口的路径
|
||||
// ac.backendPath = "/";
|
||||
ac.pluginConfigs = new ArrayList<>();
|
||||
PluginConfig pc = new PluginConfig();
|
||||
pc.plugin = "myPlugin"; // 应用 id 为 myPlugin 的插件
|
||||
ac.pluginConfigs.add(pc);
|
||||
|
||||
apiConfigs.add(ac);
|
||||
|
||||
log.info("set api configs end");
|
||||
return apiConfigs; // 返回路由配置
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.3-beta1</version>
|
||||
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fizz-common</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -28,7 +28,11 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.ServerWebExchangeDecorator;
|
||||
import reactor.core.publisher.Mono;
|
||||
import we.spring.http.server.reactive.ext.FizzServerHttpRequestDecorator;
|
||||
|
||||
import we.util.Consts;
|
||||
|
||||
|
||||
|
||||
import we.util.NettyDataBufferUtils;
|
||||
import we.util.ThreadContext;
|
||||
|
||||
@@ -73,7 +77,9 @@ public class FizzServerWebExchangeDecorator extends ServerWebExchangeDecorator {
|
||||
if (idx == -1) {
|
||||
result.add(URLDecoder.decode(pair, charset.name()), null);
|
||||
} else {
|
||||
|
||||
String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
|
||||
|
||||
String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
|
||||
result.add(name, value);
|
||||
}
|
||||
@@ -126,6 +132,7 @@ public class FizzServerWebExchangeDecorator extends ServerWebExchangeDecorator {
|
||||
String field = fieldValuesEntry.getKey();
|
||||
List<String> values = fieldValuesEntry.getValue();
|
||||
if (CollectionUtils.isEmpty(values)) {
|
||||
|
||||
b.append(URLEncoder.encode(field, Consts.C.UTF8));
|
||||
} else {
|
||||
int vs = values.size();
|
||||
@@ -133,6 +140,7 @@ public class FizzServerWebExchangeDecorator extends ServerWebExchangeDecorator {
|
||||
b.append(URLEncoder.encode(field, Consts.C.UTF8))
|
||||
.append('=')
|
||||
.append(URLEncoder.encode(values.get(i), Consts.C.UTF8));
|
||||
|
||||
if ((++i) != vs) {
|
||||
b.append('&');
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.3-beta1</version>
|
||||
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fizz-core</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -61,7 +61,9 @@ public class RequestBodyPlugin implements FizzPluginFilter {
|
||||
} finally {
|
||||
NettyDataBufferUtils.release(body);
|
||||
}
|
||||
|
||||
// requestDecorator.getHeaders().remove(HttpHeaders.CONTENT_LENGTH);
|
||||
|
||||
}
|
||||
ServerWebExchange mutatedExchange = exchange.mutate().request(requestDecorator).build();
|
||||
ServerWebExchange newExchange = mutatedExchange;
|
||||
@@ -70,8 +72,10 @@ public class RequestBodyPlugin implements FizzPluginFilter {
|
||||
newExchange = new FizzServerWebExchangeDecorator(mutatedExchange);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
|
||||
String traceId = WebUtils.getTraceId(exchange);
|
||||
log.debug(traceId + " request is decorated", LogService.BIZ_ID, traceId);
|
||||
|
||||
}
|
||||
return FizzPluginFilterChain.next(newExchange);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.3-beta1</version>
|
||||
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fizz-plugin</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
21
fizz-plugin/src/main/java/we/plugin/myplugin/MyPlugin.java
Normal file
21
fizz-plugin/src/main/java/we/plugin/myplugin/MyPlugin.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package we.plugin.myplugin;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
import we.plugin.FizzPluginFilter;
|
||||
import we.plugin.FizzPluginFilterChain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component(MyPlugin.MY_PLUGIN) // 必须,且为插件 id
|
||||
public class MyPlugin implements FizzPluginFilter {
|
||||
|
||||
public static final String MY_PLUGIN = "myPlugin"; // 插件 id
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, Map<String, Object> config) {
|
||||
System.err.println("this is my plugin"); // 本插件只输出这个
|
||||
return FizzPluginFilterChain.next(exchange); // 执行后续逻辑
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
|
||||
<version>2.3.3-beta1</version>
|
||||
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>fizz-spring-boot-starter</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
Reference in New Issue
Block a user