修复cloud gateway调用异常

1.x
tanghc 6 years ago
parent 837fa3ee86
commit 502f541ba8
  1. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java
  2. 21
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java
  3. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java
  4. 18
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.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会从容器中直接获取所以直接注入即可
*

@ -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() {

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

@ -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();
}
}

Loading…
Cancel
Save