diff --git a/fizz-core/pom.xml b/fizz-core/pom.xml
index 8d3960a..53935a1 100644
--- a/fizz-core/pom.xml
+++ b/fizz-core/pom.xml
@@ -13,9 +13,16 @@
fizz-core
+ 1.0.0-SNAPSHOT
+
+ com.fizzgate
+ fizz-aggregate-spring-boot-starter
+ ${aggregate.version}
+
+
com.lmaxdisruptor
diff --git a/fizz-core/src/main/java/com/fizzgate/config/AppConfigProperties.java b/fizz-core/src/main/java/com/fizzgate/config/AppConfigProperties.java
deleted file mode 100644
index 6e4fa5a..0000000
--- a/fizz-core/src/main/java/com/fizzgate/config/AppConfigProperties.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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 .
- */
-
-package com.fizzgate.config;
-
-import lombok.Data;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.cloud.context.config.annotation.RefreshScope;
-import org.springframework.stereotype.Component;
-
-@RefreshScope
-@Component
-@Data
-public class AppConfigProperties {
-
- @Value("${spring.profiles.active}")
- private String env;
-}
-
diff --git a/fizz-core/src/main/java/com/fizzgate/config/RefreshLocalCacheConfig.java b/fizz-core/src/main/java/com/fizzgate/config/RefreshLocalCacheConfig.java
index 3148837..355a7b1 100644
--- a/fizz-core/src/main/java/com/fizzgate/config/RefreshLocalCacheConfig.java
+++ b/fizz-core/src/main/java/com/fizzgate/config/RefreshLocalCacheConfig.java
@@ -16,12 +16,12 @@
*/
package com.fizzgate.config;
+import com.fizzgate.aggregate.web.loader.ConfigLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
-import com.fizzgate.fizz.ConfigLoader;
import com.fizzgate.plugin.auth.ApiConfig2appsService;
import com.fizzgate.plugin.auth.ApiConfigService;
import com.fizzgate.plugin.auth.AppService;
diff --git a/fizz-core/src/main/java/com/fizzgate/controller/ConfigController.java b/fizz-core/src/main/java/com/fizzgate/controller/ConfigController.java
index 807e2e1..e97539c 100644
--- a/fizz-core/src/main/java/com/fizzgate/controller/ConfigController.java
+++ b/fizz-core/src/main/java/com/fizzgate/controller/ConfigController.java
@@ -17,12 +17,12 @@
package com.fizzgate.controller;
+import com.fizzgate.aggregate.web.loader.ConfigLoader;
import org.apache.commons.io.FileUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;
-import com.fizzgate.fizz.ConfigLoader;
import com.fizzgate.util.ScriptUtils;
import reactor.core.publisher.Mono;
diff --git a/fizz-core/src/main/java/com/fizzgate/controller/ManagerConfigController.java b/fizz-core/src/main/java/com/fizzgate/controller/ManagerConfigController.java
index 263dbff..92e683c 100644
--- a/fizz-core/src/main/java/com/fizzgate/controller/ManagerConfigController.java
+++ b/fizz-core/src/main/java/com/fizzgate/controller/ManagerConfigController.java
@@ -17,6 +17,7 @@
package com.fizzgate.controller;
+import com.fizzgate.aggregate.web.loader.ConfigLoader;
import com.fizzgate.controller.req.BaseManagerConfigReq;
import com.fizzgate.controller.req.GetApiConfigDetailReq;
import com.fizzgate.controller.req.GetApiConfigReq;
@@ -27,7 +28,6 @@ import com.fizzgate.controller.resp.ConfigResp;
import com.fizzgate.controller.resp.ConfigStrResp;
import com.fizzgate.controller.resp.GetApiConfigDetailResp;
import com.fizzgate.controller.resp.GetApiConfigResp;
-import com.fizzgate.fizz.ConfigLoader;
import com.fizzgate.plugin.PluginConfig;
import com.fizzgate.plugin.auth.ApiConfig;
import com.fizzgate.plugin.auth.ApiConfig2appsService;
diff --git a/fizz-core/src/main/java/com/fizzgate/controller/resp/ConfigResp.java b/fizz-core/src/main/java/com/fizzgate/controller/resp/ConfigResp.java
index c69ed7d..9e55f8c 100644
--- a/fizz-core/src/main/java/com/fizzgate/controller/resp/ConfigResp.java
+++ b/fizz-core/src/main/java/com/fizzgate/controller/resp/ConfigResp.java
@@ -17,12 +17,12 @@
package com.fizzgate.controller.resp;
+import com.fizzgate.aggregate.web.loader.ConfigLoader;
+
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
-import com.fizzgate.fizz.ConfigLoader;
-
/**
* 聚合配置响应实体类
* @author zhongjie
diff --git a/fizz-core/src/main/java/com/fizzgate/exception/ExecuteScriptException.java b/fizz-core/src/main/java/com/fizzgate/exception/ExecuteScriptException.java
deleted file mode 100644
index ffd88f8..0000000
--- a/fizz-core/src/main/java/com/fizzgate/exception/ExecuteScriptException.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 .
- */
-
-package com.fizzgate.exception;
-
-import com.fizzgate.fizz.StepContext;
-
-/**
- * @author Francis
- */
-public class ExecuteScriptException extends RuntimeException {
-
- private StepContext stepContext;
-
- private Object data;
-
- public ExecuteScriptException(String message, StepContext stepContext, Object data) {
- super(message);
- this.data = data;
- this.stepContext = stepContext;
- this.stepContext.setExceptionInfo(this, data);
- }
-
- public ExecuteScriptException(Throwable cause, StepContext stepContext, Object data) {
- super("execute script failed: " + cause.getMessage(), cause);
- this.data = data;
- this.stepContext = stepContext;
- this.setStackTrace(cause.getStackTrace());
- this.stepContext.setExceptionInfo(this, data);
- }
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public Object getData() {
- return data;
- }
-
- public void setData(Object data) {
- this.data = data;
- }
-
- public StepContext getStepContext() {
- return stepContext;
- }
-
- public void setStepContext(StepContext stepContext) {
- this.stepContext = stepContext;
- }
-
-}
diff --git a/fizz-core/src/main/java/com/fizzgate/exception/RedirectException.java b/fizz-core/src/main/java/com/fizzgate/exception/RedirectException.java
deleted file mode 100644
index 27a2f65..0000000
--- a/fizz-core/src/main/java/com/fizzgate/exception/RedirectException.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 .
- */
-
-package com.fizzgate.exception;
-
-/**
- * @author Francis
- */
-public class RedirectException extends RuntimeException {
-
- private String redirectUrl;
-
- public RedirectException(String message, String redirectUrl) {
- super(message);
- this.redirectUrl = redirectUrl;
- }
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public String getRedirectUrl() {
- return redirectUrl;
- }
-
- public void setRedirectUrl(String redirectUrl) {
- this.redirectUrl = redirectUrl;
- }
-
-}
diff --git a/fizz-core/src/main/java/com/fizzgate/exception/StopAndResponseException.java b/fizz-core/src/main/java/com/fizzgate/exception/StopAndResponseException.java
deleted file mode 100644
index 2ff078f..0000000
--- a/fizz-core/src/main/java/com/fizzgate/exception/StopAndResponseException.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 .
- */
-
-package com.fizzgate.exception;
-
-/**
- * @author Francis
- */
-public class StopAndResponseException extends RuntimeException {
-
- private String data;
-
- public StopAndResponseException(String message, String data) {
- super(message);
- this.data = data;
- }
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public String getData() {
- return data;
- }
-
- public void setData(String data) {
- this.data = data;
- }
-
-}
diff --git a/fizz-core/src/main/java/com/fizzgate/filter/AggregateFilter.java b/fizz-core/src/main/java/com/fizzgate/filter/AggregateFilter.java
deleted file mode 100644
index 96a73fc..0000000
--- a/fizz-core/src/main/java/com/fizzgate/filter/AggregateFilter.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * 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 .
- */
-
-package com.fizzgate.filter;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.serializer.SerializerFeature;
-import com.fizzgate.config.SystemConfig;
-import com.fizzgate.constants.CommonConstants;
-import com.fizzgate.fizz.AggregateResource;
-import com.fizzgate.fizz.AggregateResult;
-import com.fizzgate.fizz.ConfigLoader;
-import com.fizzgate.fizz.Pipeline;
-import com.fizzgate.fizz.input.Input;
-import com.fizzgate.plugin.auth.ApiConfig;
-import com.fizzgate.util.Consts;
-import com.fizzgate.util.MapUtil;
-import com.fizzgate.util.NettyDataBufferUtils;
-import com.fizzgate.util.WebUtils;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.logging.log4j.ThreadContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.annotation.Order;
-import org.springframework.core.io.buffer.DataBufferUtils;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.codec.multipart.FilePart;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.stereotype.Component;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilter;
-import org.springframework.web.server.WebFilterChain;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
-
-import javax.annotation.Resource;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * @author Francis Dong
- */
-@Component
-@Order(30)
-public class AggregateFilter implements WebFilter {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(AggregateFilter.class);
-
- private static final String X_FORWARDED_FOR = "X-FORWARDED-FOR";
-
- @Resource
- private ConfigLoader configLoader;
-
- @Resource
- private AggregateFilterProperties aggregateFilterProperties;
-
- @Resource
- private SystemConfig systemConfig;
-
- @Override
- public Mono filter(ServerWebExchange exchange, WebFilterChain chain) {
-
- 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) {
- String p = exchange.getRequest().getURI().getPath();
- if (StringUtils.startsWith(p, SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX0)) {
- if (systemConfig.isAggregateTestAuth()) {
- return chain.filter(exchange);
- }
- } else if (aggregateFilterProperties.isNeedAuth()) {
- return chain.filter(exchange);
- }
- } else if (act != ApiConfig.Type.SERVICE_AGGREGATE) {
- return chain.filter(exchange);
- }
- }
-
- FilterResult pfr = WebUtils.getPrevFilterResult(exchange);
- if (!pfr.success) {
- return WebUtils.getDirectResponse(exchange);
- }
-
- long start = System.currentTimeMillis();
- ServerHttpRequest request = exchange.getRequest();
- ServerHttpResponse serverHttpResponse = exchange.getResponse();
-
- String clientReqPathPrefix = WebUtils.getClientReqPathPrefix(exchange);
- String path = clientReqPathPrefix + serviceId + WebUtils.getBackendPath(exchange);
- String method = request.getMethodValue();
- if (HttpMethod.HEAD.matches(method.toUpperCase())) {
- method = HttpMethod.GET.name();
- }
- AggregateResource aggregateResource = configLoader.matchAggregateResource(method, path);
- if (aggregateResource == null) {
- if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX0.equals(clientReqPathPrefix) ||
- WebUtils.getApiConfigType(exchange) == ApiConfig.Type.SERVICE_AGGREGATE) {
- return WebUtils.responseError(exchange, HttpStatus.NOT_FOUND.value(), "API not found in aggregation: " + path);
- } else {
- return chain.filter(exchange);
- }
- }
-
- Pipeline pipeline = aggregateResource.getPipeline();
- Input input = aggregateResource.getInput();
-
- HttpHeaders hds = request.getHeaders();
- Map headers = MapUtil.headerToHashMap(hds);
- if (CollectionUtils.isEmpty(hds.get(X_FORWARDED_FOR)) && systemConfig.isFizzWebClientXForwardedForEnable()) {
- headers.put(X_FORWARDED_FOR, WebUtils.getOriginIp(exchange));
- }
- Map fizzHeaders = (Map) exchange.getAttributes().get(WebUtils.APPEND_HEADERS);
- if (fizzHeaders != null && !fizzHeaders.isEmpty()) {
- Set> entrys = fizzHeaders.entrySet();
- for (Entry entry : entrys) {
- headers.put(entry.getKey().toUpperCase(), entry.getValue());
- }
- }
-
- // traceId
- final String traceId = WebUtils.getTraceId(exchange);
- // LogService.setBizId(traceId);
- ThreadContext.put(Consts.TRACE_ID, traceId);
-
- LOGGER.debug("{} matched api in aggregation: {}", traceId, path);
-
- // 客户端提交上来的信息
- Map clientInput = new HashMap<>();
- clientInput.put("path", path);
- clientInput.put("method", method);
- clientInput.put("headers", headers);
- clientInput.put("params", MapUtil.toHashMap(request.getQueryParams()));
- clientInput.put("contentType", request.getHeaders().getFirst(CommonConstants.HEADER_CONTENT_TYPE));
-
- Mono result = null;
- MediaType contentType = request.getHeaders().getContentType();
-
- if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) {
- result = exchange.getMultipartData().flatMap(md -> {
- Map filePartMap = new HashMap<>();
- clientInput.put("body", MapUtil.extractFormData(md, CommonConstants.FILE_KEY_PREFIX, filePartMap));
- clientInput.put("filePartMap", filePartMap);
- return pipeline.run(input, clientInput, traceId);
- });
- } else if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
- result = exchange.getFormData().flatMap(fd -> {
- clientInput.put("body", MapUtil.toHashMap(fd));
- return pipeline.run(input, clientInput, traceId);
- });
- } else {
- if (HttpMethod.POST.name().equalsIgnoreCase(method)) {
- result = DataBufferUtils.join(request.getBody()).defaultIfEmpty(NettyDataBufferUtils.EMPTY_DATA_BUFFER).flatMap(buf -> {
- if (buf != NettyDataBufferUtils.EMPTY_DATA_BUFFER) {
- try {
- clientInput.put("body", buf.toString(StandardCharsets.UTF_8));
- } finally {
- DataBufferUtils.release(buf);
- }
- }
- return pipeline.run(input, clientInput, traceId);
- });
- } else {
- result = pipeline.run(input, clientInput, traceId);
- }
- }
- return result.subscribeOn(Schedulers.elastic()).flatMap(aggResult -> {
- // LogService.setBizId(traceId);
- ThreadContext.put(Consts.TRACE_ID, traceId);
- if (aggResult.getHttpStatus() != null) {
- serverHttpResponse.setRawStatusCode(aggResult.getHttpStatus());
- }
- String jsonString = null;
- if (aggResult.getBody() instanceof String) {
- jsonString = (String) aggResult.getBody();
- } else {
- if (this.aggregateFilterProperties.isWriteMapNullValue()) {
- jsonString = JSON.toJSONString(aggResult.getBody(), SerializerFeature.WriteMapNullValue);
- } else {
- jsonString = JSON.toJSONString(aggResult.getBody());
- }
- }
- LOGGER.debug("{} response body: {}", traceId, jsonString);
- if (aggResult.getHeaders() != null && !aggResult.getHeaders().isEmpty()) {
- serverHttpResponse.getHeaders().addAll(aggResult.getHeaders());
- serverHttpResponse.getHeaders().remove(CommonConstants.HEADER_CONTENT_LENGTH);
- }
- if (!serverHttpResponse.getHeaders().containsKey(CommonConstants.HEADER_CONTENT_TYPE)) {
- // default content-type
- serverHttpResponse.getHeaders().add(CommonConstants.HEADER_CONTENT_TYPE, CommonConstants.CONTENT_TYPE_JSON);
- }
- List headerTraceIds = serverHttpResponse.getHeaders().get(systemConfig.fizzTraceIdHeader());
- if (headerTraceIds == null || !headerTraceIds.contains(traceId)) {
- serverHttpResponse.getHeaders().add(systemConfig.fizzTraceIdHeader(), traceId);
- }
-
- long end = System.currentTimeMillis();
- pipeline.getStepContext().addElapsedTime("总耗时", end - start);
- LOGGER.info("{} ElapsedTimes={}", traceId, JSON.toJSONString(pipeline.getStepContext().getElapsedTimes()));
-
- return serverHttpResponse
- .writeWith(Flux.just(exchange.getResponse().bufferFactory().wrap(jsonString.getBytes())));
- });
-
- }
-
-}
\ No newline at end of file
diff --git a/fizz-core/src/main/java/com/fizzgate/filter/AggregateFilterProperties.java b/fizz-core/src/main/java/com/fizzgate/filter/AggregateFilterProperties.java
deleted file mode 100644
index 1063af5..0000000
--- a/fizz-core/src/main/java/com/fizzgate/filter/AggregateFilterProperties.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 .
- */
-package com.fizzgate.filter;
-
-import lombok.Data;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.cloud.context.config.annotation.RefreshScope;
-import org.springframework.stereotype.Component;
-
-import com.fizzgate.context.config.annotation.FizzRefreshScope;
-
-/**
- * {@link AggregateFilter} properties
- *
- * @author zhongjie
- */
-//@RefreshScope
-@FizzRefreshScope
-@Component
-@Data
-public class AggregateFilterProperties {
-
- @Value("${need-auth:true}")
- private boolean needAuth;
-
- @Value("${fizz.aggregate.writeMapNullValue:false}")
- private boolean writeMapNullValue;
-}
diff --git a/fizz-core/src/main/java/com/fizzgate/filter/FilterExceptionHandlerConfig.java b/fizz-core/src/main/java/com/fizzgate/filter/FilterExceptionHandlerConfig.java
index e773488..83d1e90 100644
--- a/fizz-core/src/main/java/com/fizzgate/filter/FilterExceptionHandlerConfig.java
+++ b/fizz-core/src/main/java/com/fizzgate/filter/FilterExceptionHandlerConfig.java
@@ -17,6 +17,12 @@
package com.fizzgate.filter;
+import com.fizzgate.Fizz;
+import com.fizzgate.aggregate.web.util.AggregateExceptionHandleUtils;
+import com.fizzgate.config.SystemConfig;
+import com.fizzgate.util.Consts;
+import com.fizzgate.util.ThreadContext;
+import com.fizzgate.util.WebUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,23 +36,8 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebExceptionHandler;
-
-import com.fizzgate.Fizz;
-import com.fizzgate.config.SystemConfig;
-import com.fizzgate.exception.ExecuteScriptException;
-import com.fizzgate.exception.RedirectException;
-import com.fizzgate.exception.StopAndResponseException;
-import com.fizzgate.fizz.exception.FizzRuntimeException;
-import com.fizzgate.legacy.RespEntity;
-import com.fizzgate.util.Consts;
-import com.fizzgate.util.JacksonUtils;
-import com.fizzgate.util.ThreadContext;
-import com.fizzgate.util.WebUtils;
-
import reactor.core.publisher.Mono;
-import java.net.URI;
-
/**
* @author hongqiaowei
*/
@@ -84,53 +75,14 @@ public class FilterExceptionHandlerConfig {
respHeaders.set(WebUtils.BODY_ENCRYPT, Consts.S.FALSE0);
}
- if (t instanceof StopAndResponseException) {
- StopAndResponseException ex = (StopAndResponseException) t;
- if (ex.getData() != null) {
- respHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
- return resp.writeWith(Mono.just(resp.bufferFactory().wrap(ex.getData().toString().getBytes())));
- }
- }
- if (t instanceof RedirectException) {
- RedirectException ex = (RedirectException) t;
- if (ex.getRedirectUrl() != null) {
- resp.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
- respHeaders.setLocation(URI.create(ex.getRedirectUrl()));
- return Mono.empty();
- }
+ if (AggregateExceptionHandleUtils.needHandle(t)) {
+ return AggregateExceptionHandleUtils.handle(exchange, respHeaders, resp, t, traceId, LOGGER);
}
String tMsg = t.getMessage();
if (tMsg == null) {
tMsg = t.toString();
}
- if (t instanceof ExecuteScriptException) {
- ExecuteScriptException ex = (ExecuteScriptException) t;
- respHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
- RespEntity rs = null;
- if (ex.getStepContext() != null && ex.getStepContext().returnContext()) {
- rs = new RespEntity(HttpStatus.INTERNAL_SERVER_ERROR.value(), tMsg, traceId, ex.getStepContext());
- return resp.writeWith(Mono.just(resp.bufferFactory().wrap(JacksonUtils.writeValueAsBytes(rs))));
- } else {
- rs = new RespEntity(HttpStatus.INTERNAL_SERVER_ERROR.value(), tMsg, traceId);
- return resp.writeWith(Mono.just(resp.bufferFactory().wrap(rs.toString().getBytes())));
- }
- }
-
- if (t instanceof FizzRuntimeException) {
- FizzRuntimeException ex = (FizzRuntimeException) t;
- org.apache.logging.log4j.ThreadContext.put(Consts.TRACE_ID, traceId);
- LOGGER.error(tMsg, ex);
- respHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
- RespEntity rs = null;
- if (ex.getStepContext() != null && ex.getStepContext().returnContext()) {
- rs = new RespEntity(HttpStatus.INTERNAL_SERVER_ERROR.value(), tMsg, traceId, ex.getStepContext());
- return resp.writeWith(Mono.just(resp.bufferFactory().wrap(JacksonUtils.writeValueAsString(rs).getBytes())));
- } else {
- rs = new RespEntity(HttpStatus.INTERNAL_SERVER_ERROR.value(), tMsg, traceId);
- return resp.writeWith(Mono.just(resp.bufferFactory().wrap(rs.toString().getBytes())));
- }
- }
Mono vm;
Object fc = exchange.getAttribute(WebUtils.FILTER_CONTEXT);
diff --git a/fizz-core/src/main/java/com/fizzgate/fizz/AggregateResource.java b/fizz-core/src/main/java/com/fizzgate/fizz/AggregateResource.java
deleted file mode 100644
index bd5f4a4..0000000
--- a/fizz-core/src/main/java/com/fizzgate/fizz/AggregateResource.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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 .
- */
-package com.fizzgate.fizz;
-
-import com.fizzgate.fizz.input.Input;
-
-/**
- *
- * @author Francis Dong
- *
- */
-public class AggregateResource {
-
- private Pipeline pipeline;
- private Input input;
-
- public AggregateResource(Pipeline pipeline, Input input) {
- super();
- this.pipeline = pipeline;
- this.input = input;
- }
-
- public Pipeline getPipeline() {
- return pipeline;
- }
-
- public void setPipeline(Pipeline pipeline) {
- this.pipeline = pipeline;
- }
-
- public Input getInput() {
- return input;
- }
-
- public void setInput(Input input) {
- this.input = input;
- }
-
-}
diff --git a/fizz-core/src/main/java/com/fizzgate/fizz/AggregateResult.java b/fizz-core/src/main/java/com/fizzgate/fizz/AggregateResult.java
deleted file mode 100644
index 199735a..0000000
--- a/fizz-core/src/main/java/com/fizzgate/fizz/AggregateResult.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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 .
- */
-
-package com.fizzgate.fizz;
-
-import org.springframework.util.MultiValueMap;
-
-/**
- *
- * @author Francis Dong
- *
- */
-public class AggregateResult {
-
- private Integer httpStatus;
-
- private MultiValueMap headers;
-
- private Object body;
-
- private StepContext stepContext;
-
- public MultiValueMap getHeaders() {
- return headers;
- }
-
- public void setHeaders(MultiValueMap headers) {
- this.headers = headers;
- }
-
- public Object getBody() {
- return body;
- }
-
- public void setBody(Object body) {
- this.body = body;
- }
-
- public StepContext getStepContext() {
- return stepContext;
- }
-
- public void setStepContext(StepContext stepContext) {
- this.stepContext = stepContext;
- }
-
- public Integer getHttpStatus() {
- return httpStatus;
- }
-
- public void setHttpStatus(Integer httpStatus) {
- this.httpStatus = httpStatus;
- }
-
-}
diff --git a/fizz-core/src/main/java/com/fizzgate/fizz/AggregateService.java b/fizz-core/src/main/java/com/fizzgate/fizz/AggregateService.java
deleted file mode 100644
index 763e88c..0000000
--- a/fizz-core/src/main/java/com/fizzgate/fizz/AggregateService.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * 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 .
- */
-
-package com.fizzgate.fizz;
-
-import com.alibaba.fastjson.JSON;
-import com.fizzgate.config.SystemConfig;
-import com.fizzgate.fizz.input.Input;
-import com.fizzgate.util.Consts;
-import com.fizzgate.util.MapUtil;
-import com.fizzgate.util.Utils;
-import com.fizzgate.util.WebUtils;
-
-import org.apache.logging.log4j.ThreadContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.io.buffer.DataBuffer;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.stereotype.Service;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
-
-import javax.annotation.Resource;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author hongqiaowei
- */
-
-@Service
-public class AggregateService {
-
- private static final Logger log = LoggerFactory.getLogger(AggregateService.class);
-
- @Resource
- private ConfigLoader aggregateResourceLoader;
-
- @Resource
- private SystemConfig systemConfig;
-
- public Mono request(String traceId, String clientReqPathPrefix, String method, String service, String path, MultiValueMap queryParams,
- HttpHeaders headers, String body) {
-
- // long start = System.currentTimeMillis();
- // ServerHttpRequest request = exchange.getRequest();
- String pash = clientReqPathPrefix + service + path;
- // String method = request.getMethodValue();
- AggregateResource aggregateResource = aggregateResourceLoader.matchAggregateResource(method, pash);
- if (aggregateResource == null) {
- return Mono.error(Utils.runtimeExceptionWithoutStack("no aggregate resource: " + method + ' ' + pash));
- } else {
- Pipeline pipeline = aggregateResource.getPipeline();
- Input input = aggregateResource.getInput();
- Map hs = MapUtil.toHashMap(headers);
- // LogService.setBizId(traceId);
- ThreadContext.put(Consts.TRACE_ID, traceId);
- log.debug("matched aggregation api: {}", pash);
- Map clientInput = new HashMap<>();
- clientInput.put("path", pash);
- clientInput.put("method", method);
- clientInput.put("headers", hs);
- // MultiValueMap queryParams = request.getQueryParams();
- if (queryParams != null) {
- clientInput.put("params", MapUtil.toHashMap(queryParams));
- }
- if (body != null) {
- clientInput.put("body", JSON.parse(body));
- }
- return pipeline.run(input, clientInput, traceId).subscribeOn(Schedulers.elastic());
- }
- }
-
- public Mono request(String traceId, String clientReqPathPrefix, String method, String service, String path, MultiValueMap queryParams,
- HttpHeaders headers, DataBuffer body) {
- String b = null;
- if (body != null) {
- b = body.toString(StandardCharsets.UTF_8);
- }
- return request(traceId, clientReqPathPrefix, method, service, path, queryParams, headers, b);
- }
-
- public Mono extends Void> genAggregateResponse(ServerWebExchange exchange, AggregateResult ar) {
- ServerHttpResponse clientResp = exchange.getResponse();
- String traceId = WebUtils.getTraceId(exchange);
- // LogService.setBizId(traceId);
- ThreadContext.put(Consts.TRACE_ID, traceId);
- String js = null;
- if(ar.getBody() instanceof String) {
- js = (String) ar.getBody();
- }else {
- js = JSON.toJSONString(ar.getBody());
- }
- log.debug("aggregate response body: {}", js);
- if (ar.getHeaders() != null && !ar.getHeaders().isEmpty()) {
- ar.getHeaders().remove("Content-Length");
- clientResp.getHeaders().addAll(ar.getHeaders());
- }
- if (!clientResp.getHeaders().containsKey("Content-Type")) {
- // defalut content-type
- clientResp.getHeaders().add("Content-Type", "application/json; charset=UTF-8");
- }
- List headerTraceIds = clientResp.getHeaders().get(systemConfig.fizzTraceIdHeader());
- if (headerTraceIds == null || !headerTraceIds.contains(traceId)) {
- clientResp.getHeaders().add(systemConfig.fizzTraceIdHeader(), traceId);
- }
- // long end = System.currentTimeMillis();
- // pipeline.getStepContext().addElapsedTime("总耗时", end - start);
- // log.info("ElapsedTimes={}", JSON.toJSONString(pipeline.getStepContext().getElapsedTimes()));
- return clientResp
- .writeWith(Flux.just(exchange.getResponse().bufferFactory().wrap(js.getBytes())));
- }
-
-}
diff --git a/fizz-core/src/main/java/com/fizzgate/fizz/ConfigLoader.java b/fizz-core/src/main/java/com/fizzgate/fizz/ConfigLoader.java
deleted file mode 100644
index 54565a1..0000000
--- a/fizz-core/src/main/java/com/fizzgate/fizz/ConfigLoader.java
+++ /dev/null
@@ -1,520 +0,0 @@
-/*
- * 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 .
- */
-
-package com.fizzgate.fizz;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.fizzgate.config.AppConfigProperties;
-import com.fizzgate.fizz.input.ClientInputConfig;
-import com.fizzgate.fizz.input.Input;
-import com.fizzgate.fizz.input.InputFactory;
-import com.fizzgate.fizz.input.InputType;
-import com.fizzgate.util.Consts;
-import com.fizzgate.util.ReactorUtils;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.logging.log4j.ThreadContext;
-import org.noear.snack.ONode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
-import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.lang.ref.SoftReference;
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
-import static com.fizzgate.config.AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE;
-import static com.fizzgate.util.Consts.S.FORWARD_SLASH;
-import static com.fizzgate.util.Consts.S.FORWARD_SLASH_STR;
-
-/**
- *
- * @author Francis Dong
- * @author zhongjie
- *
- */
-@Component
-public class ConfigLoader {
- /**
- * legacy aggregate formal path prefix
- */
- private static final String LEGACY_FORMAL_PATH_PREFIX = "/proxy";
- /**
- * legacy aggregate test path prefix
- */
- private static final String LEGACY_TEST_PATH_PREFIX = "/proxytest";
- /**
- * aggregate test path prefix
- */
- private static final String TEST_PATH_PREFIX = "/_proxytest";
- /**
- * aggregate test path service name start index
- */
- private static final int TEST_PATH_SERVICE_NAME_START_INDEX = TEST_PATH_PREFIX.length() + 1;
-
- @Autowired
- public ConfigurableApplicationContext appContext;
- private static final Logger LOGGER = LoggerFactory.getLogger(ConfigLoader.class);
-
- /**
- * 聚合配置存放Hash的Key
- */
- private static final String AGGREGATE_HASH_KEY = "fizz_aggregate_config";
-
- private static Map aggregateResources = null;
- private static Map resourceKey2ConfigInfoMap = null;
- private static Map aggregateId2ResourceKeyMap = null;
-
- @Resource
- private AppConfigProperties appConfigProperties;
-
- @Resource(name = AGGREGATE_REACTIVE_REDIS_TEMPLATE)
- private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
-
- @Resource
- private ConfigLoaderProperties configLoaderProperties;
-
- private String formalPathPrefix;
- private int formalPathServiceNameStartIndex;
-
- public Input createInput(String configStr) throws IOException {
- ONode cfgNode = ONode.loadStr(configStr);
-
- Input input = new Input();
- input.setName(cfgNode.select("$.name").getString());
-
- ClientInputConfig clientInputConfig = new ClientInputConfig();
- clientInputConfig.setDataMapping(cfgNode.select("$.dataMapping").toObject(Map.class));
- clientInputConfig.setHeaders(cfgNode.select("$.headers").toObject(Map.class));
- clientInputConfig.setMethod(cfgNode.select("$.method").getString());
- clientInputConfig.setPath(cfgNode.select("$.path").getString());
- if (clientInputConfig.getPath().startsWith(TEST_PATH_PREFIX)) {
- // always enable debug for testing
- clientInputConfig.setDebug(true);
- } else {
- if (cfgNode.select("$.debug") != null) {
- clientInputConfig.setDebug(cfgNode.select("$.debug").getBoolean());
- }
- }
- clientInputConfig.setType(InputType.valueOf(cfgNode.select("$.type").getString()));
- clientInputConfig.setLangDef(cfgNode.select("$.langDef").toObject(Map.class));
- clientInputConfig.setBodyDef(cfgNode.select("$.bodyDef").toObject(Map.class));
- clientInputConfig.setHeadersDef(cfgNode.select("$.headersDef").toObject(Map.class));
- clientInputConfig.setParamsDef(cfgNode.select("$.paramsDef").toObject(Map.class));
- clientInputConfig.setScriptValidate(cfgNode.select("$.scriptValidate").toObject(Map.class));
- clientInputConfig.setValidateResponse(cfgNode.select("$.validateResponse").toObject(Map.class));
- clientInputConfig.setContentType(cfgNode.select("$.contentType").getString());
- clientInputConfig.setXmlArrPaths(cfgNode.select("$.xmlArrPaths").getString());
- input.setConfig(clientInputConfig);
- return input;
- }
-
- public Pipeline createPipeline(String configStr) throws IOException {
- ONode cfgNode = ONode.loadStr(configStr);
-
- Pipeline pipeline = new Pipeline();
- pipeline.setApplicationContext(appContext);
-
- List