| | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Enumeration; |
| | | |
| | | /** |
| | | * Http帮助类 |
| | | * @author WWW |
| | | */ |
| | | @SuppressWarnings("ALL") |
| | | public class HttpHelper { |
| | | private final static String HTTP_SLASH2 = "://"; |
| | | |
| | |
| | | |
| | | protected String getRealCookie(String cookieValue) { |
| | | StringBuilder escapedCookie = new StringBuilder(); |
| | | |
| | | String[] cookies = cookieValue.split("[;,]"); |
| | | for (String cookie : cookies) { |
| | | String[] cookieSplit = cookie.split("="); |
| | |
| | | if (null == entity) { |
| | | return; |
| | | } |
| | | if (null == res) { |
| | | entity.writeTo(response.getOutputStream()); |
| | | return; |
| | | } |
| | | |
| | | switch (res.getCategory()) { |
| | | case 2: |
| | |
| | | } |
| | | |
| | | private void copeGeoService(HttpResponse proxyResponse, HttpServletRequest request, HttpServletResponse response, ResEntity res) throws IOException { |
| | | if (StaticData.GET_CAPABILITIES.equals(res.getBak())) { |
| | | // |
| | | 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 { |