diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java index 3cdcdc3fb1..7041977a49 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java @@ -58,7 +58,9 @@ import java.net.InetSocketAddress; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.BiFunction; +import java.util.stream.Collectors; import static co.elastic.apm.agent.tracer.AbstractSpan.PRIORITY_HIGH_LEVEL_FRAMEWORK; import static co.elastic.apm.agent.tracer.AbstractSpan.PRIORITY_LOW_LEVEL_FRAMEWORK; @@ -313,13 +315,16 @@ private static void fillResponse(Transaction transaction, ServerWebExchange e } private static void copyHeaders(HttpHeaders source, PotentiallyMultiValuedMap destination) { - for (Map.Entry> header : source.entrySet()) { + // This is the only way I could find to make a multiValueMap without having access + // to the api from spring framework 7 that will work across versions 5, 6 and 7 + Map> multiValueHeaderMap = source.toSingleValueMap().keySet() + .parallelStream().collect(Collectors.toMap(e -> e, key -> Objects.requireNonNull(source.get(key)))); + for (Map.Entry> header : multiValueHeaderMap.entrySet()) { for (String value : header.getValue()) { destination.add(header.getKey(), value); } } } - private static void copyCookies(MultiValueMap source, PotentiallyMultiValuedMap destination) { for (Map.Entry> cookie : source.entrySet()) { for (HttpCookie value : cookie.getValue()) {