Skip to content
Merged
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
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -68,6 +66,7 @@
* @author Olga Maciaszek-Sharma
* @author Jasbir Singh
* @author Jinho Lee
* @author HyeongDo Myeong
*/
class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware {

Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -42,6 +42,7 @@
* @author Michal Domagala
* @author Szymon Linowski
* @author Olga Maciaszek-Sharma
* @author HyeongDo Myeong
*/
class FeignClientsRegistrarTests {

Expand Down Expand Up @@ -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/");
Expand Down