Skip to content

Commit 7348c31

Browse files
Make JCacheCacheMeterBinderProvider back off when user provides a bean (fixes #46212)
Signed-off-by: Siva Sai Udayagiri <[email protected]>
1 parent 1bd6ffe commit 7348c31

File tree

4 files changed

+51
-81
lines changed

4 files changed

+51
-81
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/cache/CacheMeterBinderProvidersConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.boot.actuate.metrics.cache.JCacheCacheMeterBinderProvider;
3131
import org.springframework.boot.actuate.metrics.cache.RedisCacheMeterBinderProvider;
3232
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
33+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3334
import org.springframework.cache.caffeine.CaffeineCache;
3435
import org.springframework.cache.jcache.JCacheCache;
3536
import org.springframework.context.annotation.Bean;
@@ -83,6 +84,7 @@ HazelcastCacheMeterBinderProvider hazelcastCacheMeterBinderProvider() {
8384
static class JCacheCacheMeterBinderProviderConfiguration {
8485

8586
@Bean
87+
@ConditionalOnMissingBean(JCacheCacheMeterBinderProvider.class)
8688
JCacheCacheMeterBinderProvider jCacheCacheMeterBinderProvider() {
8789
return new JCacheCacheMeterBinderProvider();
8890
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.metrics.cache;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.boot.actuate.metrics.cache.JCacheCacheMeterBinderProvider;
22+
import org.springframework.boot.autoconfigure.AutoConfigurations;
23+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
class JCacheCacheMeterBinderProviderBackOffTests {
28+
29+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
30+
.withConfiguration(AutoConfigurations.of(CacheMetricsAutoConfiguration.class));
31+
32+
@Test
33+
void backsOffWhenUserProvidesProvider() {
34+
JCacheCacheMeterBinderProvider custom = new JCacheCacheMeterBinderProvider();
35+
this.contextRunner.withBean(JCacheCacheMeterBinderProvider.class, () -> custom).run((context) -> {
36+
var bean = context.getBean(JCacheCacheMeterBinderProvider.class);
37+
assertThat(bean).isSameAs(custom);
38+
});
39+
}
40+
41+
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.OutputStream;
2323
import java.net.URI;
2424
import java.net.URISyntaxException;
25+
import java.nio.charset.StandardCharsets;
2526

2627
import org.apache.hc.client5.http.classic.HttpClient;
2728
import org.apache.hc.client5.http.classic.methods.HttpDelete;
@@ -65,66 +66,31 @@ protected HttpClientTransport(HttpClient client, HttpHost host) {
6566
this.host = host;
6667
}
6768

68-
/**
69-
* Perform an HTTP GET operation.
70-
* @param uri the destination URI
71-
* @return the operation response
72-
*/
7369
@Override
7470
public Response get(URI uri) {
7571
return execute(new HttpGet(uri));
7672
}
7773

78-
/**
79-
* Perform an HTTP POST operation.
80-
* @param uri the destination URI
81-
* @return the operation response
82-
*/
8374
@Override
8475
public Response post(URI uri) {
8576
return execute(new HttpPost(uri));
8677
}
8778

88-
/**
89-
* Perform an HTTP POST operation.
90-
* @param uri the destination URI
91-
* @param registryAuth registry authentication credentials
92-
* @return the operation response
93-
*/
9479
@Override
9580
public Response post(URI uri, String registryAuth) {
9681
return execute(new HttpPost(uri), registryAuth);
9782
}
9883

99-
/**
100-
* Perform an HTTP POST operation.
101-
* @param uri the destination URI
102-
* @param contentType the content type to write
103-
* @param writer a content writer
104-
* @return the operation response
105-
*/
10684
@Override
10785
public Response post(URI uri, String contentType, IOConsumer<OutputStream> writer) {
10886
return execute(new HttpPost(uri), contentType, writer);
10987
}
11088

111-
/**
112-
* Perform an HTTP PUT operation.
113-
* @param uri the destination URI
114-
* @param contentType the content type to write
115-
* @param writer a content writer
116-
* @return the operation response
117-
*/
11889
@Override
11990
public Response put(URI uri, String contentType, IOConsumer<OutputStream> writer) {
12091
return execute(new HttpPut(uri), contentType, writer);
12192
}
12293

123-
/**
124-
* Perform an HTTP DELETE operation.
125-
* @param uri the destination URI
126-
* @return the operation response
127-
*/
12894
@Override
12995
public Response delete(URI uri) {
13096
return execute(new HttpDelete(uri));
@@ -149,22 +115,22 @@ private Response execute(HttpUriRequest request) {
149115

150116
if (statusCode >= 400 && statusCode <= 500) {
151117
byte[] content = readContent(response);
118+
// Always close the response for error paths
119+
response.close();
152120

121+
// Special handling for proxy auth failures
153122
if (statusCode == 407) {
154-
response.close();
155-
156123
String detail = null;
157124
Message json = deserializeMessage(content);
158-
if (json != null && org.springframework.util.StringUtils.hasText(json.getMessage())) {
125+
if (json != null && StringUtils.hasText(json.getMessage())) {
159126
detail = json.getMessage();
160127
}
161-
else {
162-
detail = new String(content, java.nio.charset.StandardCharsets.UTF_8);
128+
else if (content != null) {
129+
detail = new String(content, StandardCharsets.UTF_8);
163130
}
164131

165132
String msg = "Proxy authentication required for host: " + this.host.toHostString() + ", uri: "
166-
+ request.getUri()
167-
+ (org.springframework.util.StringUtils.hasText(detail) ? " - " + detail : "");
133+
+ request.getUri() + (StringUtils.hasText(detail) ? " - " + detail : "");
168134

169135
throw new ProxyAuthenticationException(msg);
170136
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/ProxyAuthenticationExceptionTests.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)