Skip to content

Commit a7d4400

Browse files
committed
support serviceBaseUrl with query parameters other than SERVICE=WMS
1 parent a59d6b5 commit a7d4400

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

grumpy-ogc/src/main/java/com/github/davidmoten/grumpy/wms/CapabilitiesProviderFromCapabilities.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.xml.transform.TransformerException;
1313

1414
import org.apache.commons.io.IOUtils;
15+
import org.apache.commons.text.StringEscapeUtils;
1516
import org.slf4j.Logger;
1617
import org.slf4j.LoggerFactory;
1718

@@ -40,11 +41,33 @@ public String getCapabilities(HttpServletRequest request) {
4041
template = template.replace("${imageFormats}", formats(capabilities.getImageFormats()));
4142
template = template.replace("${infoFormats}", formats(capabilities.getInfoFormats()));
4243
template = template.replace("${layers}", layers(capabilities.getLayers()));
43-
template = template.replace("${serviceBaseUrl}", capabilities.getServiceUrlBase());
44+
template = template.replace("${serviceBaseUrl}",
45+
StringEscapeUtils.escapeXml11(adjustUrl(capabilities.getServiceUrlBase())));
4446
log.info("capabilities=\n" + template);
4547
return template;
4648
}
4749

50+
private static final String SERVICE_EQUALS_WMS = "SERVICE=WMS";
51+
52+
private static String adjustUrl(String u) {
53+
// ensure ends in & and contains parameter SERVICE=WMS
54+
if (u.contains("?")) {
55+
if (u.contains(SERVICE_EQUALS_WMS)) {
56+
if (u.endsWith("&")) {
57+
return u;
58+
} else {
59+
return u + "&";
60+
}
61+
} else if (u.endsWith("&")) {
62+
return u + SERVICE_EQUALS_WMS + "&";
63+
} else {
64+
return u + "&" + SERVICE_EQUALS_WMS + "&";
65+
}
66+
} else {
67+
return u + "?" + SERVICE_EQUALS_WMS + "&";
68+
}
69+
}
70+
4871
private String layers(List<CapabilitiesLayer> layers) {
4972
StringBuilder s = new StringBuilder();
5073
for (CapabilitiesLayer layer : layers) {

grumpy-ogc/src/main/resources/wms-capabilities-template.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<Get>
4141
<OnlineResource
4242
xlink:type="simple"
43-
xlink:href="${serviceBaseUrl}?SERVICE=WMS&amp;" />
43+
xlink:href="${serviceBaseUrl}" />
4444
</Get>
4545
</HTTP>
4646
</DCPType>
@@ -52,7 +52,7 @@
5252
<Get>
5353
<OnlineResource
5454
xlink:type="simple"
55-
xlink:href="${serviceBaseUrl}?SERVICE=WMS&amp;" />
55+
xlink:href="${serviceBaseUrl}" />
5656
</Get>
5757
</HTTP>
5858
</DCPType>
@@ -64,7 +64,7 @@
6464
<Get>
6565
<OnlineResource
6666
xlink:type="simple"
67-
xlink:href="${serviceBaseUrl}?SERVICE=WMS&amp;" />
67+
xlink:href="${serviceBaseUrl}&amp;" />
6868
</Get>
6969
</HTTP>
7070
</DCPType>

0 commit comments

Comments
 (0)