I recently encountered some unexpected behaviour and was wondering if this was in fact intended functionality when using WebClient. With a client config as shown below, the uri variables in the template are being overridden with the fields from a POJO used as an arg to bodyValue.
class ExampleRequest {
private String namespace = "jar";
private String service = "zoo";
...
}
...
this.client = WebClient.builder()
.baseUrl("http://{service}.{namespace}.svc.cluster.local")
.defaultUriVariables(Map.of("service", "foo", "namespace", "bar"))
.build();
this.client.post()
.uri("/baz")
.bodyValue(new ExampleRequest())
.retrieve()
...
The above ends up calling out to http://zoo.jar.svc.cluster.local/baz
, not http://foo.bar.svc.cluster.local/baz
. I wasn't expecting the body of the message in this instance to be picked up as uri variables. :confused:
This seems strange to me, but if this is expected could point me to the source/docs of where this expansion is taking place..?
Could you please use standard HashMap implementation and recheck? I tested locally for me it is working as expected, I mean foo and bar chosen: