mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
代码转移
This commit is contained in:
@@ -6,14 +6,17 @@ import com.gitee.sop.gatewaycommon.manager.AbstractConfiguration;
|
|||||||
import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext;
|
import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext;
|
||||||
import com.gitee.sop.gatewaycommon.param.ParamBuilder;
|
import com.gitee.sop.gatewaycommon.param.ParamBuilder;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.ValidateService;
|
import com.gitee.sop.gatewaycommon.zuul.ValidateService;
|
||||||
|
import com.gitee.sop.gatewaycommon.zuul.controller.ConfigChannelController;
|
||||||
|
import com.gitee.sop.gatewaycommon.zuul.controller.ErrorLogController;
|
||||||
|
import com.gitee.sop.gatewaycommon.zuul.controller.ZuulIndexController;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter;
|
import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.FormBodyWrapperFilterExt;
|
import com.gitee.sop.gatewaycommon.zuul.filter.FormBodyWrapperFilterExt;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.PostResultFilter;
|
import com.gitee.sop.gatewaycommon.zuul.filter.PostResultFilter;
|
||||||
|
import com.gitee.sop.gatewaycommon.zuul.filter.PreEnvGrayFilter;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.PreHttpServletRequestWrapperFilter;
|
import com.gitee.sop.gatewaycommon.zuul.filter.PreHttpServletRequestWrapperFilter;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.PreLimitFilter;
|
import com.gitee.sop.gatewaycommon.zuul.filter.PreLimitFilter;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.PreParameterFormatterFilter;
|
import com.gitee.sop.gatewaycommon.zuul.filter.PreParameterFormatterFilter;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.PreValidateFilter;
|
import com.gitee.sop.gatewaycommon.zuul.filter.PreValidateFilter;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.PreEnvGrayFilter;
|
|
||||||
import com.gitee.sop.gatewaycommon.zuul.filter.Servlet30WrapperFilterExt;
|
import com.gitee.sop.gatewaycommon.zuul.filter.Servlet30WrapperFilterExt;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.route.SopRouteLocator;
|
import com.gitee.sop.gatewaycommon.zuul.route.SopRouteLocator;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.route.ZuulRouteCache;
|
import com.gitee.sop.gatewaycommon.zuul.route.ZuulRouteCache;
|
||||||
@@ -39,6 +42,21 @@ public class BaseZuulConfiguration extends AbstractConfiguration {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected ServerProperties server;
|
protected ServerProperties server;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ConfigChannelController configChannelController() {
|
||||||
|
return new ConfigChannelController();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ErrorLogController errorLogController() {
|
||||||
|
return new ErrorLogController();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ZuulIndexController zuulIndexController() {
|
||||||
|
return new ZuulIndexController();
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
ParamBuilder<RequestContext> paramBuilder() {
|
ParamBuilder<RequestContext> paramBuilder() {
|
||||||
|
@@ -8,6 +8,7 @@ import com.gitee.sop.gatewaycommon.result.CustomDataNameBuilder;
|
|||||||
*
|
*
|
||||||
* @author tanghc
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class WebappZuulConfiguration extends BaseZuulConfiguration {
|
public class WebappZuulConfiguration extends BaseZuulConfiguration {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@@ -1,21 +1,21 @@
|
|||||||
package com.gitee.sop.gateway.controller;
|
package com.gitee.sop.gatewaycommon.zuul.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.gitee.sop.gateway.manager.DbEnvGrayManager;
|
|
||||||
import com.gitee.sop.gateway.manager.DbIPBlacklistManager;
|
|
||||||
import com.gitee.sop.gateway.manager.DbIsvManager;
|
|
||||||
import com.gitee.sop.gateway.manager.DbIsvRoutePermissionManager;
|
|
||||||
import com.gitee.sop.gateway.manager.DbLimitConfigManager;
|
|
||||||
import com.gitee.sop.gateway.manager.DbRouteConfigManager;
|
|
||||||
import com.gitee.sop.gatewaycommon.bean.GatewayPushDTO;
|
import com.gitee.sop.gatewaycommon.bean.GatewayPushDTO;
|
||||||
import com.gitee.sop.gatewaycommon.bean.NacosConfigs;
|
import com.gitee.sop.gatewaycommon.bean.NacosConfigs;
|
||||||
import com.gitee.sop.gatewaycommon.bean.SpringContext;
|
import com.gitee.sop.gatewaycommon.bean.SpringContext;
|
||||||
import com.gitee.sop.gatewaycommon.manager.ChannelMsgProcessor;
|
import com.gitee.sop.gatewaycommon.manager.ChannelMsgProcessor;
|
||||||
|
import com.gitee.sop.gatewaycommon.manager.EnvGrayManager;
|
||||||
|
import com.gitee.sop.gatewaycommon.manager.IPBlacklistManager;
|
||||||
|
import com.gitee.sop.gatewaycommon.manager.IsvRoutePermissionManager;
|
||||||
|
import com.gitee.sop.gatewaycommon.manager.LimitConfigManager;
|
||||||
|
import com.gitee.sop.gatewaycommon.manager.RouteConfigManager;
|
||||||
|
import com.gitee.sop.gatewaycommon.secret.IsvManager;
|
||||||
import com.gitee.sop.gatewaycommon.util.RequestUtil;
|
import com.gitee.sop.gatewaycommon.util.RequestUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -26,24 +26,24 @@ import java.util.Map;
|
|||||||
* @author tanghc
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@Controller
|
||||||
public class ConfigChannelController {
|
public class ConfigChannelController {
|
||||||
|
|
||||||
private static Map<String, Class<? extends ChannelMsgProcessor>> processorMap = new HashMap<>(16);
|
private static Map<String, Class<? extends ChannelMsgProcessor>> processorMap = new HashMap<>(16);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_GRAY, DbEnvGrayManager.class);
|
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_GRAY, EnvGrayManager.class);
|
||||||
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_IP_BLACKLIST, DbIPBlacklistManager.class);
|
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_IP_BLACKLIST, IPBlacklistManager.class);
|
||||||
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_ISV, DbIsvManager.class);
|
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_ISV, IsvManager.class);
|
||||||
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_ROUTE_PERMISSION, DbIsvRoutePermissionManager.class);
|
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_ROUTE_PERMISSION, IsvRoutePermissionManager.class);
|
||||||
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_LIMIT_CONFIG, DbLimitConfigManager.class);
|
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_LIMIT_CONFIG, LimitConfigManager.class);
|
||||||
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_ROUTE_CONFIG, DbRouteConfigManager.class);
|
processorMap.put(NacosConfigs.GROUP_CHANNEL + NacosConfigs.DATA_ID_ROUTE_CONFIG, RouteConfigManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${zuul.secret}")
|
@Value("${zuul.secret}")
|
||||||
private String secret;
|
private String secret;
|
||||||
|
|
||||||
@PostMapping("/configChannelMsg")
|
@PostMapping("/sop/configChannelMsg")
|
||||||
public String configChannel(HttpServletRequest request) throws IOException {
|
public String configChannel(HttpServletRequest request) throws IOException {
|
||||||
String requestJson = RequestUtil.getText(request);
|
String requestJson = RequestUtil.getText(request);
|
||||||
String sign = request.getHeader("sign");
|
String sign = request.getHeader("sign");
|
@@ -1,4 +1,4 @@
|
|||||||
package com.gitee.sop.gateway.controller;
|
package com.gitee.sop.gatewaycommon.zuul.controller;
|
||||||
|
|
||||||
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
|
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
|
||||||
import com.gitee.sop.gatewaycommon.bean.ErrorEntity;
|
import com.gitee.sop.gatewaycommon.bean.ErrorEntity;
|
||||||
@@ -9,6 +9,7 @@ import com.gitee.sop.gatewaycommon.result.JsonResult;
|
|||||||
import com.gitee.sop.gatewaycommon.util.RequestUtil;
|
import com.gitee.sop.gatewaycommon.util.RequestUtil;
|
||||||
import com.gitee.sop.gatewaycommon.validate.taobao.TaobaoSigner;
|
import com.gitee.sop.gatewaycommon.validate.taobao.TaobaoSigner;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* @author tanghc
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
@RestController
|
@Controller
|
||||||
public class ErrorLogController {
|
public class ErrorLogController {
|
||||||
|
|
||||||
TaobaoSigner signer = new TaobaoSigner();
|
TaobaoSigner signer = new TaobaoSigner();
|
@@ -1,4 +1,4 @@
|
|||||||
package com.gitee.sop.gateway.controller;
|
package com.gitee.sop.gatewaycommon.zuul.controller;
|
||||||
|
|
||||||
import com.gitee.sop.gatewaycommon.bean.SopConstants;
|
import com.gitee.sop.gatewaycommon.bean.SopConstants;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -14,7 +14,7 @@ import java.io.IOException;
|
|||||||
* 传统web开发入口
|
* 传统web开发入口
|
||||||
* @author tanghc
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
@WebServlet(urlPatterns = "/rest/*")
|
//@WebServlet(urlPatterns = "/rest/*")
|
||||||
public class RestServlet extends HttpServlet {
|
public class RestServlet extends HttpServlet {
|
||||||
|
|
||||||
private static final String EMPTY_VERSION = "";
|
private static final String EMPTY_VERSION = "";
|
@@ -1,4 +1,4 @@
|
|||||||
package com.gitee.sop.gateway.controller;
|
package com.gitee.sop.gatewaycommon.zuul.controller;
|
||||||
|
|
||||||
import com.gitee.sop.gatewaycommon.bean.SopConstants;
|
import com.gitee.sop.gatewaycommon.bean.SopConstants;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.ValidateService;
|
import com.gitee.sop.gatewaycommon.zuul.ValidateService;
|
||||||
@@ -9,8 +9,10 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* zuul网关入口
|
* zuul网关入口
|
||||||
@@ -21,12 +23,17 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
@Controller
|
@Controller
|
||||||
public class ZuulIndexController {
|
public class ZuulIndexController {
|
||||||
|
|
||||||
|
private static final String EMPTY_VERSION = "";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ValidateService validateService;
|
private ValidateService validateService;
|
||||||
|
|
||||||
@Value("${zuul.servlet-path:/zuul}")
|
@Value("${zuul.servlet-path:/zuul}")
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
|
@Value("${sop.restful.path:/rest}")
|
||||||
|
private String restPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证回调,可自定义实现接口
|
* 验证回调,可自定义实现接口
|
||||||
*/
|
*/
|
||||||
@@ -49,6 +56,25 @@ public class ZuulIndexController {
|
|||||||
validateService.validate(request, response, callback);
|
validateService.validate(request, response, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* restful入口
|
||||||
|
* @param request
|
||||||
|
* @param response
|
||||||
|
* @throws ServletException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@RequestMapping("/rest/**")
|
||||||
|
public void rest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
String url = request.getRequestURL().toString();
|
||||||
|
int index = url.indexOf(restPath);
|
||||||
|
// 取/rest的后面部分
|
||||||
|
String path = url.substring(index + restPath.length());
|
||||||
|
request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, path);
|
||||||
|
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, EMPTY_VERSION);
|
||||||
|
request.setAttribute(SopConstants.SOP_NOT_MERGE, true);
|
||||||
|
request.getRequestDispatcher(this.path).forward(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping("/{method}/{version}/")
|
@RequestMapping("/{method}/{version}/")
|
||||||
public void redirect(
|
public void redirect(
|
||||||
@PathVariable("method") String method
|
@PathVariable("method") String method
|
||||||
@@ -60,7 +86,4 @@ public class ZuulIndexController {
|
|||||||
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version);
|
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version);
|
||||||
validateService.validate(request, response, callback);
|
validateService.validate(request, response, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user