| | |
| | | |
| | | CloseableHttpClient client = null; |
| | | HttpResponse proxyResponse = null; |
| | | |
| | | try { |
| | | client = this.createHttpClient(); |
| | | proxyResponse = client.execute(host, proxyRequest); |
| | |
| | | |
| | | protected String getRealCookie(String cookieValue) { |
| | | StringBuilder escapedCookie = new StringBuilder(); |
| | | |
| | | String[] cookies = cookieValue.split("[;,]"); |
| | | for (String cookie : cookies) { |
| | | String[] cookieSplit = cookie.split("="); |
| | |
| | | return; |
| | | } |
| | | |
| | | do { |
| | | if (null == res || StringHelper.isNull(res.getUrl())) { |
| | | switch (res.getCategory()) { |
| | | case 2: |
| | | copeGeoService(proxyResponse, request, response, res); |
| | | break; |
| | | case 3: |
| | | copeSjService(proxyResponse, request, response, res); |
| | | break; |
| | | default: |
| | | entity.writeTo(response.getOutputStream()); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void copeGeoService(HttpResponse proxyResponse, HttpServletRequest request, HttpServletResponse response, ResEntity res) throws IOException { |
| | | if (!StaticData.GET_CAPABILITIES.equals(res.getBak())) { |
| | | proxyResponse.getEntity().writeTo(response.getOutputStream()); |
| | | return; |
| | | } |
| | | |
| | | 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 start = str.indexOf("<Name>", index) + StaticData.I6; |
| | | int end = str.indexOf("</Layer>", index) + StaticData.I8; |
| | | |
| | | String name = ":" + str.substring(start, str.indexOf("</Name>", start)); |
| | | if (!res.getTab().contains(name)) { |
| | | end = str.indexOf("<", end); |
| | | str = str.substring(0, index) + str.substring(end); |
| | | index = str.indexOf(StaticData.QUERYABLE, index); |
| | | } else { |
| | | index = str.indexOf(StaticData.QUERYABLE, end); |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | response.getOutputStream().write(bytes); |
| | | } |
| | | |
| | | byte[] bytes = str.getBytes(StandardCharsets.UTF_8); |
| | | response.setContentLength(bytes.length); |
| | | response.getOutputStream().write(bytes); |
| | | return; |
| | | } |
| | | } while (false); |
| | | |
| | | entity.writeTo(response.getOutputStream()); |
| | | private void copeSjService(HttpResponse proxyResponse, HttpServletRequest request, HttpServletResponse response, ResEntity res) throws IOException { |
| | | 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(proxyResponse.getEntity(), "UTF-8")); |
| | | byte[] bytes = str.getBytes(StandardCharsets.UTF_8); |
| | | response.setContentLength(bytes.length); |
| | | response.getOutputStream().write(bytes); |
| | | } else { |
| | | proxyResponse.getEntity().writeTo(response.getOutputStream()); |
| | | } |
| | | } |
| | | |
| | | private String filterStr(HttpServletRequest request, HttpServletResponse response, ResEntity res, String str) { |