Skip to content

Commit 279508a

Browse files
committed
Merge pull request #22705 from jhaeyaert/22371
2 parents ed70978 + e0c2a1c commit 279508a

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java

+6
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ public RequestBodySpec uri(String uriTemplate, Map<String, ?> uriVariables) {
184184
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));
185185
}
186186

187+
@Override
188+
public RequestBodySpec uri(String uriTemplate, Function<UriBuilder, URI> uriFunction) {
189+
attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate);
190+
return uri(uriFunction.apply(uriBuilderFactory.uriString(uriTemplate)));
191+
}
192+
187193
@Override
188194
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
189195
return uri(uriFunction.apply(uriBuilderFactory.builder()));

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -349,8 +349,15 @@ interface UriSpec<S extends RequestHeadersSpec<?>> {
349349
S uri(String uri, Map<String, ?> uriVariables);
350350

351351
/**
352-
* Build the URI for the request using the {@link UriBuilderFactory}
353-
* configured for this client.
352+
* Specify the URI starting with a URI template and finishing off with a
353+
* {@link UriBuilder} created from the template.
354+
* @since 5.2
355+
*/
356+
S uri(String uri, Function<UriBuilder, URI> uriFunction);
357+
358+
/**
359+
* Specify the URI by through a {@link UriBuilder}.
360+
* @see #uri(String, Function)
354361
*/
355362
S uri(Function<UriBuilder, URI> uriFunction);
356363
}

spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultWebClientTests.java

+11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ public void uriBuilder() {
8484
assertEquals("/base/path?q=12", request.url().toString());
8585
}
8686

87+
@Test // gh-22705
88+
public void uriBuilderWithUriTemplate() {
89+
this.builder.build().get()
90+
.uri("/path/{id}", builder -> builder.queryParam("q", "12").build("identifier"))
91+
.exchange().block(Duration.ofSeconds(10));
92+
93+
ClientRequest request = verifyAndGetRequest();
94+
assertEquals("/base/path/identifier?q=12", request.url().toString());
95+
assertEquals("/path/{id}", request.attribute(WebClient.class.getName() + ".uriTemplate").get());
96+
}
97+
8798
@Test
8899
public void uriBuilderWithPathOverride() {
89100
this.builder.build().get()

0 commit comments

Comments
 (0)