mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
1.13.1
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package com.gitee.sop.gatewaycommon.util;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class MappingUtil {
|
||||
|
||||
public static final char SEPARATOR_CHAR = '/';
|
||||
|
||||
/**
|
||||
* 将springmvc接口路径转换成SOP方法名
|
||||
* @param path springmvc路径,如/a/b,/goods/listGoods
|
||||
* @return 返回接口方法名,/goods/listGoods -> goods.listGoods
|
||||
*/
|
||||
public static String buildApiName(String path) {
|
||||
path = StringUtils.trimLeadingCharacter(path, SEPARATOR_CHAR);
|
||||
path = StringUtils.trimTrailingCharacter(path, SEPARATOR_CHAR);
|
||||
path = path.replace(SEPARATOR_CHAR, '.');
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +1,7 @@
|
||||
package com.gitee.sop.gatewaycommon.util;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@@ -22,6 +24,19 @@ 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, '.');
|
||||
}
|
||||
|
||||
public static String getZuulLocation(String uri) {
|
||||
if (uri.toLowerCase().startsWith(PROTOCOL_LOAD_BALANCE)) {
|
||||
return uri.substring(PROTOCOL_LOAD_BALANCE.length());
|
||||
|
@@ -4,7 +4,7 @@ import com.gitee.sop.servercommon.bean.ServiceApiInfo;
|
||||
import com.gitee.sop.servercommon.bean.ServiceConfig;
|
||||
import com.gitee.sop.servercommon.mapping.ApiMappingInfo;
|
||||
import com.gitee.sop.servercommon.mapping.ApiMappingRequestCondition;
|
||||
import com.gitee.sop.servercommon.mapping.MappingUtil;
|
||||
import com.gitee.sop.servercommon.mapping.RouteUtil;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.core.env.Environment;
|
||||
@@ -108,7 +108,7 @@ public class DefaultRequestMappingEvent implements RequestMappingEvent {
|
||||
|
||||
|
||||
protected String buildName(String path) {
|
||||
return MappingUtil.buildApiName(path);
|
||||
return RouteUtil.buildApiName(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,24 +0,0 @@
|
||||
package com.gitee.sop.servercommon.mapping;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
public class MappingUtil {
|
||||
|
||||
public static final char SEPARATOR_CHAR = '/';
|
||||
|
||||
/**
|
||||
* 将springmvc接口路径转换成SOP方法名
|
||||
* @param path springmvc路径,如/a/b,/goods/listGoods
|
||||
* @return 返回接口方法名,/goods/listGoods -> goods.listGoods
|
||||
*/
|
||||
public static String buildApiName(String path) {
|
||||
path = StringUtils.trimLeadingCharacter(path, SEPARATOR_CHAR);
|
||||
path = StringUtils.trimTrailingCharacter(path, SEPARATOR_CHAR);
|
||||
path = path.replace(SEPARATOR_CHAR, '.');
|
||||
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, '.');
|
||||
}
|
||||
|
||||
}
|
@@ -3,7 +3,7 @@ package com.gitee.sop.servercommon.swagger;
|
||||
import com.gitee.sop.servercommon.annotation.ApiAbility;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.bean.ServiceConfig;
|
||||
import com.gitee.sop.servercommon.mapping.MappingUtil;
|
||||
import com.gitee.sop.servercommon.mapping.RouteUtil;
|
||||
import com.google.common.base.Optional;
|
||||
import springfox.documentation.service.Operation;
|
||||
import springfox.documentation.service.StringVendorExtension;
|
||||
@@ -42,7 +42,7 @@ public class DocumentationPluginsManagerExt extends DocumentationPluginsManager
|
||||
if (abilityOptional.isPresent()) {
|
||||
ApiAbility apiAbility = abilityOptional.get();
|
||||
String mappingPattern = operationContext.requestMappingPattern();
|
||||
String name = MappingUtil.buildApiName(mappingPattern);
|
||||
String name = RouteUtil.buildApiName(mappingPattern);
|
||||
String version = buildVersion(apiAbility.version());
|
||||
vendorExtensions.add(new StringVendorExtension(SOP_NAME, name));
|
||||
vendorExtensions.add(new StringVendorExtension(SOP_VERSION, version));
|
||||
|
@@ -2,7 +2,7 @@ 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.MappingUtil;
|
||||
import com.gitee.sop.gatewaycommon.util.RouteUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@@ -17,9 +17,12 @@ public class RestServlet extends HttpServlet {
|
||||
|
||||
private static final String REST_PATH = "/rest";
|
||||
|
||||
@Value("${zuul.servlet-path}")
|
||||
@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);
|
||||
@@ -31,10 +34,10 @@ public class RestServlet extends HttpServlet {
|
||||
int index = url.indexOf(REST_PATH);
|
||||
// 取/rest的后面部分
|
||||
String path = url.substring(index + REST_PATH.length());
|
||||
String method = MappingUtil.buildApiName(path);
|
||||
String method = RouteUtil.buildApiName(path);
|
||||
String version = request.getParameter(ParamNames.VERSION_NAME);
|
||||
if (version == null) {
|
||||
version = "1.0";
|
||||
version = defaultVersion;
|
||||
}
|
||||
request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, method);
|
||||
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version);
|
||||
|
@@ -21,6 +21,8 @@ zuul.FormBodyWrapperFilter.pre.disable=true
|
||||
zuul.Servlet30WrapperFilter.pre.disable=true
|
||||
# 不用改,如果要改,请全局替换修改
|
||||
zuul.secret=MZZOUSTua6LzApIWXCwEgbBmxSzpzC
|
||||
# 不用改
|
||||
zuul.rest-default-version=1.0
|
||||
|
||||
# https://blog.csdn.net/qq_36872046/article/details/81058045
|
||||
# 路由转发超时时间,毫秒,默认值1000,详见:RibbonClientConfiguration.DEFAULT_READ_TIMEOUT。
|
||||
|
Reference in New Issue
Block a user