Add defaultUriVariables property to RestTemplate
Issue: SPR-14147
This commit is contained in:
@@ -49,6 +49,22 @@ public class DefaultUriTemplateHandlerTests {
|
||||
assertEquals("http://localhost:8080/context/myapiresource", actual.toString());
|
||||
}
|
||||
|
||||
@Test // SPR-14147
|
||||
public void defaultUriVariables() throws Exception {
|
||||
Map<String, String> defaultVars = new HashMap<>(2);
|
||||
defaultVars.put("host", "api.example.com");
|
||||
defaultVars.put("port", "443");
|
||||
this.handler.setDefaultUriVariables(defaultVars);
|
||||
|
||||
Map<String, Object> vars = new HashMap<>(1);
|
||||
vars.put("id", 123L);
|
||||
|
||||
String template = "https://{host}:{port}/v42/customers/{id}";
|
||||
URI actual = this.handler.expand(template, vars);
|
||||
|
||||
assertEquals("https://api.example.com:443/v42/customers/123", actual.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsePathIsOff() throws Exception {
|
||||
this.handler.setParsePath(false);
|
||||
@@ -114,4 +130,20 @@ public class DefaultUriTemplateHandlerTests {
|
||||
assertEquals("http://www.example.com/user/john%3Bdoe/dashboard", actual.toString());
|
||||
}
|
||||
|
||||
@Test // SPR-14147
|
||||
public void strictEncodingAndDefaultUriVariables() throws Exception {
|
||||
Map<String, String> defaultVars = new HashMap<>(1);
|
||||
defaultVars.put("host", "www.example.com");
|
||||
this.handler.setDefaultUriVariables(defaultVars);
|
||||
this.handler.setStrictEncoding(true);
|
||||
|
||||
Map<String, Object> vars = new HashMap<>(1);
|
||||
vars.put("userId", "john;doe");
|
||||
|
||||
String template = "http://{host}/user/{userId}/dashboard";
|
||||
URI actual = this.handler.expand(template, vars);
|
||||
|
||||
assertEquals("http://www.example.com/user/john%3Bdoe/dashboard", actual.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user