Sinds enige tijd maak ik, via GeoServer, gebruik van de NWB (Wegen) WFS om straatnamen op een kaart te tonen. Onlangs kwam ik er achter dat de WFS nu fouten geeft in GeoServer, om specifieker te zijn in de GeoTools library die GeoServer gebruikt. Het lijkt er op dat er iets in de service is gewijzigd omdat deze voorheen altijd heeft gewerkt.
De fout is als volgt: java.lang.ClassCastException: java.util.HashMap cannot be cast to org.opengis.feature.simple.SimpleFeature
Na wat zoeken kwam ik bij de FAQ van GeoTools (http://docs.geotools.org/latest/userguide/library/xml/faq.html) waarop het volgende staat:
Q: For WFS why does Parser return a Map? This shows up as the following error:
ClassCastException “java.util.HashMap cannot be cast to FeatureCollection”. To understand this error please remember that the GML returned by a WFS GetFeatures request is a normal XML file, with a reference to an XML schema at the top.
For a WFS GetFeature response the schema reference is usually a DescribeFeatureType call that returns an XML Schema.
If this schema is incorrectly configured (common with MapServer) or cannot be reached (common with restricted environments) our Parser will give up guessing what is a Feature and just return the values in a HashMap.
Note If you are using the GML utility class it will perform a bit of analysis and create an ad-hoc FeatureType in order to return you Features. looking at the HashMaps returned building a feature type that matches that kind of contents building features that match that FeatureType This is similar to the approach taken by OGR; OGR figures out where the “geometry” is; and then goes up two levels and assumes those things are features. Both of these approaches are strictly a work around for a common problem of misconfigured WFS servers. Here is how to review the configuration of your WFS Server:
If you are having a problem with a HashMap being returned when you expect a Feature, you should check GetCapabilities responses for remote server e.g. with browser:
http://{URL}?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetCapabilities After that, ensure that elements contain urls that actually work
In particular check that DescribeFeatureType responds with the expected XML Schema
Kan het zijn, zoals in de FAQ beschreven, dat het schema van de WFS niet juist is of iets anders in die richting?