From d7ec67eb33d2b12a1c465e6d8924e7700383dc19 Mon Sep 17 00:00:00 2001 From: Fred Allard Date: Thu, 16 Dec 2021 08:57:10 -0500 Subject: [PATCH] fix #147 by using the base path attribute instead. --- .../web/starter/SkipPatternAutoConfiguration.java | 10 +++++++--- .../spring/web/starter/SkipPatternConfigTest.java | 15 +++++++++++++-- pom.xml | 6 +++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/opentracing-spring-web-starter/src/main/java/io/opentracing/contrib/spring/web/starter/SkipPatternAutoConfiguration.java b/opentracing-spring-web-starter/src/main/java/io/opentracing/contrib/spring/web/starter/SkipPatternAutoConfiguration.java index 6bc20d0b..0ea125c8 100644 --- a/opentracing-spring-web-starter/src/main/java/io/opentracing/contrib/spring/web/starter/SkipPatternAutoConfiguration.java +++ b/opentracing-spring-web-starter/src/main/java/io/opentracing/contrib/spring/web/starter/SkipPatternAutoConfiguration.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2019 The OpenTracing Authors + * Copyright 2016-2021 The OpenTracing Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -65,13 +65,17 @@ protected static class ManagementSkipPatternProviderConfig { static Optional getPatternForManagementServerProperties( ManagementServerProperties managementServerProperties) { - String contextPath = managementServerProperties.getServlet().getContextPath(); + String contextPath = managementServerProperties.getBasePath(); if (StringUtils.hasText(contextPath)) { - return Optional.of(Pattern.compile(contextPath + ".*")); + return Optional.of(Pattern.compile(cleanup(contextPath) + ".*")); } return Optional.empty(); } + private static String cleanup(String contextPath) { + return contextPath.startsWith("/") ? contextPath.substring(1) : contextPath; + } + @Bean @ConditionalOnBean(ManagementServerProperties.class) public SkipPattern skipPatternForManagementServerProperties( diff --git a/opentracing-spring-web-starter/src/test/java/io/opentracing/contrib/spring/web/starter/SkipPatternConfigTest.java b/opentracing-spring-web-starter/src/test/java/io/opentracing/contrib/spring/web/starter/SkipPatternConfigTest.java index 521c151c..cb64726a 100644 --- a/opentracing-spring-web-starter/src/test/java/io/opentracing/contrib/spring/web/starter/SkipPatternConfigTest.java +++ b/opentracing-spring-web-starter/src/test/java/io/opentracing/contrib/spring/web/starter/SkipPatternConfigTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2019 The OpenTracing Authors + * Copyright 2016-2021 The OpenTracing Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -62,10 +62,21 @@ public void testShouldReturnEmptyWhenManagementContextHasNoContextPath() { then(pattern).isEmpty(); } + @Test + public void testShouldReturnEmptyWhenManagementContextHasOnlyARootSlashHasContextPath() { + ManagementServerProperties properties = new ManagementServerProperties(); + properties.setBasePath("/"); + + Optional pattern = new SkipPatternAutoConfiguration.ManagementSkipPatternProviderConfig() + .skipPatternForManagementServerProperties(properties).pattern(); + + then(pattern).isEmpty(); + } + @Test public void testShouldReturnManagementContextWithContextPath() { ManagementServerProperties properties = new ManagementServerProperties(); - properties.getServlet().setContextPath("foo"); + properties.setBasePath("foo"); Optional pattern = new SkipPatternAutoConfiguration.ManagementSkipPatternProviderConfig() .skipPatternForManagementServerProperties(properties).pattern(); diff --git a/pom.xml b/pom.xml index 475384cc..3db923f8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ - 5.2.9.RELEASE + 5.3.1 2.21.0 0.9.12.RELEASE