From e16f5fdfbc1c49f4c519f05b190e96e497253b51 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 13 十一月 2024 17:32:14 +0800
Subject: [PATCH] 1

---
 src/main/java/com/moon/server/helper/HttpHelper.java |   40 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/moon/server/helper/HttpHelper.java b/src/main/java/com/moon/server/helper/HttpHelper.java
index 6d621d0..1c02ea0 100644
--- a/src/main/java/com/moon/server/helper/HttpHelper.java
+++ b/src/main/java/com/moon/server/helper/HttpHelper.java
@@ -69,7 +69,6 @@
 
         CloseableHttpClient client = null;
         HttpResponse proxyResponse = null;
-
         try {
             client = this.createHttpClient();
             proxyResponse = client.execute(host, proxyRequest);
@@ -159,7 +158,6 @@
 
     protected String getRealCookie(String cookieValue) {
         StringBuilder escapedCookie = new StringBuilder();
-
         String[] cookies = cookieValue.split("[;,]");
         for (String cookie : cookies) {
             String[] cookieSplit = cookie.split("=");
@@ -272,6 +270,10 @@
         if (null == entity) {
             return;
         }
+        if (null == res) {
+            entity.writeTo(response.getOutputStream());
+            return;
+        }
 
         switch (res.getCategory()) {
             case 2:
@@ -287,11 +289,39 @@
     }
 
     private void copeGeoService(HttpResponse proxyResponse, HttpServletRequest request, HttpServletResponse response, ResEntity res) throws IOException {
-        if (StaticData.GET_CAPABILITIES.equals(request.getParameter(StaticData.REQUEST))) {
-            //
+        if (!StaticData.GET_CAPABILITIES.equals(res.getBak())) {
+            proxyResponse.getEntity().writeTo(response.getOutputStream());
+            return;
         }
 
-        proxyResponse.getEntity().writeTo(response.getOutputStream());
+        String str = EntityUtils.toString(proxyResponse.getEntity(), "UTF-8");
+        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);
+
+        int index = str.indexOf(StaticData.QUERYABLE);
+        while (index > -1) {
+            int end = str.indexOf("</Layer>", index) + StaticData.I8;
+            int nameStart = str.indexOf("<Name>", index);
+            int nameEnd = str.indexOf("</Name>", nameStart);
+
+            String name = ":" + str.substring(nameStart + StaticData.I6, nameEnd);
+            int idx = res.getTab().indexOf(name);
+            if (idx > -1) {
+                int preIdx = res.getTab().lastIndexOf(",", idx) + 1;
+                String prefix = res.getTab().substring(preIdx, idx);
+                str = str.substring(0, nameStart + StaticData.I6) + prefix + name + str.substring(nameEnd);
+                index = str.indexOf(StaticData.QUERYABLE, end);
+            } else {
+                end = str.indexOf("<", end);
+                str = str.substring(0, index) + str.substring(end);
+                index = str.indexOf(StaticData.QUERYABLE, index);
+            }
+        }
+
+        byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
+        response.setContentLength(bytes.length);
+        response.getOutputStream().write(bytes);
     }
 
     private void copeSjService(HttpResponse proxyResponse, HttpServletRequest request, HttpServletResponse response, ResEntity res) throws IOException {

--
Gitblit v1.9.3