Skip to content

Commit

Permalink
Merge pull request #982 from ZakarFin/error-handling
Browse files Browse the repository at this point in the history
Add error handling for WFS-services
  • Loading branch information
ZakarFin authored Aug 15, 2023
2 parents ce4bb68 + e4c2179 commit 2072878
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ private Map<String, Object> getControlData (LayerCapabilitiesWFS caps, WFSLayerA
if (styleType == null) {
String geomName = caps.getGeometryField();
FeaturePropertyType fpt = caps.getFeatureProperty(geomName);
styleType = WFSConversionHelper.getStyleType(fpt.type);
if (fpt != null) {
styleType = WFSConversionHelper.getStyleType(fpt.type);
}
}
data.put(WFSLayerAttributes.KEY_STYLE_TYPE, styleType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void setSupportedCrsURIs(Set<String> uris) {

@JsonIgnore
public FeaturePropertyType getFeatureProperty(String name) {
if (name == null) {
return null;
}
return getFeatureProperties().stream().filter(p -> name.equals(p.name)).findFirst().orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ protected static SimpleFeatureCollection getFeatures(String endPoint,
url = IOHelper.constructUrl(endPoint, query);
responseHeaders = OskariWFSClient.readResponseTo(endPoint, user, pass, query, baos);
response = baos.toByteArray();
if (response.length == 0) {
throw new ServiceRuntimeException("Empty response from " + url);
}
// TODO: Select parsing algorithm based on response headers (Content-Type)
fc = parseGeoJSON(response, crs, url);
if (fc != null) {
Expand All @@ -105,6 +108,9 @@ protected static SimpleFeatureCollection getFeatures(String endPoint,
baos.reset();
responseHeaders = OskariWFSClient.readResponseTo(endPoint, user, pass, query, baos);
response = baos.toByteArray();
if (response.length == 0) {
throw new ServiceRuntimeException("Empty response from " + url);
}
fc = parseGML(response, crs, url, user, pass, gmlDecoder);
if (fc != null) {
return fc;
Expand Down

0 comments on commit 2072878

Please sign in to comment.