Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-layout-template-json</artifactId>
<version>2.25.3</version> <!-- Check for the latest version -->
<version>2.24.3</version> <!-- Check for the latest version -->
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class WfsDefaultParam {

private Map<String, String> fields;
private Map<String, String> download;
private Map<String, String> capabilities;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import static au.org.aodn.ogcapi.server.core.configuration.CacheConfig.DOWNLOADABLE_FIELDS;
import static au.org.aodn.ogcapi.server.core.configuration.CacheConfig.GET_CAPABILITIES_WFS_FEATURE_TYPES;
import static au.org.aodn.ogcapi.server.core.service.wfs.WfsDefaultParam.WFS_LINK_MARKER;
import static au.org.aodn.ogcapi.server.core.service.wms.WmsDefaultParam.WMS_LINK_MARKER;
import static au.org.aodn.ogcapi.server.core.util.GeoserverUtils.*;

@Slf4j
Expand Down Expand Up @@ -94,6 +93,23 @@ protected List<LinkModel> getWfsLinks(String collectionId) {
.toList();
}

protected String createCapabilitiesQueryUrl(String wfsServerUrl) {
// Parse the base URL to construct GetCapabilities request
UriComponents components = UriComponentsBuilder.fromUriString(wfsServerUrl).build();

// Build GetCapabilities URL
UriComponentsBuilder builder = UriComponentsBuilder
.newInstance()
.scheme("https") // hardcode to be https to avoid redirect
.port(components.getPort())
.host(components.getHost())
.path(components.getPath() != null ? components.getPath() : "/geoserver/ows");

Map<String, String> params = wfsDefaultParam.getCapabilities();
params.forEach(builder::queryParam);

return builder.build().toUriString();
}

protected String createFeatureFieldQueryUrl(String url, FeatureRequest request) {
UriComponents components = UriComponentsBuilder.fromUriString(url).build();
Expand Down Expand Up @@ -336,20 +352,7 @@ public Optional<String> getFeatureServerUrlByTitleOrQueryParam(String collection
@Cacheable(value = GET_CAPABILITIES_WFS_FEATURE_TYPES)
public List<FeatureTypeInfo> fetchCapabilitiesFeatureTypesByUrl(String wfsServerUrl) {
try {
// Parse the base URL to construct GetCapabilities request
UriComponents components = UriComponentsBuilder.fromUriString(wfsServerUrl).build();

// Build GetCapabilities URL
UriComponentsBuilder builder = UriComponentsBuilder
.newInstance()
.scheme("https") // hardcode to be https to avoid redirect
.port(components.getPort())
.host(components.getHost())
.path(components.getPath() != null ? components.getPath() : "/geoserver/ows")
.queryParam("service", "wfs")
.queryParam("request", "GetCapabilities");

String url = builder.build().toUriString();
String url = createCapabilitiesQueryUrl(wfsServerUrl);
log.debug("WFS GetCapabilities URL: {}", url);

// Make the HTTPS call
Expand Down
4 changes: 4 additions & 0 deletions server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ wfs-default-param:
SERVICE: "WFS"
VERSION: "1.0.0" # TODO: Change to 2.0.0 after testing CQL query
REQUEST: "GetFeature"
capabilities:
SERVICE: "WFS"
VERSION: "1.0.0"
REQUEST: "GetCapabilities"

# Default parameter for wms call
wms-default-param:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package au.org.aodn.ogcapi.server.service.wfs;
package au.org.aodn.ogcapi.server.core.service.wfs;

import au.org.aodn.ogcapi.server.core.exception.GeoserverFieldsNotFoundException;
import au.org.aodn.ogcapi.server.core.model.LinkModel;
Expand All @@ -8,14 +8,14 @@
import au.org.aodn.ogcapi.server.core.model.ogc.wfs.WFSFieldModel;
import au.org.aodn.ogcapi.server.core.service.ElasticSearchBase;
import au.org.aodn.ogcapi.server.core.service.Search;
import au.org.aodn.ogcapi.server.core.service.wfs.WfsDefaultParam;
import au.org.aodn.ogcapi.server.core.service.wfs.WfsServer;
import au.org.aodn.ogcapi.server.core.util.RestTemplateUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
Expand All @@ -24,14 +24,14 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static au.org.aodn.ogcapi.server.core.service.wfs.WfsDefaultParam.WFS_LINK_MARKER;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@SpringBootTest
public class WfsServerTest {

@Mock
Expand All @@ -43,20 +43,14 @@ public class WfsServerTest {
@Mock
HttpEntity<?> entity;

@Mock
@Autowired
WfsDefaultParam wfsDefaultParam;

AutoCloseable closeableMock;

@BeforeEach
public void setUp() {
closeableMock = MockitoAnnotations.openMocks(this);
// Setup default param mock
when(wfsDefaultParam.getFields()).thenReturn(Map.of(
"service", "WFS",
"version", "2.0.0",
"request", "DescribeFeatureType"
));
}

@AfterEach
Expand Down Expand Up @@ -332,4 +326,41 @@ public void testGetDownloadableFieldsNoCollection() {

assertNull(result, "Should return null when no collection found");
}

@Test
void createFeatureFieldQueryUrl_buildsCorrectUrlWithTypename() {
// arrange
String baseUrl = "https://example.com/wfs?service=WFS&version=1.1.0&request=GetFeature";
FeatureRequest request = FeatureRequest
.builder()
.layerName("my:layer")
.build();

// act
WfsServer server = new WfsServer(mockSearch, restTemplate, new RestTemplateUtils(restTemplate), entity, wfsDefaultParam);
String result = server.createFeatureFieldQueryUrl(baseUrl, request);

// assert
assertNotNull(result);
assertTrue(result.contains("TYPENAME=my:layer"));
assertTrue(result.contains("SERVICE=WFS"));
assertTrue(result.contains("VERSION=2.0.0")); // from defaults
assertTrue(result.contains("REQUEST=DescribeFeatureType")); // original one is replaced
}

@Test
void createCapabilitiesQueryUrl_buildsCorrectUrl() {
// arrange
String baseUrl = "https://example.com/wfs?service=WFS&version=1.1.0&request=GetFeature";

// act
WfsServer server = new WfsServer(mockSearch, restTemplate, new RestTemplateUtils(restTemplate), entity, wfsDefaultParam);
String result = server.createCapabilitiesQueryUrl(baseUrl);

// assert
assertNotNull(result);
assertTrue(result.contains("SERVICE=WFS"));
assertTrue(result.contains("VERSION=1.0.0")); // from defaults
assertTrue(result.contains("REQUEST=GetCapabilities")); // original one is replaced
}
}
Loading