Add IPv6 support in RestTemplate
Prior to this commit, RestTemplate would not would not accept IPv6 raw addresses in URLs because UriComponentsBuilder would not parse/encode the Host part correctly. The UriComponentsBuilder now parses and encode raw IPv6 addresses in the "[1abc:2abc:3abc::5ABC:6abc]" format and also supports the use of IPv6 scope_ids (see JDK8 java.net.Inet6Address), like "[1abc:2abc:3abc::5ABC:6abc%eth0]". Issue: SPR-10539
This commit is contained in:
@@ -169,6 +169,31 @@ public class UriComponentsBuilderTests {
|
||||
assertEquals("https", UriComponentsBuilder.fromHttpUrl("HTTPS://www.google.com").build().getScheme());
|
||||
}
|
||||
|
||||
// SPR-10539
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void fromHttpUrlStringInvalidIPv6Host() throws URISyntaxException {
|
||||
UriComponents result = UriComponentsBuilder
|
||||
.fromHttpUrl("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource").build().encode();
|
||||
}
|
||||
|
||||
// SPR-10539
|
||||
|
||||
@Test
|
||||
public void fromUriStringIPv6Host() throws URISyntaxException {
|
||||
UriComponents result = UriComponentsBuilder
|
||||
.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc]:8080/resource").build().encode();
|
||||
assertEquals("[1abc:2abc:3abc::5ABC:6abc]",result.getHost());
|
||||
|
||||
UriComponents resultWithScopeId = UriComponentsBuilder
|
||||
.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc%eth0]:8080/resource").build().encode();
|
||||
assertEquals("[1abc:2abc:3abc::5ABC:6abc%25eth0]",resultWithScopeId.getHost());
|
||||
|
||||
UriComponents resultIPv4compatible = UriComponentsBuilder
|
||||
.fromUriString("http://[::192.168.1.1]:8080/resource").build().encode();
|
||||
assertEquals("[::192.168.1.1]",resultIPv4compatible.getHost());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void path() throws URISyntaxException {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");
|
||||
|
||||
Reference in New Issue
Block a user