From 94d9b0da90428b1ad504f07192fd5733afeb0f9e Mon Sep 17 00:00:00 2001 From: tanghc Date: Mon, 25 Nov 2019 19:53:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E6=A1=A3=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitee/sop/gatewaycommon/bean/SopConstants.java | 2 ++ .../gatewaycommon/manager/ServiceRoutesLoader.java | 5 ++--- .../gatewaycommon/route/ServiceRouteListener.java | 5 ++--- .../sop/servercommon/bean/OpenContextImpl.java | 2 ++ .../mapping/ApiMappingHandlerMapping.java | 13 ------------- 5 files changed, 8 insertions(+), 19 deletions(-) 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);