commit
6fc25b5434
@ -1,32 +1,32 @@ |
||||
* [首页](/?t=1563956863130) |
||||
* [首页](/?t=1564027102043) |
||||
* 开发文档 |
||||
* [快速体验](files/10010_快速体验.md?t=1563956863132) |
||||
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1563956863153) |
||||
* [新增接口](files/10020_新增接口.md?t=1563956863153) |
||||
* [业务参数校验](files/10030_业务参数校验.md?t=1563956863153) |
||||
* [错误处理](files/10040_错误处理.md?t=1563956863153) |
||||
* [编写文档](files/10041_编写文档.md?t=1563956863153) |
||||
* [接口交互详解](files/10050_接口交互详解.md?t=1563956863153) |
||||
* [easyopen支持](files/10070_easyopen支持.md?t=1563956863154) |
||||
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1563956863154) |
||||
* [ISV管理](files/10085_ISV管理.md?t=1563956863154) |
||||
* [自定义路由](files/10086_自定义路由.md?t=1563956863154) |
||||
* [路由授权](files/10090_路由授权.md?t=1563956863154) |
||||
* [接口限流](files/10092_接口限流.md?t=1563956863154) |
||||
* [监控日志](files/10093_监控日志.md?t=1563956863154) |
||||
* [SDK开发](files/10095_SDK开发.md?t=1563956863154) |
||||
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1563956863154) |
||||
* [应用授权](files/10097_应用授权.md?t=1563956863155) |
||||
* [更改数据节点名称](files/10099_更改数据节点名称.md?t=1563956863155) |
||||
* [传统web开发](files/10100_传统web开发.md?t=1563956863155) |
||||
* [自定义过滤器](files/10102_自定义过滤器.md?t=1563956863155) |
||||
* [文件上传](files/10104_文件上传.md?t=1563956863155) |
||||
* [nacos注册中心](files/10106_nacos注册中心.md?t=1563956863155) |
||||
* [扩展其它注册中心](files/10107_扩展其它注册中心.md?t=1563956863155) |
||||
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1563956863155) |
||||
* [快速体验](files/10010_快速体验.md?t=1564027102045) |
||||
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1564027102062) |
||||
* [新增接口](files/10020_新增接口.md?t=1564027102062) |
||||
* [业务参数校验](files/10030_业务参数校验.md?t=1564027102062) |
||||
* [错误处理](files/10040_错误处理.md?t=1564027102062) |
||||
* [编写文档](files/10041_编写文档.md?t=1564027102063) |
||||
* [接口交互详解](files/10050_接口交互详解.md?t=1564027102063) |
||||
* [easyopen支持](files/10070_easyopen支持.md?t=1564027102063) |
||||
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1564027102063) |
||||
* [ISV管理](files/10085_ISV管理.md?t=1564027102063) |
||||
* [自定义路由](files/10086_自定义路由.md?t=1564027102063) |
||||
* [路由授权](files/10090_路由授权.md?t=1564027102063) |
||||
* [接口限流](files/10092_接口限流.md?t=1564027102063) |
||||
* [监控日志](files/10093_监控日志.md?t=1564027102063) |
||||
* [SDK开发](files/10095_SDK开发.md?t=1564027102063) |
||||
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1564027102064) |
||||
* [应用授权](files/10097_应用授权.md?t=1564027102064) |
||||
* [更改数据节点名称](files/10099_更改数据节点名称.md?t=1564027102064) |
||||
* [传统web开发](files/10100_传统web开发.md?t=1564027102064) |
||||
* [自定义过滤器](files/10102_自定义过滤器.md?t=1564027102064) |
||||
* [文件上传](files/10104_文件上传.md?t=1564027102064) |
||||
* [nacos注册中心](files/10106_nacos注册中心.md?t=1564027102064) |
||||
* [扩展其它注册中心](files/10107_扩展其它注册中心.md?t=1564027102064) |
||||
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1564027102064) |
||||
* 原理分析 |
||||
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1563956863156) |
||||
* [原理分析之路由存储](files/90011_原理分析之路由存储.md?t=1563956863156) |
||||
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1563956863156) |
||||
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1563956863156) |
||||
* [常见问题](files/90100_常见问题.md?t=1563956863156) |
||||
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1564027102064) |
||||
* [原理分析之路由存储](files/90011_原理分析之路由存储.md?t=1564027102064) |
||||
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1564027102064) |
||||
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1564027102064) |
||||
* [常见问题](files/90100_常见问题.md?t=1564027102065) |
||||
|
@ -1,20 +0,0 @@ |
||||
package com.gitee.sop.servercommon.mapping; |
||||
|
||||
import org.springframework.util.StringUtils; |
||||
|
||||
/** |
||||
* @author tanghc |
||||
*/ |
||||
public class MappingUtil { |
||||
/** |
||||
* 将springmvc接口路径转换成SOP方法名 |
||||
* @param path springmvc路径,如/a/b,/goods/listGoods |
||||
* @return |
||||
*/ |
||||
public static String buildApiName(String path) { |
||||
path = StringUtils.trimLeadingCharacter(path, '/'); |
||||
path = StringUtils.trimTrailingCharacter(path, '/'); |
||||
path = path.replace("/", "."); |
||||
return path; |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
package com.gitee.sop.servercommon.mapping; |
||||
|
||||
import org.springframework.util.StringUtils; |
||||
|
||||
/** |
||||
* @author tanghc |
||||
*/ |
||||
public class RouteUtil { |
||||
|
||||
/** |
||||
* 将springmvc接口路径转换成SOP方法名 |
||||
* |
||||
* @param path springmvc路径,如:/goods/listGoods |
||||
* @return 返回接口方法名,/goods/listGoods -> goods.listGoods |
||||
*/ |
||||
public static String buildApiName(String path) { |
||||
char separatorChar = '/'; |
||||
path = StringUtils.trimLeadingCharacter(path, separatorChar); |
||||
path = StringUtils.trimTrailingCharacter(path, separatorChar); |
||||
return path.replace(separatorChar, '.'); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,47 @@ |
||||
package com.gitee.sop.gateway.controller; |
||||
|
||||
import com.gitee.sop.gatewaycommon.bean.SopConstants; |
||||
import com.gitee.sop.gatewaycommon.param.ParamNames; |
||||
import com.gitee.sop.gatewaycommon.util.RouteUtil; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
|
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.annotation.WebServlet; |
||||
import javax.servlet.http.HttpServlet; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
|
||||
@WebServlet(urlPatterns = "/rest/*") |
||||
public class RestServlet extends HttpServlet { |
||||
|
||||
private static final String REST_PATH = "/rest"; |
||||
|
||||
@Value("${zuul.servlet-path:/zuul}") |
||||
private String path; |
||||
|
||||
@Value("${zuul.rest-default-version:1.0}") |
||||
private String defaultVersion; |
||||
|
||||
@Override |
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
doPost(request, response); |
||||
} |
||||
|
||||
@Override |
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
||||
String url = request.getRequestURL().toString(); |
||||
int index = url.indexOf(REST_PATH); |
||||
// 取/rest的后面部分
|
||||
String path = url.substring(index + REST_PATH.length()); |
||||
String method = RouteUtil.buildApiName(path); |
||||
String version = request.getParameter(ParamNames.VERSION_NAME); |
||||
if (version == null) { |
||||
version = defaultVersion; |
||||
} |
||||
request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, method); |
||||
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version); |
||||
request.getRequestDispatcher(this.path).forward(request, response); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue