Skip to content

Commit 90162d8

Browse files
authored
HTM-1978: Encode style name to allow spaces when getting proxied legend styles (#1678)
2 parents db9bfb4 + fbc8a48 commit 90162d8

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import jakarta.persistence.EntityManager;
1818
import java.lang.invoke.MethodHandles;
1919
import java.net.URI;
20+
import java.nio.charset.StandardCharsets;
2021
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -32,6 +33,7 @@
3233
import org.springframework.stereotype.Service;
3334
import org.springframework.transaction.annotation.Transactional;
3435
import org.springframework.web.util.UriComponentsBuilder;
36+
import org.springframework.web.util.UriUtils;
3537
import org.tailormap.api.controller.GeoServiceProxyController;
3638
import org.tailormap.api.persistence.Application;
3739
import org.tailormap.api.persistence.Configuration;
@@ -197,16 +199,28 @@ private List<WMSStyle> getProxiedLegendStyles(
197199
Application application, AppTreeLayerNode appTreeLayerNode, List<WMSStyle> legendStyles) {
198200
String legendProxyUrl = getLegendProxyUrl(application, appTreeLayerNode);
199201
return legendStyles.stream()
200-
.map(style ->
202+
.map(style -> {
203+
try {
201204
// Create a copy of the style so we don't mutate configuration objects
202-
new WMSStyle()
205+
return new WMSStyle()
203206
.name(style.getName())
204207
.title(style.getTitle())
205208
.abstractText(style.getAbstractText())
206209
.legendUrl(UriComponentsBuilder.fromUriString(legendProxyUrl)
207-
.queryParam("STYLE", style.getName())
210+
.queryParam("STYLE", UriUtils.encode(style.getName(), StandardCharsets.UTF_8))
208211
.build(true)
209-
.toUri()))
212+
.toUri());
213+
} catch (Exception e) {
214+
logger.warn(
215+
"Failed to create proxied legend style for application {} layer {} style {}: {}",
216+
application.getId(),
217+
appTreeLayerNode.getId(),
218+
style.getName(),
219+
e.getMessage());
220+
return null;
221+
}
222+
})
223+
.filter(Objects::nonNull)
210224
.toList();
211225
}
212226

0 commit comments

Comments
 (0)