diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java index 00fe8f195..d36b3f723 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java @@ -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 @@ * @author Olga Maciaszek-Sharma * @author Jasbir Singh * @author Jinho Lee + * @author HyeongDo Myeong */ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware { @@ -122,9 +121,9 @@ static String getUrl(String url) { 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); } } diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java index 5459dd662..3ac36ea5f 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java @@ -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 @@ * @author Michal Domagala * @author Szymon Linowski * @author Olga Maciaszek-Sharma + * @author HyeongDo Myeong */ class FeignClientsRegistrarTests { @@ -89,6 +90,18 @@ private String testGetName(String name) { 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/");