Replace deprecated URL constructor in getUrl (#1179)
* Replace URL with URI in FeignClientsRegistrar to avoid deprecation warning The constructor 'URL(String)' has been deprecated since Java 20. Although this does not affect the current environment (Java 17), it will cause issues when upgrading to Java 21 or later. This commit updates the URL validation in FeignClientsRegistrar.getUrl by replacing `new URL(url)` with `new URI(url)`, ensuring forward compatibility. Verified with Java 17 and the FeignClientsRegistrarTests. Signed-off-by: HyeongDo-Myeong <hd.m@kt.com> * chore: update license year and add author tags Updated license headers to reflect year 2025 in all modified Java files. Also added @author Javadoc tags with full name to classes modified in the previous commit as requested in PR review. Signed-off-by: HyeongDo-Myeong <hd.m@kt.com> --------- Signed-off-by: HyeongDo-Myeong <hd.m@kt.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2024 the original author or authors.
|
||||
* Copyright 2013-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,10 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.openfeign;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -68,6 +66,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @author Jasbir Singh
|
||||
* @author Jinho Lee
|
||||
* @author HyeongDo Myeong
|
||||
*/
|
||||
class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware {
|
||||
|
||||
@@ -122,9 +121,9 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLo
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
try {
|
||||
new URL(url);
|
||||
new URI(url);
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(url + " is malformed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2024 the original author or authors.
|
||||
* Copyright 2013-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.
|
||||
@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Michal Domagala
|
||||
* @author Szymon Linowski
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @author HyeongDo Myeong
|
||||
*/
|
||||
class FeignClientsRegistrarTests {
|
||||
|
||||
@@ -89,6 +90,18 @@ class FeignClientsRegistrarTests {
|
||||
return registrar.getName(Collections.singletonMap("name", name));
|
||||
}
|
||||
|
||||
@Test
|
||||
void goodUrl() {
|
||||
String url = FeignClientsRegistrar.getUrl("https://good.url");
|
||||
assertThat(url).as("url was wrong").isEqualTo("https://good.url");
|
||||
}
|
||||
|
||||
@Test
|
||||
void badUrl() {
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> FeignClientsRegistrar.getUrl("http://bad url"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveTrailingSlashFromUrl() {
|
||||
String url = FeignClientsRegistrar.getUrl("http://localhost/");
|
||||
|
||||
Reference in New Issue
Block a user