Commit 40c2c6db authored by Stephane Nicoll's avatar Stephane Nicoll

Clean remote url if necessary

Make sure that the remote URL does not contain a trailing slash.

Closes gh-4297
parent edd3f1ea
...@@ -46,7 +46,7 @@ class RemoteUrlPropertyExtractor ...@@ -46,7 +46,7 @@ class RemoteUrlPropertyExtractor
@Override @Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
ConfigurableEnvironment environment = event.getEnvironment(); ConfigurableEnvironment environment = event.getEnvironment();
String url = environment.getProperty(NON_OPTION_ARGS); String url = cleanRemoteUrl(environment.getProperty(NON_OPTION_ARGS));
Assert.state(StringUtils.hasLength(url), "No remote URL specified"); Assert.state(StringUtils.hasLength(url), "No remote URL specified");
Assert.state(url.indexOf(",") == -1, "Multiple URLs specified"); Assert.state(url.indexOf(",") == -1, "Multiple URLs specified");
try { try {
...@@ -60,6 +60,13 @@ class RemoteUrlPropertyExtractor ...@@ -60,6 +60,13 @@ class RemoteUrlPropertyExtractor
environment.getPropertySources().addLast(propertySource); environment.getPropertySources().addLast(propertySource);
} }
private String cleanRemoteUrl(String url) {
if (StringUtils.hasText(url) && url.endsWith("/")) {
return url.substring(0, url.length() - 1);
}
return url;
}
@Override @Override
public int getOrder() { public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE; return Ordered.HIGHEST_PRECEDENCE;
......
...@@ -79,6 +79,13 @@ public class RemoteUrlPropertyExtractorTests { ...@@ -79,6 +79,13 @@ public class RemoteUrlPropertyExtractorTests {
is(nullValue())); is(nullValue()));
} }
@Test
public void cleanValidUrl() throws Exception {
ApplicationContext context = doTest("http://localhost:8080/");
assertThat(context.getEnvironment().getProperty("remoteUrl"),
equalTo("http://localhost:8080"));
}
private ApplicationContext doTest(String... args) { private ApplicationContext doTest(String... args) {
SpringApplication application = new SpringApplication(Config.class); SpringApplication application = new SpringApplication(Config.class);
application.setWebEnvironment(false); application.setWebEnvironment(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment