/*
* Copyright (C) 2020 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.fizzgate.util;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.server.ServerWebExchange;
import com.fizzgate.config.SystemConfig;
import com.fizzgate.filter.FilterResult;
import com.fizzgate.plugin.auth.ApiConfig;
import com.fizzgate.plugin.auth.AuthPluginFilter;
import com.fizzgate.proxy.Route;
import com.fizzgate.util.Consts;
import com.fizzgate.util.JacksonUtils;
import com.fizzgate.util.NettyDataBufferUtils;
import com.fizzgate.util.Result;
import com.fizzgate.util.ThreadContext;
import com.fizzgate.util.Utils;
import reactor.core.publisher.Mono;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author hongqiaowei
*/
public abstract class WebUtils {
// TODO: don't log in this class
private static final Logger log = LoggerFactory.getLogger(WebUtils.class);
private static final String clientService = "cs@";
private static final String xForwardedFor = "X-Forwarded-For";
private static final String unknown = "unknown";
private static final String loopBack = "127.0.0.1";
private static final String binaryAddress = "0:0:0:0:0:0:0:1";
private static final String directResponse = "dr@";
private static final String response = " response ";
private static final String originIp = "oi@";
private static final String clientRequestPath = "crp@";
private static final String clientRequestPathPrefix = "crpp@";
private static final String clientRequestQuery = "crq@";
private static String gatewayPrefix = SystemConfig.DEFAULT_GATEWAY_PREFIX;
private static List<String> appHeaders = Stream.of(SystemConfig.FIZZ_APP_ID) .collect(Collectors.toList());
private static List<String> signHeaders = Stream.of(SystemConfig.FIZZ_SIGN) .collect(Collectors.toList());
private static List<String> timestampHeaders = Stream.of(SystemConfig.FIZZ_TIMESTAMP).collect(Collectors.toList());
public static final String TRACE_ID = "traid@";
public static final String BACKEND_SERVICE = "bs@";
public static final String FILTER_CONTEXT = "fc@";
public static final String APPEND_HEADERS = "ahs@";
public static final String PREV_FILTER_RESULT = "pfr@";
public static final String BACKEND_PATH = "bp@";
public static final String ROUTE = "rout@";
public static boolean LOG_RESPONSE_BODY = false;
public static Set<String> LOG_HEADER_SET = Collections.emptySet();
public static final String ADMIN_REQUEST = "ar@";
public static final String FIZZ_REQUEST = "fr@";
public static final String FAV_REQUEST = "fa@";
public static final String BODY_ENCRYPT = "b-ecyt";
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;
}
public static boolean isAdminReq(ServerWebExchange exchange) {
return exchange.getAttribute(ADMIN_REQUEST) != null;
}
public static boolean isFizzReq(ServerWebExchange exchange) {
return exchange.getAttribute(FIZZ_REQUEST) != null;
}
public static void setGatewayPrefix(String p) {
gatewayPrefix = p;
}
public static void setAppHeaders(List<String> hdrs) {
appHeaders = hdrs;
}
public static void setSignHeaders(List<String> hdrs) {
signHeaders = hdrs;
}
public static void setTimestampHeaders(List<String> hdrs) {
timestampHeaders = hdrs;
}
public static String getHeaderValue(ServerWebExchange exchange, String header) {
return exchange.getRequest().getHeaders().getFirst(header);
}
public static List<String> getHeaderValues(ServerWebExchange exchange, String header) {
return exchange.getRequest().getHeaders().get(header);
}
public static boolean isDedicatedLineRequest(ServerWebExchange exchange) {
String v = exchange.getRequest().getHeaders().getFirst(SystemConfig.FIZZ_DL_ID);
return v != null;
}
public static String getAppId(ServerWebExchange exchange) {
HttpHeaders headers = exchange.getRequest().getHeaders();
for (int i = 0; i < appHeaders.size(); i++) {
String v = headers.getFirst(appHeaders.get(i));
if (v != null) {
return v;
}
}
return null;
}
public static String getTimestamp(ServerWebExchange exchange) {
HttpHeaders headers = exchange.getRequest().getHeaders();
for (int i = 0; i < timestampHeaders.size(); i++) {
String v = headers.getFirst(timestampHeaders.get(i));
if (v != null) {
return v;
}
}
return null;
}
public static String getSign(ServerWebExchange exchange) {
HttpHeaders headers = exchange.getRequest().getHeaders();
for (int i = 0; i < signHeaders.size(); i++) {
String v = headers.getFirst(signHeaders.get(i));
if (v != null) {
return v;
}
}
return null;
}
public static String getDedicatedLineId(ServerWebExchange exchange) {
return getHeaderValue(exchange, SystemConfig.FIZZ_DL_ID);
}
public static String getDedicatedLineTimestamp(ServerWebExchange exchange) {
return getHeaderValue(exchange, SystemConfig.FIZZ_DL_TS);
}
p
没有合适的资源?快使用搜索试试~ 我知道了~
一个基于 Java开发的微服务聚合网关,是拥有自主知识产权的应用网关国产化替代方案
共320个文件
java:274个
xml:10个
yml:9个
0 下载量 119 浏览量
2023-11-04
15:16:14
上传
评论
收藏 511KB ZIP 举报
温馨提示
一个基于 Java开发的微服务聚合网关,是拥有自主知识产权的应用网关国产化替代方案,能够实现热服务编排聚合、自动授权选择、线上服务脚本编码、在线测试、高性能路由、API审核管理、回调管理等目的,拥有强大的自定义插件系统可以自行扩展,并且提供友好的图形化配置界面,能够快速帮助企业进行API服务治理、减少中间层胶水代码以及降低编码投入、提高 API 服务的稳定性和安全性。
资源推荐
资源详情
资源评论
收起资源包目录
一个基于 Java开发的微服务聚合网关,是拥有自主知识产权的应用网关国产化替代方案 (320个子文件)
mvnw.cmd 6KB
boot.cmd 2KB
Dockerfile 541B
spring.factories 2KB
spring.factories 145B
.gitignore 101B
.gitignore 9B
.gitignore 9B
.gitignore 9B
.gitignore 9B
.gitignore 9B
favicon.ico 885B
WebUtils.java 40KB
ApiConfigService.java 29KB
XmlToJson.java 25KB
GrayReleasePlugin.java 23KB
FlowStat.java 22KB
FlowControlFilter.java 21KB
FlowStatTests.java 19KB
DedicatedLineHttpHandler.java 19KB
CircuitBreaker.java 16KB
CircuitBreakManager.java 15KB
FizzWebClient.java 14KB
FlowStatSchedConfig.java 14KB
FizzNacosProperties.java 13KB
FizzBeanFactoryPostProcessor.java 13KB
RouteFilter.java 13KB
ManagerConfigController.java 13KB
RpcInstanceServiceImpl.java 13KB
CallbackFilter.java 13KB
CallbackService.java 13KB
GrayReleasePluginTests.java 12KB
SystemConfig.java 12KB
ResourceRateLimitConfigService.java 12KB
FizzBootstrapApplication.java 11KB
UrlTransformUtils.java 11KB
CircuitBreakManagerTests.java 11KB
MapUtil.java 11KB
ServerReflectionClient.java 11KB
JsonToXml.java 11KB
FizzEnvironmentPostProcessor.java 10KB
ResourceStat.java 10KB
IpMatchUtils.java 10KB
PluginTests.java 9KB
RegistryCenterService.java 9KB
DedicatedLineController.java 9KB
FizzNacosServiceRegistration.java 8KB
RedisReactiveConfig.java 8KB
ReactiveRedisHelper.java 8KB
GatewayGroupService.java 8KB
JacksonUtils.java 8KB
AggregateRedisConfig.java 8KB
ServiceResolver.java 8KB
ApiConfig.java 8KB
FizzEurekaServiceRegistration.java 8KB
DedicatedLineService.java 8KB
JwtAuthPluginFilter.java 8KB
WebClientConfig.java 8KB
ServiceConfig.java 7KB
WebUtilsTests.java 7KB
ApiConfig2appsService.java 7KB
CacheCheckController.java 7KB
RedisReactiveProperties.java 7KB
IpUtils.java 7KB
PreprocessFilter.java 7KB
DegradeRuleService.java 7KB
FizzEurekaHelper.java 7KB
FizzMonitorService.java 7KB
GrpcReflectionUtils.java 7KB
DedicatedLineServiceRegistration.java 7KB
FizzServerWebExchangeDecorator.java 7KB
DedicatedLineCodecPluginFilter.java 7KB
RefreshLocalCacheConfig.java 7KB
AppService.java 7KB
TimeSlot.java 7KB
DateTimeUtils.java 6KB
IpPlugin.java 6KB
DedicatedLineInfoService.java 6KB
GlobalResourceService.java 6KB
App.java 6KB
XmlTests.java 6KB
Consts.java 6KB
RateLimitTests.java 6KB
AbstractFizzPlugin.java 6KB
FizzServerHttpRequestDecorator.java 6KB
FlowControlFilterTests.java 6KB
ScriptUtils.java 6KB
StatPluginFilter.java 5KB
FizzNacosHelper.java 5KB
GrpcClient.java 5KB
DedicatedLinePairingPluginFilter.java 5KB
LogSendAppenderWithLog4j2.java 5KB
BasicAuthPluginFilter.java 5KB
Constants.java 5KB
ApolloLog4j2ConfigurationFactory.java 5KB
Utils.java 5KB
FizzGatewayNodeStatSchedConfig.java 5KB
RequestBodyPlugin.java 5KB
NetworkUtils.java 5KB
RegistryCenterServiceTests.java 5KB
共 320 条
- 1
- 2
- 3
- 4
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7365
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于Hadoop的分布式数据处理系统.zip
- UML类图绘制指南.docx
- C#ASP.NET大型快运(快递)管理系统源码带完整文档数据库 SQL2008源码类型 WebForm
- (源码)基于ESP32CAM的QR码和RFID数据记录系统.zip
- (源码)基于深度学习和Flask框架的AI人脸识别系统.zip
- 苏标协议(江苏-道路运输车辆主动安全智能防控系统)
- (源码)基于Spring Boot和MyBatis Plus的秒杀系统.zip
- 数据分发服务-该服务用于将边缘端,算法特征数据,算法回传数据 进行分发,采用Flink广播+规则计算的方式进行分发
- (源码)基于ProtoCentral tinyGSR的实时生理状态监测系统.zip
- (源码)基于Arduino的吉他音符频率检测系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功