fix spring-webflux cast to PathPattern throws ClassCastException (#6872)

when
ServerWebExchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
"path string type").
opentelemetry javaagent will throw exception.

[企业微信截图_76344afd-4541-482c-a90f-0606ad720351](https://user-images.githubusercontent.com/15957476/195615160-45559fb5-5e0c-4c25-8678-7d8aa603f346.png)
This commit is contained in:
王展城 2022-10-21 16:35:33 +08:00 committed by GitHub
parent 598ee82659
commit 397a5a89b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -41,9 +41,14 @@ public final class WebfluxSingletons {
public static HttpRouteGetter<ServerWebExchange> httpRouteGetter() {
return (context, exchange) -> {
PathPattern bestPattern =
exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
return bestPattern == null ? null : bestPattern.getPatternString();
Object bestPatternObj = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (bestPatternObj == null) {
return null;
}
if (bestPatternObj instanceof PathPattern) {
return ((PathPattern) bestPatternObj).getPatternString();
}
return bestPatternObj.toString();
};
}