It copies a zip file into a directory - generally a temporary one - an unzip it, so that it is + * ready for use. + */ +@UtilityClass +public class GeoServerCatalogTestData { + + /** + * This method copies the zipped datadir into the Path object given as argument and unzip it at + * the same place. + * + *
It is the caller's responsability to clean up when the datadir is not needed anymore. + * + *
Note: we have to copy the resource into the directory first, because the method from
+ * GeoTools which is being used does not support zip URIs nested into jar files.
+ *
+ * @param tmpPath the temporary path where the datadir has to be unzipped to.
+ * @throws URISyntaxException
+ * @throws IOException
+ */
+ public static void unzipGeoserverCatalogTestData(Path tmpPath)
+ throws URISyntaxException, IOException {
+ InputStream zippedDatadir =
+ GeoServerCatalogTestData.class.getResourceAsStream("/test-data-directory.zip");
+ File tmpDir = tmpPath.toFile();
+ File destFile = new File(tmpDir, "test-data-directory.zip");
+ FileUtils.copyToFile(zippedDatadir, destFile);
+ TestData.unzip(destFile, tmpDir);
+ destFile.delete();
+ }
+}
diff --git a/src/catalog/plugin/src/test/resources/test-data-directory.zip b/src/catalog/plugin/src/test/resources/test-data-directory.zip
new file mode 100644
index 000000000..faf9dafed
Binary files /dev/null and b/src/catalog/plugin/src/test/resources/test-data-directory.zip differ
diff --git a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/web/gwc/GeoWebCacheUIAutoConfiguration.java b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/web/gwc/GeoWebCacheUIAutoConfiguration.java
index 39f5aee81..e090844d6 100644
--- a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/web/gwc/GeoWebCacheUIAutoConfiguration.java
+++ b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/web/gwc/GeoWebCacheUIAutoConfiguration.java
@@ -6,15 +6,21 @@
import lombok.extern.slf4j.Slf4j;
-import org.geoserver.cloud.autoconfigure.gwc.ConditionalOnGeoWebCacheRestConfigEnabled;
+import org.geoserver.catalog.Catalog;
import org.geoserver.cloud.autoconfigure.gwc.ConditionalOnWebUIEnabled;
import org.geoserver.cloud.gwc.config.core.GeoWebCacheConfigurationProperties;
+import org.geoserver.cloud.virtualservice.VirtualServiceVerifier;
+import org.geoserver.gwc.controller.GwcUrlHandlerMapping;
+import org.geoserver.ows.Dispatcher;
import org.geowebcache.GeoWebCacheDispatcher;
import org.geowebcache.rest.controller.ByteStreamController;
import org.gwc.web.rest.GeoWebCacheController;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Bean;
+import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import javax.annotation.PostConstruct;
@@ -28,17 +34,63 @@ public class GeoWebCacheUIAutoConfiguration {
}
@Bean
- GeoWebCacheController gwcController(GeoWebCacheDispatcher gwcDispatcher) {
- return new GeoWebCacheController(gwcDispatcher);
+ GeoWebCacheController gwcController(
+ Dispatcher geoserverDispatcher,
+ GeoWebCacheDispatcher geoWebCacheDispatcher,
+ VirtualServiceVerifier verifier) {
+ return new GeoWebCacheController(geoserverDispatcher, geoWebCacheDispatcher, verifier);
}
- /**
- * Provide a handler for static web resources if missing, for example, because {@link
- * ConditionalOnGeoWebCacheRestConfigEnabled} is disabled
- */
+ /** ConditionalOnGeoWebCacheRestConfigEnabled} is disabled */
@Bean
@ConditionalOnMissingBean(ByteStreamController.class)
ByteStreamController byteStreamController() {
return new ByteStreamController();
}
+
+ @Bean
+ VirtualServiceVerifier virtualServiceVerifier(@Qualifier("rawCatalog") Catalog catalog) {
+ return new VirtualServiceVerifier(catalog);
+ }
+
+ /**
+ * GS's src/web/gwc/src/main/java/applicationContext.xml
+ *
+ *
Copied from {@link GeoServerGWCDispatcherController} */ @Controller -@RequestMapping("/gwc") @RequiredArgsConstructor public class GeoWebCacheController { - private final @NonNull GeoWebCacheDispatcher gwcDispatcher; + private final @NonNull Dispatcher geoserverDispatcher; + + private final @NonNull GeoWebCacheDispatcher geoWebCacheDispatcher; + + private final @NonNull VirtualServiceVerifier virtualServiceVerifier; + + @GetMapping(path = {"/gwc", "/gwc/home", "/gwc/demo/**", "/gwc/proxy/**"}) + public void handleGet(HttpServletRequest request, HttpServletResponse response) + throws Exception { + geoWebCacheDispatcher.handleRequest(request, response); + } @GetMapping( path = { - "", - "/home", - "/demo/**", - "/proxy/**", + "/{namespace}/gwc", + "/{namespace}/gwc/home", + "/{namespace}/gwc/demo/**", + "/{namespace}/gwc/proxy/**" }) - public void handleGet(HttpServletRequest request, HttpServletResponse response) + public void handlePrefixedNamespaceGet( + @PathVariable String namespace, + HttpServletRequest request, + HttpServletResponse response) throws Exception { - gwcDispatcher.handleRequest(request, response); + virtualServiceVerifier.checkVirtualService(namespace); + geoserverDispatcher.handleRequest(request, response); } }