diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java index d4c7856c..54a2fd60 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java @@ -22,6 +22,8 @@ public class SopConstants { public static final String REDIRECT_PATH_KEY = "r-path"; + public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path"; + /** * 在拦截器中调用获取参数: * String cachedBody = (String)exchange.getAttribute(SopConstants.CACHE_REQUEST_BODY_OBJECT_KEY); diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java index c80158fd..1391bfa7 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java @@ -9,6 +9,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import com.gitee.sop.gatewaycommon.bean.NacosConfigs; import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo; +import com.gitee.sop.gatewaycommon.bean.SopConstants; import com.gitee.sop.gatewaycommon.bean.TargetRoute; import com.gitee.sop.gatewaycommon.route.RegistryListener; import lombok.extern.slf4j.Slf4j; @@ -46,8 +47,6 @@ public class ServiceRoutesLoader { private static final int FIVE_SECONDS = 1000 * 5; - private static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path"; - private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path"; @Autowired @@ -159,7 +158,7 @@ public class ServiceRoutesLoader { } else { // 默认处理 homeUrl = getHomeUrl(instance); - String contextPath = metadata.getOrDefault(METADATA_SERVER_CONTEXT_PATH, ""); + String contextPath = metadata.getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, ""); servletPath = contextPath + SOP_ROUTES_PATH; } if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java index 3a0f81d9..5c7b0a80 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java @@ -3,6 +3,7 @@ package com.gitee.sop.gatewaycommon.route; import com.alibaba.fastjson.JSON; import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo; +import com.gitee.sop.gatewaycommon.bean.SopConstants; import com.gitee.sop.gatewaycommon.manager.BaseRouteCache; import com.gitee.sop.gatewaycommon.manager.EnvironmentKeys; import lombok.extern.slf4j.Slf4j; @@ -23,8 +24,6 @@ public class ServiceRouteListener extends BaseServiceListener { private static final String SOP_ROUTES_PATH = "/sop/routes"; - private static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path"; - private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path"; private static final String HEADER_RESTFUL = "restful"; @@ -89,7 +88,7 @@ public class ServiceRouteListener extends BaseServiceListener { } else { // 默认处理 homeUrl = getHomeUrl(instance); - String contextPath = metadata.getOrDefault(METADATA_SERVER_CONTEXT_PATH, ""); + String contextPath = metadata.getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, ""); servletPath = contextPath + SOP_ROUTES_PATH; } if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) { diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java index 93efe8ea..a71bf45b 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java @@ -39,6 +39,8 @@ public class OpenContextImpl implements OpenContext { String bizContent = getBizContent(); if (bizContent != null) { bizObject = (T) JSON.parseObject(bizContent, bizClass); + } else { + bizObject = (T) rootJsonObject.toJavaObject(bizClass); } } } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java index 506704b6..8506f015 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java @@ -17,19 +17,6 @@ import java.lang.reflect.Method; */ public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping implements PriorityOrdered { - private static StringValueResolver stringValueResolver = new ApiMappingStringValueResolver(); - - @Override - protected RequestMappingInfo getMappingForMethod(Method method, Class handlerType) { - ApiMapping apiMapping = method.getAnnotation(ApiMapping.class); - StringValueResolver valueResolver = null; - if (apiMapping != null) { - valueResolver = stringValueResolver; - } - this.setEmbeddedValueResolver(valueResolver); - return super.getMappingForMethod(method, handlerType); - } - @Override protected RequestCondition getCustomMethodCondition(Method method) { method.setAccessible(true);