mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 06:53:42 +08:00
1.13.1
This commit is contained in:
@@ -2,10 +2,13 @@ package com.gitee.sop.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
||||
|
||||
// 开启网关功能
|
||||
@EnableZuulProxy
|
||||
// 扫描自定义的servlet(类上标注@WebServle)
|
||||
@ServletComponentScan
|
||||
@SpringBootApplication
|
||||
public class SopGatewayApplication {
|
||||
|
||||
|
@@ -32,15 +32,4 @@ public class RedirectController {
|
||||
request.getRequestDispatcher(path).forward(request, response);
|
||||
}
|
||||
|
||||
@RequestMapping("/{method}")
|
||||
public void redirect2(
|
||||
@PathVariable("method") String method
|
||||
, HttpServletRequest request
|
||||
, HttpServletResponse response
|
||||
) throws ServletException, IOException {
|
||||
request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, method);
|
||||
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, "1.0");
|
||||
request.getRequestDispatcher(path).forward(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,44 @@
|
||||
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.MappingUtil;
|
||||
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;
|
||||
|
||||
@WebServlet(urlPatterns = "/rest/*")
|
||||
public class RestServlet extends HttpServlet {
|
||||
|
||||
private static final String REST_PATH = "/rest";
|
||||
|
||||
@Value("${zuul.servlet-path}")
|
||||
private String path;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doPost(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
String url = request.getRequestURL().toString();
|
||||
int index = url.indexOf(REST_PATH);
|
||||
// 取/rest的后面部分
|
||||
String path = url.substring(index + REST_PATH.length());
|
||||
String method = MappingUtil.buildApiName(path);
|
||||
String version = request.getParameter(ParamNames.VERSION_NAME);
|
||||
if (version == null) {
|
||||
version = "1.0";
|
||||
}
|
||||
request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, method);
|
||||
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version);
|
||||
request.getRequestDispatcher(this.path).forward(request, response);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user