main
黄海 10 months ago
parent 8019eb2a10
commit 5cfc2c1a49

@ -1,7 +1,5 @@
package com.dsideal.gw.Bean;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
@ -17,26 +15,17 @@ public class RetBean {
*/
private int code;
private String msg;
private Object data;
public static final Integer SUCCESS = 200;
public static final Integer ERROR = 500;
public static final Integer OVERDUE = 401;
public static final Integer TIMEOUT = 30000;
public RetBean(int code, String msg, JSONObject data) {
public RetBean(int code, String msg) {
this.code = code;
this.msg = msg;
if (data.getJSONArray("data") != null) {
this.data = data.getJSONArray("data");
} else {
this.data = data;
}
}
public String toJsonString() {
return JSONObject.toJSONString(this);
public String toString() {
return "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
}
}

@ -1,6 +1,5 @@
package com.dsideal.gw.Handler;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.gw.Bean.RetBean;
import com.dsideal.gw.GwApplication;
import com.dsideal.gw.Util.CommonUtil;
@ -39,32 +38,14 @@ public class RouterHandler extends Handler {
* JSON
*
* @param res
* @param jo
*/
public void renderJson(HttpServletResponse res, JSONObject jo) {
public void renderJson(HttpServletResponse res, String body) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Cache-Control", "no-cache");
res.setCharacterEncoding("UTF-8");
res.setContentType("application/json");
try {
RetBean ret;
String msg = "";
if (jo.containsKey("msg")) {
msg = jo.getString("msg");
jo.remove("msg");
} else if (jo.containsKey("message")) {
msg = jo.getString("message");
jo.remove("message");
}
if (jo.getBoolean("success")) {
jo.remove("success");
ret = new RetBean(RetBean.SUCCESS, msg, jo);
} else {
jo.remove("success");
ret = new RetBean(RetBean.ERROR, msg, jo);
}
res.getWriter().println(ret.toJsonString());
res.getWriter().println(body);
res.getWriter().flush();
} catch (IOException e) {
throw new RuntimeException(e);
@ -79,13 +60,9 @@ public class RouterHandler extends Handler {
if (response.body() != null) {
responseBody = response.body().string();
}
JSONObject jo = JSONObject.parseObject(responseBody);
renderJson(res, jo);
renderJson(res, responseBody);
} else {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "请求失败!");
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, "请求失败!").toString());
}
}
@ -166,10 +143,7 @@ public class RouterHandler extends Handler {
}
}
if (!canPass) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "登录已过期,请重新登录!");
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, "登录已过期,请重新登录!").toString());
isHandled[0] = true; //停止filter
return;
}
@ -182,20 +156,14 @@ public class RouterHandler extends Handler {
//action名称
String action = servletPath.substring(xie2 + 1);
if (xie1 == -1 || xie2 == -1) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "输入的字符串格式不正确,没有找到两个 '/'。");
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, "输入的字符串格式不正确,没有找到两个 '/'。").toString());
isHandled[0] = true; //停止filter
return;
}
String prefix = servletPath.substring(xie1 + 1, xie2); // 截取两个 '/' 之间的内容
if (!GwApplication.routeList.containsKey(prefix)) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", prefix + "前缀没有找到合适的路由表,请检查是否请求正确!");
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, prefix + "前缀没有找到合适的路由表,请检查是否请求正确!").toString());
isHandled[0] = true; //停止filter
return;
}
@ -209,10 +177,7 @@ public class RouterHandler extends Handler {
MultipartRequest mp = new MultipartRequest(req);
List<UploadFile> files = mp.getFiles();
if (files.isEmpty()) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "没有上传文件!");
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, "没有上传文件!").toString());
isHandled[0] = true;//停止filter
return;
}
@ -235,10 +200,7 @@ public class RouterHandler extends Handler {
isHandled[0] = true;//停止filter
return;
} catch (Exception e) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "请求失败!" + e);
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, "请求失败!" + e).toString());
isHandled[0] = true;//停止filter
return;
}
@ -263,10 +225,7 @@ public class RouterHandler extends Handler {
isHandled[0] = true;//停止filter
return;
} catch (IOException e) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "请求失败!" + e);
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, "请求失败!" + e).toString());
isHandled[0] = true;//停止filter
return;
}
@ -292,20 +251,14 @@ public class RouterHandler extends Handler {
isHandled[0] = true;//停止filter
return;
} catch (IOException e) {
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "请求失败!" + e);
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, "请求失败!" + e).toString());
isHandled[0] = true;//停止filter
return;
}
}
//4、其它的OPTIONS
JSONObject jo = new JSONObject();
jo.put("success", false);
jo.put("message", "系统只支持GET,POST其它的OPTIONS不支持文件上传请使用S3协议进行直传不通过JAVA处理JAVA只处理授权");
renderJson(res, jo);
renderJson(res, new RetBean(RetBean.ERROR, "系统只支持GET,POST其它的OPTIONS不支持文件上传请使用S3协议进行直传不通过JAVA处理JAVA只处理授权").toString());
//停止filter
isHandled[0] = true;
}

@ -18,6 +18,10 @@ public class BaseController extends Controller {
Kv kv = Kv.create();
kv.set("success", true);
kv.set("data", list);
kv.set("pageNum", 1);
kv.set("pageSize", 10);
kv.set("pageNum", list.size());
kv.set("data",list);
renderJson(kv);
}
}

@ -0,0 +1,19 @@
#!/bin/bash
# 容器名称
CONTAINER_NAME=dsRes
# 登录镜像仓库
docker login --username=东师黄海 registry.cn-hangzhou.aliyuncs.com --password DsideaL4r5t6y7u
# 镜像名称
IMAGE_NAME=registry.cn-hangzhou.aliyuncs.com/dsideal/ds_base:dev_20240924140624
# 删除容器
docker rm -f ${CONTAINER_NAME}
# 运行容器
docker run -d --network=host --name "${CONTAINER_NAME}" \
--privileged=true --env WORKING_ENV=dev -w /home -p 8002:8002 -v "$PWD/logs:/home/logs" --restart=always "${IMAGE_NAME}"
# 查看日志
docker logs -f --tail 500 "${CONTAINER_NAME}"
Loading…
Cancel
Save