Skip to content

Commit b4d5fc3

Browse files
committed
HTM-1852: Allow WMS capabilities loading to use DTD, add a timeout in the tests
1 parent 476ab8e commit b4d5fc3

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/main/java/org/tailormap/api/persistence/helper/GeoServiceHelper.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.time.Instant;
1818
import java.util.ArrayList;
1919
import java.util.List;
20+
import java.util.Map;
2021
import java.util.Objects;
2122
import java.util.Optional;
2223
import java.util.Set;
@@ -33,6 +34,7 @@
3334
import org.geotools.ows.wms.WebMapServer;
3435
import org.geotools.ows.wmts.WebMapTileServer;
3536
import org.geotools.ows.wmts.model.WMTSLayer;
37+
import org.geotools.xml.DocumentFactory;
3638
import org.slf4j.Logger;
3739
import org.slf4j.LoggerFactory;
3840
import org.springframework.beans.factory.annotation.Autowired;
@@ -293,10 +295,15 @@ private void addLayerRecursive(
293295
}
294296
}
295297

296-
void loadWMSCapabilities(GeoService geoService, ResponseTeeingHTTPClient client) throws Exception {
298+
private void loadWMSCapabilities(GeoService geoService, ResponseTeeingHTTPClient client) throws Exception {
297299
WebMapServer wms;
298300
try {
299-
wms = new WebMapServer(new URI(geoService.getUrl()).toURL(), client);
301+
wms = new WebMapServer(
302+
new URI(geoService.getUrl()).toURL(),
303+
client,
304+
Map.of(
305+
// allow DTD for WMS 1.1.x
306+
DocumentFactory.ENABLE_DTD, true));
300307
} catch (ClassCastException | IllegalStateException e) {
301308
// The gt-wms module tries to cast the XML unmarshalling result expecting capabilities, but a
302309
// WMS 1.0.0/1.1.0 ServiceException may have been unmarshalled which leads to a
@@ -380,7 +387,7 @@ void loadWMSCapabilities(GeoService geoService, ResponseTeeingHTTPClient client)
380387
Set.of());
381388
}
382389

383-
void loadWMTSCapabilities(GeoService geoService, ResponseTeeingHTTPClient client) throws Exception {
390+
private void loadWMTSCapabilities(GeoService geoService, ResponseTeeingHTTPClient client) throws Exception {
384391
WebMapTileServer wmts = new WebMapTileServer(new URI(geoService.getUrl()).toURL(), client);
385392
setServiceInfo(geoService, client, wmts);
386393

src/test/java/org/tailormap/api/controller/admin/GeoServiceAdminControllerIntegrationTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.jayway.jsonpath.JsonPath;
1414
import java.util.Objects;
15+
import java.util.concurrent.TimeUnit;
1516
import mockwebserver3.MockResponse;
1617
import mockwebserver3.MockWebServer;
1718
import okhttp3.Headers;
@@ -105,7 +106,9 @@ void refresh_capabilities() throws Exception {
105106

106107
assertEquals(
107108
"GetCapabilities",
108-
Objects.requireNonNull(server.takeRequest().getUrl()).queryParameter("REQUEST"));
109+
Objects.requireNonNull(Objects.requireNonNull(server.takeRequest(10, TimeUnit.SECONDS))
110+
.getUrl())
111+
.queryParameter("REQUEST"));
109112

110113
// This capabilities document has an extra layer
111114
body = getResourceString(wmsTestCapabilitiesUpdated);
@@ -118,7 +121,9 @@ void refresh_capabilities() throws Exception {
118121

119122
assertEquals(
120123
"GetCapabilities",
121-
Objects.requireNonNull(server.takeRequest().getUrl()).queryParameter("REQUEST"));
124+
Objects.requireNonNull(Objects.requireNonNull(server.takeRequest(10, TimeUnit.SECONDS))
125+
.getUrl())
126+
.queryParameter("REQUEST"));
122127

123128
mockMvc.perform(get(selfLink).accept(MediaType.APPLICATION_JSON))
124129
.andExpect(status().isOk())

0 commit comments

Comments
 (0)