|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|