From 6c4fbc47abfbfc25467e2992eca3c2a9eae6b150 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 17 Mar 2023 17:37:04 +0800 Subject: [PATCH] update:nas ip update:/public/request.do add:/public/file/request.do --- .../java/com/yutou/tools/nas/UpdateIp.java | 2 +- .../java/com/yutou/tools/other/tools.java | 36 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/yutou/tools/nas/UpdateIp.java b/src/main/java/com/yutou/tools/nas/UpdateIp.java index c4fa740..9310ad9 100644 --- a/src/main/java/com/yutou/tools/nas/UpdateIp.java +++ b/src/main/java/com/yutou/tools/nas/UpdateIp.java @@ -21,7 +21,7 @@ import java.util.regex.Pattern; @Controller public class UpdateIp { private static List keys = new ArrayList<>(); - public static String nas_ip=null; + public static String nas_ip="nas.yutou233.cn"; static { if ("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) { nas_ip="192.168.31.88"; diff --git a/src/main/java/com/yutou/tools/other/tools.java b/src/main/java/com/yutou/tools/other/tools.java index 9187f86..8da9775 100644 --- a/src/main/java/com/yutou/tools/other/tools.java +++ b/src/main/java/com/yutou/tools/other/tools.java @@ -15,7 +15,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.Cookie; @@ -24,8 +26,11 @@ import javax.servlet.http.HttpServletResponse; import java.io.*; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Enumeration; import java.util.List; +import java.util.Locale; @Controller public class tools { @@ -68,7 +73,13 @@ public class tools { @SneakyThrows @ResponseBody @RequestMapping("/public/request.do") + public String testRequest(HttpServletRequest request) { + return testRequest(request, null); + } + @ResponseBody + @RequestMapping("/public/file/request.do") + public String testRequest(HttpServletRequest request, @RequestParam("file")MultipartFile file) { JSONObject params = new JSONObject(); JSONArray cookies = new JSONArray(); JSONObject header = new JSONObject(); @@ -81,14 +92,19 @@ public class tools { cookies.add(ck); } } - BufferedInputStream stream = new BufferedInputStream(request.getInputStream()); - byte[] bytes = new byte[1024]; - int len = 0, size; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - while ((len = stream.read(bytes)) != -1) { - outputStream.write(bytes, 0, len); - outputStream.flush(); + try { + BufferedInputStream stream = new BufferedInputStream(request.getInputStream()); + byte[] bytes = new byte[1024]; + int len = 0, size; + while ((len = stream.read(bytes)) != -1) { + outputStream.write(bytes, 0, len); + outputStream.flush(); + } + }catch (Exception e){ + e.printStackTrace(); } + Enumeration enumeration = request.getHeaderNames(); while (enumeration != null && enumeration.hasMoreElements()) { String tmp = enumeration.nextElement(); @@ -107,6 +123,14 @@ public class tools { json.put("header", header); System.out.println("json = " + json); // Tools.sendServer("打印请求", json.toJSONString()); + if(file!=null){ + try { + Tools.createFile("tmp",file,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date())+".zip"); + } catch (Exception e) { + e.printStackTrace(); + } + } + Tools.sendServer("打印请求", json.toJSONString()); try { switch (RedisTools.get("request")) { case "success":