mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
2.5.10
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-gateway-common</artifactId>
|
||||
<version>2.5.9-SNAPSHOT</version>
|
||||
<version>2.5.10-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->
|
||||
|
@@ -1,43 +1,66 @@
|
||||
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 org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 网关入口
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
public class RedirectController {
|
||||
|
||||
@Autowired
|
||||
private ValidateService validateService;
|
||||
|
||||
@Value("${zuul.servlet-path:/zuul}")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 验证回调,可自定义实现接口
|
||||
*/
|
||||
private ValidateService.ValidateCallback callback = (currentContext -> {
|
||||
try {
|
||||
currentContext.getRequest().getRequestDispatcher(path).forward(currentContext.getRequest(), currentContext.getResponse());
|
||||
} catch (Exception e) {
|
||||
log.error("请求转发异常", e);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 网关入口
|
||||
*
|
||||
* @param request request
|
||||
* @param response response
|
||||
*/
|
||||
@RequestMapping("/")
|
||||
public void index(HttpServletRequest request, HttpServletResponse response) {
|
||||
validateService.validate(request, response, callback);
|
||||
}
|
||||
|
||||
@RequestMapping("/{method}/{version}/")
|
||||
public void redirect(
|
||||
@PathVariable("method") String method
|
||||
, @PathVariable("version") String version
|
||||
, HttpServletRequest request
|
||||
, HttpServletResponse response
|
||||
) throws ServletException, IOException {
|
||||
) {
|
||||
request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, method);
|
||||
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version);
|
||||
request.getRequestDispatcher(path).forward(request, response);
|
||||
validateService.validate(request, response, callback);
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public void index(
|
||||
HttpServletRequest request
|
||||
, HttpServletResponse response
|
||||
) throws ServletException, IOException {
|
||||
request.getRequestDispatcher(path).forward(request, response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package com.gitee.sop.gateway.controller;
|
||||
|
||||
import com.gitee.sop.gatewaycommon.bean.SopConstants;
|
||||
import com.gitee.sop.gatewaycommon.param.ParamNames;
|
||||
import com.gitee.sop.gatewaycommon.util.RouteUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
Reference in New Issue
Block a user