From 6aeb1c17992bbefb3a4469cf8d70d1488baf87bd Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 22 七月 2023 16:04:46 +0800 Subject: [PATCH] 修改代理服务、zip解压 --- src/main/java/com/moon/server/entity/all/StaticData.java | 4 ++ src/main/java/com/moon/server/helper/ZipHelper.java | 74 +++++++++++++++++++++++++------------ src/main/java/com/moon/server/service/sys/ProxyService.java | 2 src/main/java/com/moon/server/helper/PathHelper.java | 4 +- src/main/java/com/moon/server/helper/HttpHelper.java | 8 +++- 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/moon/server/entity/all/StaticData.java b/src/main/java/com/moon/server/entity/all/StaticData.java index 6583316..3f78c89 100644 --- a/src/main/java/com/moon/server/entity/all/StaticData.java +++ b/src/main/java/com/moon/server/entity/all/StaticData.java @@ -18,6 +18,8 @@ public final static int TWO = 2; + public final static int THREE = 3; + public final static int FOUR = 4; public final static int NINE = 9; @@ -86,6 +88,8 @@ public final static String AK = "?ak="; + public final static String REST_LAYER = "/rest/layer/"; + /** * 鍗曞紩鍙� */ diff --git a/src/main/java/com/moon/server/helper/HttpHelper.java b/src/main/java/com/moon/server/helper/HttpHelper.java index 2e9abb5..635cd78 100644 --- a/src/main/java/com/moon/server/helper/HttpHelper.java +++ b/src/main/java/com/moon/server/helper/HttpHelper.java @@ -300,13 +300,17 @@ url = strs[0]; if (!StringHelper.isEmpty(strs[1])) { - str = str.replace("?" + strs[1], ""); + str = str.replace("?" + strs[1], "").replace("&" + strs[1], "").replace("&" + strs[1], ""); } } if (str.contains(url)) { String proxyUrl = res.getProxy().replace("{token}", response.getHeader("token")); proxyUrl = request.getRequestURL().substring(0, request.getRequestURL().indexOf(proxyUrl) + proxyUrl.length()); - str = str.replace(res.getUrl(), proxyUrl); + str = str.replace(url, proxyUrl); + + if (str.contains(StaticData.REST_LAYER)) { + str = str.replace(url.replace("/wmts/layer/", StaticData.REST_LAYER), proxyUrl); + } } return str; diff --git a/src/main/java/com/moon/server/helper/PathHelper.java b/src/main/java/com/moon/server/helper/PathHelper.java index 89c4c18..74c4033 100644 --- a/src/main/java/com/moon/server/helper/PathHelper.java +++ b/src/main/java/com/moon/server/helper/PathHelper.java @@ -23,7 +23,7 @@ private static int uploadPath = 1; - private final static double D80 = 80; + private final static double D90 = 90; private final static Log log = LogFactory.getLog(PathHelper.class); @@ -142,7 +142,7 @@ public void deleteOldPath(String tempPath) { try { double ran = Math.random() * 99; - if (ran < D80) { + if (ran < D90) { return; } diff --git a/src/main/java/com/moon/server/helper/ZipHelper.java b/src/main/java/com/moon/server/helper/ZipHelper.java index 9a56595..9b1ce99 100644 --- a/src/main/java/com/moon/server/helper/ZipHelper.java +++ b/src/main/java/com/moon/server/helper/ZipHelper.java @@ -36,31 +36,9 @@ dir.mkdirs(); } - int count; zipFile = new ZipFile(filePath, Charset.forName("GBK")); - Enumeration e = zipFile.entries(); - while (e.hasMoreElements()) { - ZipEntry entry = (ZipEntry) e.nextElement(); - if (entry.isDirectory()) { - File f = new File(zipDir + File.separator + entry.getName()); - if (!f.exists()) { - f.mkdirs(); - } - continue; - } - - BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry)); - FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName()); - BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE); - while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) { - dest.write(BUFFER, 0, count); - } - - dest.flush(); - dest.close(); - fos.close(); - is.close(); - } + createDirs(zipFile, zipDir); + writeFiles(zipFile, zipDir); return true; } catch (Exception ex) { @@ -78,6 +56,54 @@ } /** + * 鍒涘缓鐩綍 + */ + private static void createDirs(ZipFile zipFile, String zipDir) { + Enumeration<?> e = zipFile.entries(); + while (e.hasMoreElements()) { + ZipEntry entry = (ZipEntry) e.nextElement(); + if (entry.isDirectory()) { + File f = new File(zipDir + File.separator + entry.getName()); + if (!f.exists()) { + f.mkdirs(); + } + } + } + } + + /** + * 鍐欐枃浠� + */ + private static void writeFiles(ZipFile zipFile, String zipDir) throws IOException { + Enumeration<?> e = zipFile.entries(); + while (e.hasMoreElements()) { + ZipEntry entry = (ZipEntry) e.nextElement(); + if (!entry.isDirectory()) { + writeFile(zipFile, entry, zipDir); + } + } + } + + /** + * 鍐欐枃浠� + */ + private static void writeFile(ZipFile zipFile, ZipEntry entry, String zipDir) throws IOException { + int count; + + BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry)); + FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName()); + BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE); + while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) { + dest.write(BUFFER, 0, count); + } + + dest.flush(); + dest.close(); + fos.close(); + is.close(); + } + + /** * Zip鍘嬬缉 * * @param zipFile zip婧愭枃浠� diff --git a/src/main/java/com/moon/server/service/sys/ProxyService.java b/src/main/java/com/moon/server/service/sys/ProxyService.java index aa518a4..1b03132 100644 --- a/src/main/java/com/moon/server/service/sys/ProxyService.java +++ b/src/main/java/com/moon/server/service/sys/ProxyService.java @@ -56,7 +56,7 @@ // 9.鑾峰彇璧勬簮瀹炰綋 ResEntity entity = getResEntity(ue, resId); - if (null == entity || entity.getType() != 3|| StringHelper.isNull(entity.getProxy())||StringHelper.isNull(entity.getUrl())) { + if (null == entity || entity.getType() != StaticData.THREE || StringHelper.isNull(entity.getProxy()) || StringHelper.isNull(entity.getUrl())) { WebHelper.writeStr2Page(res, ILLEGAL_RESOURCE); return; } -- Gitblit v1.9.3