Skip to content
Closed
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
Expand Up @@ -64,7 +64,7 @@ public class JerseyAutoConfigurationCustomFilterContextPathTests {

@Test
public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/app/rest/hello",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/rest/hello",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class JerseyAutoConfigurationCustomServletContextPathTests {

@Test
public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/app/rest/hello",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/rest/hello",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.boot.test.web.client;

import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.web.client.RootUriTemplateHandler;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
Expand All @@ -28,6 +29,7 @@
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Eddú Meléndez
* @since 1.4.0
*/
public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {
Expand All @@ -36,6 +38,8 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {

private final String scheme;

private RelaxedPropertyResolver contextPathResolver;

/**
* Create a new {@code LocalHostUriTemplateHandler} that will generate {@code http}
* URIs using the given {@code environment} to determine the port.
Expand All @@ -58,12 +62,15 @@ public LocalHostUriTemplateHandler(Environment environment, String scheme) {
Assert.notNull(scheme, "Scheme must not be null");
this.environment = environment;
this.scheme = scheme;
this.contextPathResolver = new RelaxedPropertyResolver(environment,
"server.");
}

@Override
public String getRootUri() {
String port = this.environment.getProperty("local.server.port", "8080");
return this.scheme + "://localhost:" + port;
String contextPath = this.contextPathResolver.getProperty("context-path", "");
return this.scheme + "://localhost:" + port + contextPath;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Eddú Meléndez
*/
public class LocalHostUriTemplateHandlerTests {

Expand Down Expand Up @@ -74,4 +75,13 @@ public void getRootUriUsesCustomScheme() {
assertThat(handler.getRootUri()).isEqualTo("https://localhost:8080");
}

@Test
public void getRootUriShouldUseContextPath() throws Exception {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("server.contextPath", "/foo");
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(
environment);
assertThat(handler.getRootUri()).isEqualTo("http://localhost:8080/foo");
}

}