diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java index 17f4b765..9f6467fd 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java @@ -28,8 +28,11 @@ public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping imple ApiMapping apiMapping = method.getAnnotation(ApiMapping.class); ApiAbility apiAbility = OpenUtil.getAnnotationFromMethodOrClass(method, ApiAbility.class); StringValueResolver valueResolver = null; - if (apiMapping != null || apiAbility != null) { - valueResolver = isMvc ? stringValueResolverMVC : stringValueResolver; + if (apiMapping != null) { + valueResolver = stringValueResolver; + } + if (isMvc || apiAbility != null) { + valueResolver = stringValueResolverMVC; } this.setEmbeddedValueResolver(valueResolver); return super.getMappingForMethod(method, handlerType); 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 8e0caf14..c4b40318 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,19 +1,21 @@ 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 { @@ -25,20 +27,34 @@ 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) throws ServletException, IOException { + protected void doGet(HttpServletRequest request, HttpServletResponse response) { doPost(request, response); } @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + protected void doPost(HttpServletRequest request, HttpServletResponse response) { 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); - request.getRequestDispatcher(this.path).forward(request, response); + validateService.validate(request, response, callback); } } \ No newline at end of file diff --git a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java index 9f0839c1..a6034f43 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java @@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class AllInOneTest extends TestBase { String url = "http://localhost:8081"; - String appId = "2019032617262200001-"; + String appId = "2019032617262200001"; String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDr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