Skip to content

Commit

Permalink
ogcapi's geo+json output formats cause NPE when request comes from WFS
Browse files Browse the repository at this point in the history
ogc-features introduce two GeoJSON output formats:
- RFCGeoJSONFeaturesResponse
- DGGSGeoJSONResponse

As such, they're listed in WFS GetCapabilities as GetFeature
operation's output formats, besides the usual 'application/json'
one.

When feature collection is requested through WFS with output
format application/geo+json, an NPE exeption is thrown once
it streamed the features and calls writeLinks(), resulting
in an XML exception report mixed up with the JSON output.

This patch checks whether APIRequestInfo.get() returns null,
which means the response being produced by these new encoders
is not coming from an ogc-api endpoint, and avoids using
APIRequestInfo to write json links.
  • Loading branch information
groldan committed Apr 29, 2022
1 parent 23a24ac commit d0872d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ String buildURI(String base, String path) {
return ResponseUtils.buildURL(baseURL, path, null, URLMangler.URLType.SERVICE);
}

/** Returns the APIRequestInfo from the current {@link RequestContextHolder} */
/**
* Returns the APIRequestInfo from the current {@link RequestContextHolder}, or {@code null}
* indicating there's no OGC API request bound to the calling thread
*/
public static APIRequestInfo get() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ private void writeLinks(
GeoJSONBuilder jw,
String featureId) {
APIRequestInfo requestInfo = APIRequestInfo.get();
if (null == requestInfo) {
// request comes from WFS, not from ogcapi
return;
}
GetFeatureRequest request = GetFeatureRequest.adapt(operation.getParameters()[0]);
FeatureTypeInfo featureType = getFeatureType(request);
String baseUrl = request.getBaseUrl();
Expand Down

0 comments on commit d0872d7

Please sign in to comment.