Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.boot.actuate.metrics.cache.JCacheCacheMeterBinderProvider;
import org.springframework.boot.actuate.metrics.cache.RedisCacheMeterBinderProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.jcache.JCacheCache;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -83,6 +84,7 @@ HazelcastCacheMeterBinderProvider hazelcastCacheMeterBinderProvider() {
static class JCacheCacheMeterBinderProviderConfiguration {

@Bean
@ConditionalOnMissingBean(JCacheCacheMeterBinderProvider.class)
JCacheCacheMeterBinderProvider jCacheCacheMeterBinderProvider() {
return new JCacheCacheMeterBinderProvider();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2012-2025 the original author or 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.actuate.autoconfigure.metrics.cache;

import org.junit.jupiter.api.Test;

import org.springframework.boot.actuate.metrics.cache.JCacheCacheMeterBinderProvider;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

import static org.assertj.core.api.Assertions.assertThat;

class JCacheCacheMeterBinderProviderBackOffTests {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(CacheMetricsAutoConfiguration.class));

@Test
void backsOffWhenUserProvidesProvider() {
JCacheCacheMeterBinderProvider custom = new JCacheCacheMeterBinderProvider();
this.contextRunner.withBean(JCacheCacheMeterBinderProvider.class, () -> custom).run((context) -> {
var bean = context.getBean(JCacheCacheMeterBinderProvider.class);
assertThat(bean).isSameAs(custom);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,35 @@ private Response execute(HttpUriRequest request) {
try {
ClassicHttpResponse response = this.client.executeOpen(this.host, request, null);
int statusCode = response.getCode();

if (statusCode >= 400 && statusCode <= 500) {
byte[] content = readContent(response);
response.close();

if (statusCode == 407) {
response.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong to me as the response will now only be closed when the status code is 407.


String detail = null;
Message json = deserializeMessage(content);
if (json != null && org.springframework.util.StringUtils.hasText(json.getMessage())) {
Copy link
Member

@wilkinsona wilkinsona Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringUtils is already imported so there's no need to fully-qualify the type.

detail = json.getMessage();
}
else {
detail = new String(content, java.nio.charset.StandardCharsets.UTF_8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardCharsets should be imported rather than using the fully-qualified type here.

}

String msg = "Proxy authentication required for host: " + this.host.toHostString() + ", uri: "
+ request.getUri()
+ (org.springframework.util.StringUtils.hasText(detail) ? " - " + detail : "");
Copy link
Member

@wilkinsona wilkinsona Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringUtils is already imported so there's no need to fully-qualify the type.


throw new ProxyAuthenticationException(msg);
}

Errors errors = (statusCode != 500) ? deserializeErrors(content) : null;
Message message = deserializeMessage(content);
throw new DockerEngineException(this.host.toHostString(), request.getUri(), statusCode,
response.getReasonPhrase(), errors, message);
}

return new HttpClientResponse(response);
}
catch (IOException | URISyntaxException ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2012-2025 the original author or 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.buildpack.platform.docker.transport;

public class ProxyAuthenticationException extends RuntimeException {

public ProxyAuthenticationException(String message) {
super(message);
}

public ProxyAuthenticationException(String message, Throwable cause) {
super(message, cause);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2012-2025 the original author or 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.buildpack.platform.docker.transport;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class ProxyAuthenticationExceptionTests {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need tests for ProxyAuthenticationException. Please remove this class.


@Test
void constructsWithMessage() {
ProxyAuthenticationException ex = new ProxyAuthenticationException("Proxy auth failed");
assertThat(ex.getMessage()).isEqualTo("Proxy auth failed");
}

@Test
void constructsWithMessageAndCause() {
Exception cause = new Exception("boom");
ProxyAuthenticationException ex = new ProxyAuthenticationException("Proxy auth failed", cause);
assertThat(ex.getCause()).isSameAs(cause);
assertThat(ex.getMessage()).isEqualTo("Proxy auth failed");
}

}