forked from geoserver/geoserver-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ogcapi - first shot on introducing a ogcapi webservice
Roughly inspired from the wms webservice. It still does not work as intended, but provides ogc/* requests to the upstream OGCAPI bean.
- Loading branch information
Showing
19 changed files
with
616 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ARG TAG=latest | ||
FROM geoservercloud/gs-cloud-base-jre:$TAG as builder | ||
|
||
ARG JAR_FILE=target/gs-cloud-*-bin.jar | ||
|
||
COPY ${JAR_FILE} application.jar | ||
|
||
RUN java -Djarmode=layertools -jar application.jar extract | ||
|
||
########## | ||
FROM geoservercloud/gs-cloud-base-geoserver-image:$TAG | ||
|
||
# WORKDIR already set to /opt/app/bin | ||
|
||
COPY --from=builder dependencies/ ./ | ||
COPY --from=builder snapshot-dependencies/ ./ | ||
COPY --from=builder spring-boot-loader/ ./ | ||
COPY --from=builder application/ ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ogcapi | ||
|
||
A OGCAPI microservice, based on the GeoServer ogc-api plugin. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.geoserver.cloud.apps</groupId> | ||
<artifactId>gs-cloud-services</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<artifactId>gs-cloud-ogcapi</artifactId> | ||
<packaging>jar</packaging> | ||
<name>ogcapi-service</name> | ||
<properties> | ||
<start-class>org.geoserver.cloud.ogcapi.app.OgcApiApplication</start-class> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.geoserver.cloud</groupId> | ||
<artifactId>gs-cloud-starter-webmvc</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.geoserver</groupId> | ||
<artifactId>gs-gwc</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-core</artifactId> | ||
|
||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-features</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-maps</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-styles</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-tiles</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-images</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-changeset</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-tiled-features</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-dggs-clickhouse</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-dggs-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-dggs</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-web-dggs</artifactId> | ||
</dependency> | ||
<!-- TODO revisit: deactivated because in the need for a 'wcs20Service' bean | ||
<dependency> | ||
<groupId>org.geoserver.community</groupId> | ||
<artifactId>gs-ogcapi-coverages</artifactId> | ||
</dependency> | ||
--> | ||
<dependency> | ||
<groupId>org.geoserver</groupId> | ||
<artifactId>gs-wms</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.cloud</groupId> | ||
<artifactId>gs-cloud-starter-wms-extensions</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.cloud</groupId> | ||
<artifactId>gs-cloud-starter-security</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.cloud</groupId> | ||
<artifactId>gs-cloud-starter-vector-formats</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.geoserver.cloud</groupId> | ||
<artifactId>gs-cloud-starter-raster-formats</artifactId> | ||
</dependency> | ||
<dependency> | ||
<!-- provides GWC integration with WMS-C --> | ||
<groupId>org.geoserver.cloud.gwc</groupId> | ||
<artifactId>gwc-cloud-spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<!-- jdbcconfig can't create the tables with a newer version than this old one used in geoserver --> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>1.4.200</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy-resources</id> | ||
<goals> | ||
<goal>copy-resources</goal> | ||
</goals> | ||
<!-- here the phase you need --> | ||
<phase>validate</phase> | ||
<configuration> | ||
<outputDirectory>${basedir}/target/config</outputDirectory> | ||
<resources> | ||
<resource> | ||
<directory>${maven.multiModuleProjectDirectory}/config/</directory> | ||
<filtering>false</filtering> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
142 changes: 142 additions & 0 deletions
142
...ain/java/org/geoserver/cloud/autoconfigure/ogcapi/OgcApiApplicationAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the | ||
* GPL 2.0 license, available at the root application directory. | ||
*/ | ||
package org.geoserver.cloud.autoconfigure.ogcapi; | ||
|
||
import org.geoserver.cloud.config.factory.FilteringXmlBeanDefinitionReader; | ||
import org.geoserver.cloud.ogcapi.controller.OgcApiController; | ||
import org.geoserver.ogcapi.APIDispatcher; | ||
import org.geoserver.ogcapi.APIRequestInfo; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.ImportResource; | ||
import org.springframework.web.context.request.RequestAttributes; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletRequestWrapper; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Configuration | ||
@ImportResource( // | ||
reader = FilteringXmlBeanDefinitionReader.class, // | ||
locations = { // | ||
"jar:gs-ogcapi-.*!/applicationContext.xml", | ||
"jar:gs-wms-.*!/applicationContext.xml#name=" | ||
+ OgcApiApplicationAutoConfiguration.WMS_BEANS_BLACKLIST, // | ||
"jar:gs-wfs-.*!/applicationContext.xml#name=" | ||
+ OgcApiApplicationAutoConfiguration.WFS_BEANS_WHITELIST | ||
}) | ||
public class OgcApiApplicationAutoConfiguration { | ||
|
||
static final String WFS_BEANS_WHITELIST = | ||
""" | ||
^(\ | ||
gml.*OutputFormat\ | ||
|bboxKvpParser\ | ||
|featureIdKvpParser\ | ||
|filter.*_KvpParser\ | ||
|cqlKvpParser\ | ||
|maxFeatureKvpParser\ | ||
|sortByKvpParser\ | ||
|xmlConfiguration.*\ | ||
|gml[1-9]*SchemaBuilder\ | ||
|wfsXsd.*\ | ||
|wfsSqlViewKvpParser\ | ||
).*$\ | ||
"""; | ||
|
||
/** wms beans black-list */ | ||
static final String WMS_BEANS_BLACKLIST = | ||
""" | ||
^(?!\ | ||
legendSample\ | ||
).*$\ | ||
"""; | ||
|
||
public @Bean OgcApiController OgcApiController() { | ||
return new OgcApiController(); | ||
} | ||
|
||
private @Autowired APIDispatcher apiDispatcher; | ||
|
||
@Bean | ||
SetRequestPathInfoFilter setRequestPathInfoFilter() { | ||
return new SetRequestPathInfoFilter(); | ||
} | ||
|
||
@Bean | ||
Filter attachApiDispatcherFilter() { | ||
return new Filter() { | ||
@Override | ||
public void doFilter( | ||
ServletRequest servletRequest, | ||
ServletResponse servletResponse, | ||
FilterChain filterChain) | ||
throws IOException, ServletException { | ||
APIRequestInfo requestInfo = | ||
new APIRequestInfo( | ||
(HttpServletRequest) servletRequest, | ||
(HttpServletResponse) servletResponse, | ||
apiDispatcher); | ||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); | ||
if (requestAttributes == null) { | ||
throw new IllegalStateException("Request attributes are not set"); | ||
} | ||
requestAttributes.setAttribute( | ||
APIRequestInfo.KEY, requestInfo, RequestAttributes.SCOPE_REQUEST); | ||
filterChain.doFilter(servletRequest, servletResponse); | ||
} | ||
}; | ||
} | ||
|
||
static class SetRequestPathInfoFilter implements Filter { | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
|
||
request = adaptRequest((HttpServletRequest) request); | ||
chain.doFilter(request, response); | ||
} | ||
|
||
/** | ||
* | ||
* | ||
* <ul> | ||
* <li>{@code contextPath} is usually empty, but it'll match the gateways | ||
* ${geoserver.base-path} if such is set, thanks to the | ||
* server.forward-headers-strategy=framework in the application's bootstrap.yml | ||
* <li>{@code pathInfo} is computed beforehand to avoid decorating the HttpServletRequest | ||
* if the request is not for gwc (e.g. an actuator endpoint) | ||
* <li>{@code suffix} is used to strip it out of requestURI and fake the pathInfo gwc | ||
* expects as it assumes the request is being handled by a Dispatcher mapped to /** | ||
* <li>yes, this is odd, the alternative is re-writing GWC without weird assumptions | ||
* </ul> | ||
*/ | ||
protected ServletRequest adaptRequest(HttpServletRequest request) { | ||
// full request URI (e.g. '/geoserver/cloud/{workspace}/gwc/service/tms/1.0.0', where | ||
// '/geoserver/cloud' is the context path as given by the gateway's base uri, and | ||
// '/{workspace}/gwc' the suffix after which comes the pathInfo '/service/tms/1.0.0') | ||
final String requestURI = request.getRequestURI(); | ||
|
||
final int ogcIdx = requestURI.indexOf("/ogc"); | ||
if (ogcIdx > -1) { | ||
final String pathToOgc = requestURI.substring(0, ogcIdx + "/ogc".length()); | ||
final String pathInfo = requestURI.substring(pathToOgc.length()); | ||
|
||
return new HttpServletRequestWrapper(request) { | ||
public @Override String getPathInfo() { | ||
return pathInfo; | ||
} | ||
}; | ||
} | ||
return request; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...apps/geoserver/ogcapi/src/main/java/org/geoserver/cloud/ogcapi/app/OgcApiApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the | ||
* GPL 2.0 license, available at the root application directory. | ||
*/ | ||
package org.geoserver.cloud.ogcapi.app; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.retry.annotation.EnableRetry; | ||
|
||
@SpringBootApplication | ||
@EnableRetry | ||
public class OgcApiApplication { | ||
|
||
public static void main(String[] args) { | ||
try { | ||
SpringApplication.run(OgcApiApplication.class, args); | ||
} catch (RuntimeException e) { | ||
e.printStackTrace(); | ||
System.exit(-1); | ||
} | ||
} | ||
} |
Oops, something went wrong.