From f3575a6add173b7c662b7bb81eb7ac2ea057f776 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 7 Jan 2020 15:07:26 +0800 Subject: [PATCH] 2.5.10 --- .../sop/gatewaycommon/bean/SopConstants.java | 2 ++ .../zuul/result/ZuulResultExecutor.java | 9 +++++++ .../sop/gateway/controller/RestServlet.java | 27 +++++-------------- 3 files changed, 17 insertions(+), 21 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 fa09436f..61fbe357 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 SOP_NOT_MERGE = "sop.not-merge"; + public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path"; public static final String METADATA_SERVER_CONTEXT_PATH_COMPATIBILITY = "context-path"; diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java index afbadd0e..9cfd0cd7 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java @@ -22,6 +22,15 @@ import java.util.Map; @Slf4j public class ZuulResultExecutor extends BaseExecutorAdapter { + @Override + protected boolean isMergeResult(RequestContext request) { + Object notMerge = request.getRequest().getAttribute(SopConstants.SOP_NOT_MERGE); + if (notMerge != null) { + return false; + } + return super.isMergeResult(request); + } + @Override public int getResponseStatus(RequestContext requestContext) { List> bizHeaders = requestContext.getZuulResponseHeaders(); diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java index c4b40318..b6baadbb 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java @@ -1,21 +1,19 @@ package com.gitee.sop.gateway.controller; import com.gitee.sop.gatewaycommon.bean.SopConstants; -import com.gitee.sop.gatewaycommon.zuul.ValidateService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * 传统web开发入口 * @author tanghc */ -@Slf4j @WebServlet(urlPatterns = "/rest/*") public class RestServlet extends HttpServlet { @@ -27,34 +25,21 @@ public class RestServlet extends HttpServlet { @Value("${sop.restful.path:/rest}") private String restPath; - @Autowired - private ValidateService validateService; - - /** - * 验证回调,可自定义实现接口 - */ - private ValidateService.ValidateCallback callback = (currentContext -> { - try { - currentContext.getRequest().getRequestDispatcher(path).forward(currentContext.getRequest(), currentContext.getResponse()); - } catch (Exception e) { - log.error("请求转发异常", e); - } - }); - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = request.getRequestURL().toString(); int index = url.indexOf(restPath); // 取/rest的后面部分 String path = url.substring(index + restPath.length()); request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, path); request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, EMPTY_VERSION); - validateService.validate(request, response, callback); + request.setAttribute(SopConstants.SOP_NOT_MERGE, true); + request.getRequestDispatcher(this.path).forward(request, response); } } \ No newline at end of file