修复cloud gateway调用异常

This commit is contained in:
tanghc
2019-05-13 12:27:23 +08:00
parent 837fa3ee86
commit 502f541ba8
4 changed files with 27 additions and 21 deletions

View File

@@ -30,6 +30,11 @@ import java.util.List;
*/ */
public class BaseGatewayConfiguration extends AbstractConfiguration { public class BaseGatewayConfiguration extends AbstractConfiguration {
public static boolean USE_GATEWAY;
static {
USE_GATEWAY = true;
}
/** /**
* 自定义异常处理[@@]注册Bean时依赖的Bean会从容器中直接获取所以直接注入即可 * 自定义异常处理[@@]注册Bean时依赖的Bean会从容器中直接获取所以直接注入即可
* *

View File

@@ -1,8 +1,10 @@
package com.gitee.sop.gatewaycommon.manager; 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.ApiContext;
import com.gitee.sop.gatewaycommon.bean.BeanInitializer; import com.gitee.sop.gatewaycommon.bean.BeanInitializer;
import com.gitee.sop.gatewaycommon.message.ErrorFactory; import com.gitee.sop.gatewaycommon.message.ErrorFactory;
import com.gitee.sop.gatewaycommon.secret.IsvManager;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@@ -32,6 +34,21 @@ public class AbstractConfiguration implements ApplicationContextAware {
applicationContext = ctx; 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 @Bean
public CorsFilter corsFilter() { public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); return createCorsFilter();
source.registerCorsConfiguration("/**", corsConfiguration());
return new CorsFilter(source);
} }
protected CorsFilter createCorsFilter() { protected CorsFilter createCorsFilter() {

View File

@@ -1,6 +1,7 @@
package com.gitee.sop.gatewaycommon.message; package com.gitee.sop.gatewaycommon.message;
import com.gitee.sop.gatewaycommon.exception.ApiException; import com.gitee.sop.gatewaycommon.exception.ApiException;
import com.gitee.sop.gatewaycommon.gateway.configuration.BaseGatewayConfiguration;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import lombok.Getter; import lombok.Getter;
@@ -54,6 +55,9 @@ public class ErrorMeta {
} }
protected Locale getLocale() { protected Locale getLocale() {
if (BaseGatewayConfiguration.USE_GATEWAY) {
return ZH_CN;
}
RequestContext currentContext = RequestContext.getCurrentContext(); RequestContext currentContext = RequestContext.getCurrentContext();
if (currentContext == null) { if (currentContext == null) {
return ZH_CN; return ZH_CN;

View File

@@ -1,12 +1,8 @@
package com.gitee.sop.gatewaycommon.zuul.configuration; 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.bean.ApiContext;
import com.gitee.sop.gatewaycommon.manager.AbstractConfiguration; 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.manager.RouteRepositoryContext;
import com.gitee.sop.gatewaycommon.secret.IsvManager;
import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter; import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.PostResultFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PostResultFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.PreLimitFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PreLimitFilter;
@@ -120,18 +116,4 @@ public class BaseZuulConfiguration extends AbstractConfiguration {
return ApiContext.getApiConfig().getZuulErrorController(); 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();
}
} }