diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java index 7694f84b..95236f02 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java @@ -30,6 +30,11 @@ import java.util.List; */ public class BaseGatewayConfiguration extends AbstractConfiguration { + public static boolean USE_GATEWAY; + static { + USE_GATEWAY = true; + } + /** * 自定义异常处理[@@]注册Bean时依赖的Bean,会从容器中直接获取,所以直接注入即可 * diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java index d50671ee..a5c2d034 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java @@ -1,8 +1,10 @@ package com.gitee.sop.gatewaycommon.manager; +import com.gitee.sop.gatewaycommon.bean.ApiConfig; import com.gitee.sop.gatewaycommon.bean.ApiContext; import com.gitee.sop.gatewaycommon.bean.BeanInitializer; import com.gitee.sop.gatewaycommon.message.ErrorFactory; +import com.gitee.sop.gatewaycommon.secret.IsvManager; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -32,6 +34,21 @@ public class AbstractConfiguration implements ApplicationContextAware { applicationContext = ctx; } + @Bean + IsvManager isvManager() { + return ApiConfig.getInstance().getIsvManager(); + } + + @Bean + IsvRoutePermissionManager isvRoutePermissionManager() { + return ApiConfig.getInstance().getIsvRoutePermissionManager(); + } + + @Bean + RouteConfigManager routeConfigManager() { + return ApiConfig.getInstance().getRouteConfigManager(); + } + /** * 跨域过滤器 * @@ -39,9 +56,7 @@ public class AbstractConfiguration implements ApplicationContextAware { */ @Bean public CorsFilter corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", corsConfiguration()); - return new CorsFilter(source); + return createCorsFilter(); } protected CorsFilter createCorsFilter() { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java index c5ad6f41..10a26973 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java @@ -1,6 +1,7 @@ package com.gitee.sop.gatewaycommon.message; import com.gitee.sop.gatewaycommon.exception.ApiException; +import com.gitee.sop.gatewaycommon.gateway.configuration.BaseGatewayConfiguration; import com.netflix.zuul.context.RequestContext; import lombok.Getter; @@ -54,6 +55,9 @@ public class ErrorMeta { } protected Locale getLocale() { + if (BaseGatewayConfiguration.USE_GATEWAY) { + return ZH_CN; + } RequestContext currentContext = RequestContext.getCurrentContext(); if (currentContext == null) { return ZH_CN; diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.java index b5315662..45d17017 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.java @@ -1,12 +1,8 @@ package com.gitee.sop.gatewaycommon.zuul.configuration; -import com.gitee.sop.gatewaycommon.bean.ApiConfig; import com.gitee.sop.gatewaycommon.bean.ApiContext; import com.gitee.sop.gatewaycommon.manager.AbstractConfiguration; -import com.gitee.sop.gatewaycommon.manager.IsvRoutePermissionManager; -import com.gitee.sop.gatewaycommon.manager.RouteConfigManager; import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext; -import com.gitee.sop.gatewaycommon.secret.IsvManager; import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PostResultFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PreLimitFilter; @@ -120,18 +116,4 @@ public class BaseZuulConfiguration extends AbstractConfiguration { return ApiContext.getApiConfig().getZuulErrorController(); } - @Bean - IsvManager isvManager() { - return ApiConfig.getInstance().getIsvManager(); - } - - @Bean - IsvRoutePermissionManager isvRoutePermissionManager() { - return ApiConfig.getInstance().getIsvRoutePermissionManager(); - } - - @Bean - RouteConfigManager routeConfigManager() { - return ApiConfig.getInstance().getRouteConfigManager(); - } }