I have a servlet that executes GetFeatureInfo requests to a WMS with
responses in GML format; the response is then converted to a html
table and sent to the browser.

It appears that each time a GML response is parsed the stack grows
with quite a number of com.vividsolutions.jts.geom.Coordinate
instances slowly eating up memory. Before I start digging I'm
wondering if there's something obvious I missed?

Essentially the code is:

//Parse the gml input stream into a feature collection

  private static String convertGML(final InputStream gmlStream, final
LayerDescriptor layer) throws IOException {
    try {
      final GML gml = new GML(Version.WFS1_0);
      return featureCollectionConverter(
          gml.decodeFeatureCollection(gmlStream), layer);
    } catch (ParserConfigurationException | SAXException e) {
      LOGGER.error("Fout tijdens parsen van GML. ", e);
      return "";
    } finally {
      gmlStream.close();
    }

  }

//To create a table of features with specified attributes

  private static String featureCollectionConverter(final
SimpleFeatureCollection features, final LayerDescriptor layer) {

    final StringBuilder sb = new StringBuilder();
    final String[] fieldNames = layer.getAttributes().split(",\\s*");

    if (features != null && features.size() > 0) {
// start table
      sb.append("<table id=\"attribuutTabel\" class=\"attribuutTabel\">");
      sb.append("<caption>");
      sb.append(RESOURCES.getString("KEY_INFO_TABEL_CAPTION"));
      sb.append("</caption><thead><tr>");
      for (final String n : fieldNames) {
        sb.append("<th scope=\"col\">");
        sb.append(NAMESFILTER.filterValue(n, layer.getId()));
        sb.append("</th>");
      }
      sb.append("</tr></thead><tbody>");

// iterate features
      int i = 0;
      SimpleFeatureIterator iter = features.features();
      while (iter.hasNext()) {
        sb.append("<tr class=\"")
            .append(((i++ % 2) == 0) ? "odd" : "even")
            .append("\">");
        final SimpleFeature f = iter.next();
        for (final String n : fieldNames) {
          if (VALUESFILTER.hasFilters()) {
            sb.append("<td>")
                .append(VALUESFILTER.filterValue(f.getAttribute(n)))
                .append("</td>");
          } else {
            sb.append("<td>")
                .append(f.getAttribute(n))
                .append("</td>");
          }
        }
        sb.append("</tr>");
      }
      sb.append("</tbody></table>");
      iter.close();
      iter = null;

      LOGGER.debug("Gemaakte HTML tabel: " + sb);
      return sb.toString();
    } else {
      LOGGER.debug("Geen attribuut info voor deze locatie/zoomnivo.");
      return RESOURCES.getString("KEY_INFO_GEEN_FEATURES");
    }
  }

The full code lives at:
https://github.com/MinELenI/CBSviewer/blob/master/src/main/java/nl/mineleni/cbsviewer/servlet/wms/FeatureInfoResponseConverter.java


btw. this is with Geotools v11.0

-- 
Disclaimer;
This message is just a reflection of what I thought at the time of
sending. The message may contain information that is not intended for
you or that you don't understand.

------------------------------------------------------------------------------
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to