月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-07-25 604778b34a84b62208106d03f7c8dfaa28151024
src/main/java/com/moon/server/helper/HttpHelper.java
@@ -20,7 +20,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpCookie;
import java.net.URI;
import java.net.URISyntaxException;
@@ -294,7 +293,7 @@
    }
    private String filterStr(HttpServletRequest request, HttpServletResponse response, ResEntity res, String str) {
        String url = res.getUrl();
        /*String url = res.getUrl();
        if (url.contains(StaticData.AK)) {
            String[] strs = url.split("\\?");
            url = strs[0];
@@ -308,11 +307,28 @@
            proxyUrl = request.getRequestURL().substring(0, request.getRequestURL().indexOf(proxyUrl) + proxyUrl.length());
            str = str.replace(url, proxyUrl);
            if (str.contains(StaticData.REST_LAYER)) {
            if (StaticData.THREE == res.getFirm() && str.contains(StaticData.REST_LAYER)) {
                str = str.replace(url.replace("/wmts/layer/", StaticData.REST_LAYER), proxyUrl);
            }
        }
        return str;*/
        String[] strs = res.getUrl().contains(StaticData.AK) ? res.getUrl().split("\\?") : new String[]{res.getUrl(), null};
        if (str.contains(strs[0])) {
            String proxyUrl = res.getProxy().replace("{token}", response.getHeader("token"));
            proxyUrl = request.getRequestURL().substring(0, request.getRequestURL().indexOf(proxyUrl) + proxyUrl.length());
            str = str.replace(strs[0], proxyUrl);
            if (!StringHelper.isEmpty(strs[1])) {
                str = str.replace("?" + strs[1], "").replace("&" + strs[1], "");
            }
            if (StaticData.THREE == res.getFirm() && str.contains(StaticData.REST_LAYER)) {
                str = str.replace(strs[0].replace("/wmts/layer/", StaticData.REST_LAYER), proxyUrl.replace("/proxy/", "/proxy/rest/"));
            }
        }
        return str;
    }
}