I am using spring-web version 5.0.6.RELEASE.
I tried calling the GET exchange method with the URI variable map, but these URI variables are not set to the final URL which hit the external system.
My code snippet is as below
Map<String,Object> queryParam = new HashMap<>();
queryParam.put("id", 1);
queryParam.put("name", "ABC");
ResponseEntity<List<MyResponse>> responseEntity = restTemplate.exchange(serverUrl.toString(),HttpMethod.GET,null,
new ParameterizedTypeReference<List<MyResponse>>(){}, queryParam);
When I debugged , I found RestTemplate.execute
method have a URI creation code
URI expanded = getUriTemplateHandler().expand(url, uriVariables);
which does not set the URI params to URI
class.
I furthur debugged and found that in DefaultUriBuilderFactory.build()
method the URI variable is not passed or set to URI component builder
UriComponents uriComponents = this.uriComponentsBuilder.build().expand(uriVars);
which causes
HierarchicalUriComponents expandInternal(UriTemplateVariables uriVariables)
method of HierarchicalUriComponents
class to set the URI variable as empty.
Can anyone help me understand if I am doing anything wrong here or Spring web have any bug for such cases?