private T requestInfo(URI baseUrl, RenderingContext context)
      throws IOException, URISyntaxException, ParserConfigurationException, SAXException {
    URL url = loader.createURL(baseUrl, context);

    GetMethod method = null;
    try {
      final InputStream stream;

      if ((url.getProtocol().equals("http") || url.getProtocol().equals("https"))
          && context.getConfig().localHostForwardIsFrom(url.getHost())) {
        String scheme = url.getProtocol();
        final String host = url.getHost();
        if (url.getProtocol().equals("https")
            && context.getConfig().localHostForwardIsHttps2http()) {
          scheme = "http";
        }
        URL localUrl = new URL(scheme, "localhost", url.getPort(), url.getFile());
        HttpURLConnection connexion = (HttpURLConnection) localUrl.openConnection();
        connexion.setRequestProperty("Host", host);
        for (Map.Entry<String, String> entry : context.getHeaders().entrySet()) {
          connexion.setRequestProperty(entry.getKey(), entry.getValue());
        }
        stream = connexion.getInputStream();
      } else {
        method = new GetMethod(url.toString());
        for (Map.Entry<String, String> entry : context.getHeaders().entrySet()) {
          method.setRequestHeader(entry.getKey(), entry.getValue());
        }
        context.getConfig().getHttpClient(baseUrl).executeMethod(method);
        int code = method.getStatusCode();
        if (code < 200 || code >= 300) {
          throw new IOException(
              "Error "
                  + code
                  + " while reading the Capabilities from "
                  + url
                  + ": "
                  + method.getStatusText());
        }
        stream = method.getResponseBodyAsStream();
      }
      final T result;
      try {
        result = loader.parseInfo(stream);
      } finally {
        stream.close();
      }
      return result;
    } finally {
      if (method != null) {
        method.releaseConnection();
      }
    }
  }
Ejemplo n.º 2
0
  protected static void create(
      List<MapReader> target, RenderingContext context, PJsonObject params) {
    String map = params.getString("map");
    String group = params.getString("group");
    int metaTileWidth = params.getInt("metaTileWidth");
    int metaTileHeight = params.getInt("metaTileHeight");
    String units = context.getGlobalParams().getString("units");

    target.add(
        new KaMapCacheMapReader(map, group, units, metaTileWidth, metaTileHeight, context, params));
  }
Ejemplo n.º 3
0
  private static WMSServerInfo requestInfo(URI baseUrl, RenderingContext context)
      throws IOException, URISyntaxException, ParserConfigurationException, SAXException {
    Map<String, List<String>> queryParams = new HashMap<String, List<String>>();
    URIUtils.addParamOverride(queryParams, "SERVICE", "WMS");
    URIUtils.addParamOverride(queryParams, "REQUEST", "GetCapabilities");
    URIUtils.addParamOverride(queryParams, "VERSION", "1.1.1");
    URL url = URIUtils.addParams(baseUrl, queryParams, HTTPMapReader.OVERRIDE_ALL).toURL();

    GetMethod method = new GetMethod(url.toString());
    if (context.getReferer() != null) {
      method.setRequestHeader("Referer", context.getReferer());
    }
    try {
      context.getConfig().getHttpClient(baseUrl).executeMethod(method);
      int code = method.getStatusCode();
      if (code < 200 || code >= 300) {
        throw new IOException(
            "Error "
                + code
                + " while reading the Capabilities from "
                + url
                + ": "
                + method.getStatusText());
      }
      InputStream stream = method.getResponseBodyAsStream();
      final WMSServerInfo result;
      try {
        result = parseCapabilities(stream);
      } finally {
        stream.close();
      }
      return result;
    } finally {
      method.releaseConnection();
    }
  }