Merge branch 'we-code' into develop

This commit is contained in:
hongqiaowei
2021-10-15 15:37:41 +08:00
committed by GitHub
9 changed files with 93 additions and 22 deletions

View File

@@ -9,11 +9,12 @@
<version>2.2.13.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.fizzgate</groupId>
<artifactId>fizz-bootstrap</artifactId>
<version>2.3.3-beta2</version>
<properties>
<java.version>1.8</java.version>
<spring-framework.version>5.2.13.RELEASE</spring-framework.version>

View 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; // 返回路由配置
}
}

View File

@@ -5,11 +5,12 @@
<parent>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.3.3-beta2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>fizz-common</artifactId>
<properties>

View File

@@ -123,24 +123,24 @@ public class FizzServerWebExchangeDecorator extends ServerWebExchangeDecorator {
int fs = fieldValuesEntries.size(), cnt = 0;
try {
for (Map.Entry<String, List<String>> fieldValuesEntry : fieldValuesEntries) {
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();
for (int i = 0; i < vs; ) {
b.append(URLEncoder.encode(field, Consts.C.UTF8))
.append('=')
.append(URLEncoder.encode(values.get(i), Consts.C.UTF8));
if ((++i) != vs) {
b.append('&');
}
}
}
if ((++cnt) != fs) {
b.append('&');
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();
for (int i = 0; i < vs; ) {
b.append(URLEncoder.encode(field, Consts.C.UTF8))
.append('=')
.append(URLEncoder.encode(values.get(i), Consts.C.UTF8));
if ((++i) != vs) {
b.append('&');
}
}
}
if ((++cnt) != fs) {
b.append('&');
}
}
} catch (UnsupportedEncodingException ex) {
throw new IllegalStateException(ex);

View File

@@ -5,11 +5,12 @@
<parent>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.3.3-beta2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>fizz-core</artifactId>
<properties>

View File

@@ -5,11 +5,12 @@
<parent>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.3.3-beta2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>fizz-plugin</artifactId>
<properties>

View 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); // 执行后续逻辑
}
}

View File

@@ -5,11 +5,12 @@
<parent>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.3.3-beta2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>fizz-spring-boot-starter</artifactId>
<properties>

View File

@@ -34,7 +34,9 @@
<artifactId>fizz-gateway-community</artifactId>
<name>${project.artifactId}</name>
<description>fizz gateway community</description>
<version>2.3.3-beta2</version>
<packaging>pom</packaging>
<modules>
<module>fizz-common</module>