Skip to content

Commit

Permalink
Remove HTML advertised support as it's not there, adding support for …
Browse files Browse the repository at this point in the history
…single feature requests (yet to implement the requirement of skipping collection wrapper for GeoJson
  • Loading branch information
aaime committed Mar 7, 2018
1 parent f2dd5f1 commit b83ed69
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public class APIDocument {
static {
ERROR_RESPONSE = new Response("An error occurred");
ERROR_RESPONSE.addFormat(BaseRequest.JSON_MIME, new FormatDescription().withReference(REF_EXCEPTION));
ERROR_RESPONSE.addFormat(BaseRequest.HTML_MIME, new FormatDescription().withType(TYPE_STRING));
// uncomment when HTML format is supported
// ERROR_RESPONSE.addFormat(BaseRequest.HTML_MIME, new FormatDescription().withType(TYPE_STRING));
}


Expand Down Expand Up @@ -528,7 +529,8 @@ public Map<String, Object> getPaths() {
Response contents = new Response("The feature collections shared by this API");
contents.addFormat(BaseRequest.JSON_MIME, new FormatDescription().withReference
("'#/components/schemas/content"));
contents.addFormat(BaseRequest.HTML_MIME, new FormatDescription().withType(TYPE_STRING));
// uncomment when HTML format is supported
// contents.addFormat(BaseRequest.HTML_MIME, new FormatDescription().withType(TYPE_STRING));
caps.addResponse("200", contents);
caps.addResponse("default", ERROR_RESPONSE);
result.put("/", Collections.singletonMap("get", caps));
Expand All @@ -540,7 +542,8 @@ public Map<String, Object> getPaths() {
api.addParameter(REF_FORMAT);
Response apiResponse = new Response("This API");
apiResponse.addFormat(BaseRequest.JSON_MIME, new FormatDescription().withType(TYPE_OBJECT));
apiResponse.addFormat(BaseRequest.HTML_MIME, new FormatDescription().withType(TYPE_STRING));
// uncomment when HTML format is supported
// apiResponse.addFormat(BaseRequest.HTML_MIME, new FormatDescription().withType(TYPE_STRING));
apiResponse.addFormat(BaseRequest.YAML_MIME, new FormatDescription().withType(TYPE_OBJECT));
api.addResponse("200", apiResponse);
api.addResponse("default", ERROR_RESPONSE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ public ContentsDocument(ContentRequest request, WFSInfo wfs, Catalog catalog) {
String contentsUrl = ResponseUtils.buildURL(baseUrl, "wfs3/", null, URLMangler.URLType.SERVICE);
addLink(new ContentsDocument.Link(contentsUrl, ContentsDocument.REL_SELF, BaseRequest.JSON_MIME, "This" +
" document"));
String contentsHtmlUrl = ResponseUtils.buildURL(baseUrl, "wfs3/", Collections.singletonMap("f", "html"),
URLMangler.URLType.SERVICE);
addLink(new ContentsDocument.Link(contentsHtmlUrl, ContentsDocument.REL_ALTERNATE, BaseRequest
.HTML_MIME, "This document as HTML"));
// uncomment when HTML format is supported
// String contentsHtmlUrl = ResponseUtils.buildURL(baseUrl, "wfs3/", Collections.singletonMap("f", "html"),
// URLMangler.URLType.SERVICE);
// addLink(new ContentsDocument.Link(contentsHtmlUrl, ContentsDocument.REL_ALTERNATE, BaseRequest
// .HTML_MIME, "This document as HTML"));
String contentsYamlUrl = ResponseUtils.buildURL(baseUrl, "wfs3/", Collections.singletonMap("f", "yaml"),
URLMangler.URLType.SERVICE);
addLink(new ContentsDocument.Link(contentsYamlUrl, ContentsDocument.REL_ALTERNATE, BaseRequest
Expand All @@ -155,10 +156,10 @@ public ContentsDocument(ContentRequest request, WFSInfo wfs, Catalog catalog) {
String apiUrl = ResponseUtils.buildURL(baseUrl, "wfs3/api", null, URLMangler.URLType.SERVICE);
addLink(new ContentsDocument.Link(apiUrl, ContentsDocument.REL_SERVICE, BaseRequest.JSON_MIME, "The " +
"OpenAPI definition as JSON"));
String apiHtmlUrl = ResponseUtils.buildURL(baseUrl, "wfs3/api", Collections.singletonMap("f", "html"),
URLMangler.URLType.SERVICE);
addLink(new ContentsDocument.Link(apiHtmlUrl, ContentsDocument.REL_SERVICE, BaseRequest.HTML_MIME,
"The OpenAPI definition as HTML"));
// String apiHtmlUrl = ResponseUtils.buildURL(baseUrl, "wfs3/api", Collections.singletonMap("f", "html"),
// URLMangler.URLType.SERVICE);
// addLink(new ContentsDocument.Link(apiHtmlUrl, ContentsDocument.REL_SERVICE, BaseRequest.HTML_MIME,
// "The OpenAPI definition as HTML"));
String apiYamlUrl = ResponseUtils.buildURL(baseUrl, "wfs3/api", Collections.singletonMap("f", "yaml"),
URLMangler.URLType.SERVICE);
addLink(new ContentsDocument.Link(apiYamlUrl, ContentsDocument.REL_SERVICE, BaseRequest.YAML_MIME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

import net.opengis.wfs20.GetFeatureType;
import org.geoserver.config.GeoServer;
import org.geoserver.ows.Dispatcher;
import org.geoserver.ows.Request;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.wfs.WFSGetFeatureOutputFormat;
import org.geoserver.wfs.WFSInfo;
import org.geoserver.wfs.WebFeatureService20;
import org.geoserver.wfs.request.FeatureCollectionResponse;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.opengis.feature.Feature;
import org.opengis.filter.FilterFactory2;

import java.util.ArrayList;
Expand Down Expand Up @@ -55,8 +60,23 @@ public APIDocument api(APIRequest request) {
}

@Override
public FeatureCollectionResponse getFeature(GetFeatureType request) {
return wfs20.getFeature(request);
public Object getFeature(GetFeatureType request) {
FeatureCollectionResponse response = wfs20.getFeature(request);
// was it a single feature request? Getting at the dispatcher thread local, as delving into the
// request model is hard, the feature id is buried as a filter in one query object
// Request dr = Dispatcher.REQUEST.get();
// if (dr != null && dr.getKvp().get("featureId") != null && dr.getKvp().get("format").equals(BaseRequest
// .HTML_MIME)) {
// List<FeatureCollection> features = response.getFeature();
// try (FeatureIterator fi = features.get(0).features()) {
// // there should be one, WFS 2.0 should have already thrown a 404 otherwise
// Feature next = fi.next();
// return next;
// }
// } else {
// normal encoding
return response;
// }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
request = new RequestWrapper(requestHTTP);
} catch(HttpErrorCodeException exception) {
((HttpServletResponse) response).sendError(exception.getErrorCode(), exception.getMessage());
return;
}
}
}
Expand All @@ -81,6 +82,8 @@ private class RequestWrapper extends HttpServletRequestWrapper {
private String request;
private String typeName;
private String outputFormat;
private String featureId;
private boolean mapped;

private RequestWrapper(HttpServletRequest wrapped) {
super(wrapped);
Expand All @@ -95,6 +98,15 @@ private RequestWrapper(HttpServletRequest wrapped) {
if (pathInfo.startsWith("/")) {
pathInfo = pathInfo.substring(1);
}
// selection by feature id?
if (pathInfo.contains("/")) {
String[] split = pathInfo.split("/");
if (split.length > 2) {
throw new HttpErrorCodeException(HttpStatus.NOT_FOUND.value(), "Invalid path " + pathInfo);
}
pathInfo = split[0];
featureId = split[1];
}
List<LayerInfo> layers = NCNameResourceCodec.getLayers(catalog, pathInfo);
if (!layers.isEmpty()) {
request = "getFeature";
Expand All @@ -105,6 +117,8 @@ private RequestWrapper(HttpServletRequest wrapped) {
} else {
throw new HttpErrorCodeException(HttpStatus.NOT_FOUND.value(), "Unsupported path " + pathInfo);
}

mapped = request != null;

// everythign defaults to JSON in WFS3
String f = wrapped.getParameter("f");
Expand All @@ -123,6 +137,11 @@ private RequestWrapper(HttpServletRequest wrapped) {
}
}

@Override
public String getRequestURI() {
return super.getContextPath() + "/wfs3";
}

@Override
public Enumeration getParameterNames() {
return Collections.enumeration(getParameterMap().keySet());
Expand Down Expand Up @@ -156,6 +175,9 @@ public Map<String, String[]> getParameterMap() {
if (outputFormat != null) {
filtered.put("outputFormat", outputFormat);
}
if (featureId != null && !featureId.isEmpty()) {
filtered.put("featureId", featureId);
}
return filtered;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface WebFeatureService30 {

APIDocument api(APIRequest request);

FeatureCollectionResponse getFeature(GetFeatureType request);
Object getFeature(GetFeatureType request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ public void testGetLayerAsGeoJson() throws Exception {
print(json);
}

@Test
public void testGetSingleFeature() throws Exception {
String roadSegments = getEncodedName(MockData.ROAD_SEGMENTS);
JSON json = getAsJSON("wfs3/" + roadSegments + "/RoadSegments.1107532045088");
print(json);
}

}

0 comments on commit b83ed69

Please sign in to comment.