| | |
| | | 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; |
| | |
| | | return; |
| | | } |
| | | |
| | | OutputStream outputStream = response.getOutputStream(); |
| | | do { |
| | | if (null == res || StringHelper.isNull(res.getUrl())) { |
| | | break; |
| | | } |
| | | |
| | | Header[] headers = proxyResponse.getHeaders("content-type"); |
| | | if (null != headers && headers.length > 0 && headers[0].getValue().contains(StaticData.TEXT_XML)) { |
| | | String str = filterStr(request, response, res, EntityUtils.toString(entity, "UTF-8")); |
| | | Header[] headers = proxyResponse.getHeaders("content-type"); |
| | | if (null != headers && headers.length > 0 && headers[0].getValue().contains(StaticData.TEXT_XML)) { |
| | | String str = filterStr(request, response, res, EntityUtils.toString(entity, "UTF-8")); |
| | | |
| | | byte[] bytes = str.getBytes(StandardCharsets.UTF_8); |
| | | response.setContentLength(bytes.length); |
| | | outputStream.write(bytes); |
| | | return; |
| | | } |
| | | byte[] bytes = str.getBytes(StandardCharsets.UTF_8); |
| | | response.setContentLength(bytes.length); |
| | | response.getOutputStream().write(bytes); |
| | | return; |
| | | } |
| | | } while (false); |
| | | |
| | | entity.writeTo(outputStream); |
| | | entity.writeTo(response.getOutputStream()); |
| | | } |
| | | |
| | | 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]; |
| | | |
| | | 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 (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; |