From 049f8a0aabf789a71376bb93050fd0170905e40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Sat, 11 Jan 2025 12:40:36 +0100 Subject: [PATCH] Rely on standard NoOpResponseErrorHandler --- .../boot/build/bom/CheckLinks.java | 16 +++---------- ...verContainerInvocationContextProvider.java | 24 +++---------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckLinks.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckLinks.java index 94c415144d3..7975ef6c7a3 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckLinks.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/CheckLinks.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * 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. @@ -16,7 +16,6 @@ package org.springframework.boot.build.bom; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -31,9 +30,8 @@ import org.gradle.internal.impldep.org.apache.http.client.config.CookieSpecs; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.web.client.DefaultResponseErrorHandler; +import org.springframework.web.client.NoOpResponseErrorHandler; import org.springframework.web.client.RestTemplate; /** @@ -57,7 +55,7 @@ public abstract class CheckLinks extends DefaultTask { CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(config).build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); RestTemplate restTemplate = new RestTemplate(requestFactory); - restTemplate.setErrorHandler(new IgnoringErrorHandler()); + restTemplate.setErrorHandler(new NoOpResponseErrorHandler()); for (Library library : this.bom.getLibraries()) { library.getLinks().forEach((name, links) -> links.forEach((link) -> { URI uri; @@ -74,12 +72,4 @@ public abstract class CheckLinks extends DefaultTask { } } - static class IgnoringErrorHandler extends DefaultResponseErrorHandler { - - @Override - public void handleError(ClientHttpResponse response) throws IOException { - } - - } - } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java index 59b5c62266f..075e096c49d 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * 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. @@ -44,12 +44,10 @@ import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; import org.junit.platform.commons.util.ReflectionUtils; import org.springframework.boot.testsupport.BuildOutput; -import org.springframework.http.HttpMethod; -import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.util.FileSystemUtils; import org.springframework.util.StringUtils; -import org.springframework.web.client.ResponseErrorHandler; +import org.springframework.web.client.NoOpResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriTemplateHandler; @@ -188,23 +186,7 @@ class EmbeddedServerContainerInvocationContextProvider RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory(HttpClients.custom() .setRetryStrategy(new DefaultHttpRequestRetryStrategy(10, TimeValue.of(1, TimeUnit.SECONDS))) .build())); - rest.setErrorHandler(new ResponseErrorHandler() { - - @Override - public boolean hasError(ClientHttpResponse response) throws IOException { - return false; - } - - @Override - @SuppressWarnings("removal") - public void handleError(ClientHttpResponse response) throws IOException { - } - - @Override - public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException { - } - - }); + rest.setErrorHandler(new NoOpResponseErrorHandler()); rest.setUriTemplateHandler(new UriTemplateHandler() { @Override