pull/1/MERGE
tanghc 5 years ago
parent f6ec1a6654
commit 3a6ea57226
  1. 6
      sop-common/sop-bridge-zuul/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java
  2. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java
  3. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.java
  4. 20
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/controller/ZuulErrorController.java

@ -1,6 +1,8 @@
package com.gitee.sop.bridge;
import com.gitee.sop.gatewaycommon.zuul.configuration.AlipayZuulConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@ -12,6 +14,10 @@ import org.springframework.context.annotation.Import;
@Configuration
@EnableZuulProxy
@Import(AlipayZuulConfiguration.class)
// 在ErrorMvcAutoConfiguration之前加载
// 如果不加会出现basicErrorController和zuulErrorController冲突
// zuulErrorController是SOP中的,提前加载后basicErrorController就不会加载
@AutoConfigureBefore({ErrorMvcAutoConfiguration.class})
public class SopGatewayAutoConfiguration {
}

@ -35,7 +35,7 @@ import com.gitee.sop.gatewaycommon.validate.Encrypter;
import com.gitee.sop.gatewaycommon.validate.Signer;
import com.gitee.sop.gatewaycommon.validate.TokenValidator;
import com.gitee.sop.gatewaycommon.validate.Validator;
import com.gitee.sop.gatewaycommon.zuul.configuration.ZuulErrorController;
import com.gitee.sop.gatewaycommon.zuul.controller.ZuulErrorController;
import com.gitee.sop.gatewaycommon.zuul.param.ZuulParamBuilder;
import com.gitee.sop.gatewaycommon.zuul.result.ZuulResultExecutor;
import com.netflix.zuul.context.RequestContext;

@ -8,6 +8,7 @@ import com.gitee.sop.gatewaycommon.param.ParamBuilder;
import com.gitee.sop.gatewaycommon.zuul.ValidateService;
import com.gitee.sop.gatewaycommon.zuul.controller.ConfigChannelController;
import com.gitee.sop.gatewaycommon.zuul.controller.ErrorLogController;
import com.gitee.sop.gatewaycommon.zuul.controller.ZuulErrorController;
import com.gitee.sop.gatewaycommon.zuul.controller.ZuulIndexController;
import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.FormBodyWrapperFilterExt;
@ -166,7 +167,7 @@ public class BaseZuulConfiguration extends AbstractConfiguration {
* 统一错误处理
*/
@Bean
ZuulErrorController sopZuulController() {
ZuulErrorController zuulErrorController() {
return ApiContext.getApiConfig().getZuulErrorController();
}

@ -1,31 +1,31 @@
package com.gitee.sop.gatewaycommon.zuul.configuration;
package com.gitee.sop.gatewaycommon.zuul.controller;
import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.result.ResultExecutor;
import com.gitee.sop.gatewaycommon.zuul.ZuulContext;
import com.netflix.zuul.context.RequestContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 处理网关自身异常
* zuul的异常处理
*
* @author tanghc
*/
@ControllerAdvice
@Slf4j
public class ZuulErrorController {
@RestController
public class ZuulErrorController implements ErrorController {
/**
* 错误最终会到这里来
*/
@ExceptionHandler(Exception.class)
@ResponseBody
@RequestMapping("/error")
public Object error(HttpServletRequest request, HttpServletResponse response) {
RequestContext ctx = RequestContext.getCurrentContext();
if (ctx.getResponse() == null) {
@ -45,4 +45,8 @@ public class ZuulErrorController {
return resultExecutor.buildErrorResult(RequestContext.getCurrentContext(), throwable);
}
@Override
public String getErrorPath() {
return "/error";
}
}
Loading…
Cancel
Save