diff --git a/io/plugins/eu.esdihumboldt.hale.io.gml/src/eu/esdihumboldt/hale/io/gml/reader/internal/wfs/WfsBackedGmlInstanceCollection.java b/io/plugins/eu.esdihumboldt.hale.io.gml/src/eu/esdihumboldt/hale/io/gml/reader/internal/wfs/WfsBackedGmlInstanceCollection.java index 90a00d58af..df1c6c7d3e 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.gml/src/eu/esdihumboldt/hale/io/gml/reader/internal/wfs/WfsBackedGmlInstanceCollection.java +++ b/io/plugins/eu.esdihumboldt.hale.io.gml/src/eu/esdihumboldt/hale/io/gml/reader/internal/wfs/WfsBackedGmlInstanceCollection.java @@ -42,6 +42,7 @@ import eu.esdihumboldt.hale.common.instance.model.InstanceCollection; import eu.esdihumboldt.hale.common.instance.model.InstanceReference; import eu.esdihumboldt.hale.common.instance.model.InstanceResolver; +import eu.esdihumboldt.hale.common.instance.model.ResourceIterator; import eu.esdihumboldt.hale.common.instance.model.ext.InstanceIterator; import eu.esdihumboldt.hale.common.instance.model.impl.FilteredInstanceCollection; import eu.esdihumboldt.hale.common.instance.model.impl.IndexInstanceReference; @@ -101,7 +102,8 @@ public class WfsBackedGmlInstanceCollection implements InstanceCollection { // Number of features to retrieve at most with one WFS GetFeature request private final int featuresPerRequest; - private final int size; + private boolean emptyInitialized = false; + private boolean empty = false; // Parameters needed for instantiation of GmlInstanceCollection private final TypeIndex sourceSchema; @@ -225,41 +227,6 @@ public WfsBackedGmlInstanceCollection(LocatableInputSupplier it = iterator(); + try { + empty = !it.hasNext(); + } finally { + it.close(); + } + + emptyInitialized = true; + } + + return empty; } /** @@ -372,21 +350,6 @@ public Instance getInstance(InstanceReference reference) { } } - private int requestHits(URI requestUri) throws WFSException { - URIBuilder builder = new URIBuilder(requestUri); - builder.addParameter("RESULTTYPE", "hits"); - - InputStream in; - try { - in = builder.build().toURL().openStream(); - } catch (IOException | URISyntaxException e) { - throw new WFSException( - MessageFormat.format("Unable to execute WFS request: {0}", e.getMessage()), e); - } - - return FeatureCollectionHelper.getNumberOfFeatures(in); - } - private String getMaxFeaturesParameterName(String version) { // XXX Use WFSVersion switch (version) { @@ -556,9 +519,8 @@ public boolean hasNext() { * number of results reported by the WFS. */ protected boolean isFeatureLimitReached() { - return (maxNumberOfFeatures != UNLIMITED - && totalFeaturesProcessed >= maxNumberOfFeatures) - || (size != UNKNOWN_SIZE && totalFeaturesProcessed >= size); + return maxNumberOfFeatures != UNLIMITED + && totalFeaturesProcessed >= maxNumberOfFeatures; } /**