main
黄海 10 months ago
parent 9526218974
commit b1f8f5a7ff

@ -23,11 +23,9 @@ public class DmController extends Controller {
* 2019-02-23
*/
@Before({GET.class})
// @IsLoginInterface({})
public void getDmSchoolProperty() {
List<Record> rs = model.getDmSchoolProperty();
renderJson(CommonUtil.renderJsonForLayUI(rs));
return;
}
/**

@ -6,7 +6,7 @@ undertow.host=0.0.0.0
undertow.resourcePath =D:/dsWork/dsExam/ds-base/WebRoot,classpath:static
# 目录名称
undertow.contextPath=/dsBase
undertow.contextPath=/
# 设定I/O线程数.
server.undertow.io-threads=8

@ -1,11 +1,11 @@
# true 值支持热加载
undertow.devMode=true
undertow.port=8000
undertow.port=8001
undertow.host=0.0.0.0
undertow.resourcePath =/root/WebRoot,classpath:static
# 目录名称
undertow.contextPath=/dsBase
undertow.contextPath=/
# 设定I/O线程数.
server.undertow.io-threads=8

@ -1,6 +1,7 @@
package com.dsideal.gw.Handler;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.dsideal.gw.GwApplication;
import com.jfinal.handler.Handler;
import okhttp3.*;
@ -30,9 +31,15 @@ public class RouterHandler extends Handler {
}
}
public void renderJson(HttpServletResponse res, String msg) {
renderJson(res, new JSONObject().put("msg", msg));
}
/**
*
* GET
* http://10.10.21.20:8000/ds-base/dm/getDmSchoolProperty
* http://10.10.21.20:8000/ds-base/global/getGlobalList?page=1&limit=10
*
*
*/
//OkHttp的实例单例模式
private static final OkHttpClient OK_HTTP_CLIENT = new OkHttpClient();
@ -42,9 +49,13 @@ public class RouterHandler extends Handler {
Response response = OK_HTTP_CLIENT.newCall(request).execute();
if (response.isSuccessful()) {
String responseBody = response.body().string();
renderJson(res, responseBody);
JSONObject jo = JSONUtil.parseObj(responseBody).put("success", true).put("code", response.code());
renderJson(res, jo);
} else {
renderJson(res, "请求失败!");
JSONObject jo = new JSONObject();
jo.put("message", "请求失败!");
jo.put("code", response.code());
renderJson(res, jo);
}
}
@ -59,13 +70,19 @@ public class RouterHandler extends Handler {
int firstSlashIndex = servletPath.indexOf('/'); // 找到第一个 '/' 的索引
int secondSlashIndex = servletPath.indexOf('/', firstSlashIndex + 1); // 从第一个 '/' 之后开始找第二个 '/' 的索引
//action名称
String action = servletPath.substring(secondSlashIndex + 1);
if (firstSlashIndex != -1 && secondSlashIndex != -1) {
String prefix = servletPath.substring(firstSlashIndex + 1, secondSlashIndex); // 截取两个 '/' 之间的内容
if (!GwApplication.routeDict.containsKey(prefix)) {
renderJson(res, prefix + "前缀没有找到合适的路由表,请检查是否请求正确!");
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", prefix + "前缀没有找到合适的路由表,请检查是否请求正确!");
renderJson(res, jo);
} else {
//路由到哪个微服务
String FORWARD_URL = GwApplication.routeDict.get(prefix);
String FORWARD_URL = GwApplication.routeDict.get(prefix) + "/" + action;
//处理GET请求
if (req.getMethod().equals("GET")) {
//参数:queryString
@ -78,7 +95,10 @@ public class RouterHandler extends Handler {
try {
executeRequest(request, res);
} catch (IOException e) {
renderJson(res, "请求失败!"+ e);
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "请求失败!" + e);
renderJson(res, jo);
}
}//处理POST请求
else if (req.getMethod().equals("POST")) {
@ -87,11 +107,17 @@ public class RouterHandler extends Handler {
} else {
// MinIO - 服务端签名直传(前端 + 后端 + 效果演示)
//https://blog.csdn.net/CYK_byte/article/details/140254412
renderJson(res, "系统只支持GET,POST其它的OPTIONS不支持文件上传请使用S3协议进行直传不通过JAVA处理JAVA只处理授权");
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "系统只支持GET,POST其它的OPTIONS不支持文件上传请使用S3协议进行直传不通过JAVA处理JAVA只处理授权");
renderJson(res, jo);
}
}
} else {
renderJson(res, "输入的字符串格式不正确,没有找到两个 '/'。");
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "输入的字符串格式不正确,没有找到两个 '/'。");
renderJson(res, jo);
}
//停止filter
isHandled[0] = true;

@ -16,5 +16,5 @@ excelExportTemplatePathSuffix=/ExcelExportTemplate/
ExcelImportTemplatePathSuffix=/ExcelImportTemplate/
# 基础数据
route_dsBase= http://ds-base:8001
route_ds-base= http://ds-base:8001

@ -16,4 +16,4 @@ excelExportTemplatePathSuffix=/ExcelExportTemplate/
ExcelImportTemplatePathSuffix=/ExcelImportTemplate/
# 基础数据
route_dsBase= http://ds-base:8001
route_ds-base= http://ds-base:8001

@ -16,5 +16,5 @@ excelExportTemplatePathSuffix=/ExcelExportTemplate/
ExcelImportTemplatePathSuffix=/ExcelImportTemplate/
# 基础数据
route_dsBase= http://ds-base:8001
route_ds-base= http://ds-base:8001

@ -16,4 +16,4 @@ excelExportTemplatePathSuffix=/ExcelExportTemplate/
ExcelImportTemplatePathSuffix=/ExcelImportTemplate/
# 基础数据
route_dsBase= http://ds-base:8001
route_ds-base= http://ds-base:8001
Loading…
Cancel
Save