tanghc 5 years ago
parent 55ca508905
commit eb4612f22f
  1. 21
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/MappingUtil.java
  2. 15
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RouteUtil.java
  3. 4
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/DefaultRequestMappingEvent.java
  4. 24
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/MappingUtil.java
  5. 23
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/RouteUtil.java
  6. 4
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/DocumentationPluginsManagerExt.java
  7. 11
      sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java
  8. 2
      sop-gateway/src/main/resources/application-dev.properties

@ -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。

Loading…
Cancel
Save