Support port URI template variables
This commit makes it possible to specify port with an URI template variable.
For example :
RestTemplate restTemplate = new RestTemplate();
restTemplate.getForObject("http://localhost:{port}/resource", String.class, 8080);
Issue: SPR-12123
This commit is contained in:
committed by
Rossen Stoyanchev
parent
0b02551e2f
commit
8fbd310b07
@@ -54,6 +54,7 @@ public class AbstractJettyServerTestCase {
|
||||
|
||||
protected static String helloWorld = "H\u00e9llo W\u00f6rld";
|
||||
|
||||
protected static int port;
|
||||
protected static String baseUrl;
|
||||
|
||||
protected static MediaType textContentType;
|
||||
@@ -63,7 +64,7 @@ public class AbstractJettyServerTestCase {
|
||||
|
||||
@BeforeClass
|
||||
public static void startJettyServer() throws Exception {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
port = SocketUtils.findAvailableTcpPort();
|
||||
jettyServer = new Server(port);
|
||||
baseUrl = "http://localhost:" + port;
|
||||
ServletContextHandler handler = new ServletContextHandler();
|
||||
|
||||
@@ -229,6 +229,14 @@ public class RestTemplateIntegrationTests extends AbstractJettyServerTestCase {
|
||||
assertTrue(s.contains("\"without\":\"without\""));
|
||||
}
|
||||
|
||||
// SPR-12123
|
||||
|
||||
@Test
|
||||
public void serverPort() {
|
||||
String s = template.getForObject("http://localhost:{port}/get", String.class, port);
|
||||
assertEquals("Invalid content", helloWorld, s);
|
||||
}
|
||||
|
||||
public interface MyJacksonView1 {};
|
||||
public interface MyJacksonView2 {};
|
||||
|
||||
|
||||
@@ -80,6 +80,28 @@ public class UriComponentsTests {
|
||||
assertEquals("http://example.com/1 2 3 4", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
// SPR-12123
|
||||
|
||||
@Test
|
||||
public void port() {
|
||||
UriComponents uriComponents1 = UriComponentsBuilder.fromUriString(
|
||||
"http://example.com:8080/bar").build();
|
||||
UriComponents uriComponents2 = UriComponentsBuilder.fromUriString(
|
||||
"http://example.com/bar").port(8080).build();
|
||||
UriComponents uriComponents3 = UriComponentsBuilder.fromUriString(
|
||||
"http://example.com/bar").port("{port}").build().expand(8080);
|
||||
UriComponents uriComponents4 = UriComponentsBuilder.fromUriString(
|
||||
"http://example.com/bar").port("808{digit}").build().expand(0);
|
||||
assertEquals(8080, uriComponents1.getPort());
|
||||
assertEquals("http://example.com:8080/bar", uriComponents1.toUriString());
|
||||
assertEquals(8080, uriComponents2.getPort());
|
||||
assertEquals("http://example.com:8080/bar", uriComponents2.toUriString());
|
||||
assertEquals(8080, uriComponents3.getPort());
|
||||
assertEquals("http://example.com:8080/bar", uriComponents3.toUriString());
|
||||
assertEquals(8080, uriComponents4.getPort());
|
||||
assertEquals("http://example.com:8080/bar", uriComponents4.toUriString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void expandEncoded() {
|
||||
UriComponentsBuilder.fromPath("/{foo}").build().encode().expand("bar");
|
||||
|
||||
Reference in New Issue
Block a user