From 996c72736eddf6452acaa77d22c9b593b7b99e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Pro=C3=9F?= Date: Wed, 8 Dec 2021 10:47:28 +0100 Subject: [PATCH] Catch NPE --- .../basic/filter/spatial/BBOXTests.java | 23 +++++++++++++++---- .../basic/filter/spatial/IntersectsTests.java | 16 ++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opengis/cite/iso19142/basic/filter/spatial/BBOXTests.java b/src/main/java/org/opengis/cite/iso19142/basic/filter/spatial/BBOXTests.java index a83c4002..a339df99 100644 --- a/src/main/java/org/opengis/cite/iso19142/basic/filter/spatial/BBOXTests.java +++ b/src/main/java/org/opengis/cite/iso19142/basic/filter/spatial/BBOXTests.java @@ -86,7 +86,12 @@ public void nonSpecificBBOX(ProtocolBinding binding, QName featureType) { throw new SkipException("Feature type has no geometry properties: " + featureType); } Envelope extent = this.dataSampler.getSpatialExtent(getModel(), featureType); - Document gmlEnv = envelopeAsGML(extent); + Document gmlEnv = null; + try { + gmlEnv = envelopeAsGML(extent); + } catch (Exception e) { + throw new RuntimeException("Could not create envelope for feature type: " + featureType); + } WFSMessage.appendSimpleQuery(this.reqEntity, featureType); addBBOXPredicate(this.reqEntity, gmlEnv.getDocumentElement(), null); URI endpoint = ServiceMetadataUtils.getOperationEndpoint(this.wfsMetadata, WFS2.GET_FEATURE, binding); @@ -141,7 +146,12 @@ public void bboxWithDefaultExtent(ProtocolBinding binding, QName featureType) { Element valueRef = WFSMessage.createValueReference(geomProp); WFSMessage.appendSimpleQuery(this.reqEntity, featureType); Envelope extent = this.dataSampler.getSpatialExtent(getModel(), featureType); - Document gmlEnv = envelopeAsGML(extent); + Document gmlEnv = null; + try { + gmlEnv = envelopeAsGML(extent); + } catch (Exception e) { + throw new RuntimeException("Could not create envelope for feature type: " + featureType); + } addBBOXPredicate(this.reqEntity, gmlEnv.getDocumentElement(), valueRef); ClientResponse rsp = wfsClient.submitRequest(reqEntity, binding); this.rspEntity = extractBodyAsDocument(rsp); @@ -215,8 +225,13 @@ public void invalidGeometryOperand(QName featureType) { XSElementDeclaration gmlDesc = getModel().getElementDeclaration("description", Namespaces.GML); Element valueRef = WFSMessage.createValueReference(gmlDesc); WFSMessage.appendSimpleQuery(this.reqEntity, featureType); - Envelope spatialExtent = featureInfo.get(featureType).getSpatialExtent(); - Document gmlEnv = envelopeAsGML(spatialExtent); + Envelope extent = this.dataSampler.getSpatialExtent(getModel(), featureType); + Document gmlEnv = null; + try { + gmlEnv = envelopeAsGML(extent); + } catch (Exception e) { + throw new RuntimeException("Could not create envelope for feature type: " + featureType); + } addBBOXPredicate(this.reqEntity, gmlEnv.getDocumentElement(), valueRef); ClientResponse rsp = wfsClient.submitRequest(reqEntity, ProtocolBinding.ANY); this.rspEntity = rsp.getEntity(Document.class); diff --git a/src/main/java/org/opengis/cite/iso19142/basic/filter/spatial/IntersectsTests.java b/src/main/java/org/opengis/cite/iso19142/basic/filter/spatial/IntersectsTests.java index 20f5f126..f07161e7 100644 --- a/src/main/java/org/opengis/cite/iso19142/basic/filter/spatial/IntersectsTests.java +++ b/src/main/java/org/opengis/cite/iso19142/basic/filter/spatial/IntersectsTests.java @@ -141,7 +141,12 @@ public void intersectsPolygon(ProtocolBinding binding, QName featureType) throws throw new SkipException("Unsupported geometry operand: " + gmlPolygon); } Envelope extent = this.dataSampler.getSpatialExtent(getModel(), featureType); - Document gmlEnv = Extents.envelopeAsGML(extent); + Document gmlEnv = null; + try { + gmlEnv = Extents.envelopeAsGML(extent); + } catch (Exception e) { + throw new RuntimeException("Could not create envelope for feature type: " + featureType); + } Element gmlPolygonElem = XMLUtils .transform(new StreamSource(getClass().getResourceAsStream(XSLT_ENV2POLYGON)), gmlEnv, null) .getDocumentElement(); @@ -191,9 +196,14 @@ public void intersectsCurve(ProtocolBinding binding, QName featureType) throws X } } Envelope extent = this.dataSampler.getSpatialExtent(getModel(), featureType); - Document gmlEnvelope = Extents.envelopeAsGML(extent); + Document gmlEnv = null; + try { + gmlEnv = Extents.envelopeAsGML(extent); + } catch (Exception e) { + throw new RuntimeException("Could not create envelope for feature type: " + featureType); + } Element gmlCurveElem = XMLUtils - .transform(new StreamSource(getClass().getResourceAsStream("envelopeTocurve.xsl")), gmlEnvelope, + .transform(new StreamSource(getClass().getResourceAsStream("envelopeTocurve.xsl")), gmlEnv, Collections.singletonMap("curveType", gmlCurve.getLocalPart())) .getDocumentElement(); List geomProps = this.allGeomProperties.get(featureType);