Skip to content

Commit 5cb3af7

Browse files
committed
Add Builder to HttpServiceProxyFactory
HttpServiceProxyFactory now support programmatic initialization through a builder, while bean-style initialization is deprecated. See gh-29296
1 parent e03abc9 commit 5cb3af7

File tree

14 files changed

+410
-104
lines changed

14 files changed

+410
-104
lines changed

spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java

+372-68
Large diffs are not rendered by default.

spring-web/src/test/java/org/springframework/web/service/invoker/CookieValueArgumentResolverTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class CookieValueArgumentResolverTests {
4242

4343
@BeforeEach
4444
void setUp() throws Exception {
45-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
46-
proxyFactory.afterPropertiesSet();
45+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
4746
this.service = proxyFactory.createClient(Service.class);
4847
}
4948

spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class HttpMethodArgumentResolverTests {
4343

4444
@BeforeEach
4545
void setUp() throws Exception {
46-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
46+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
4747
proxyFactory.afterPropertiesSet();
4848
this.service = proxyFactory.createClient(Service.class);
4949
}

spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class HttpServiceMethodTests {
6464

6565
@BeforeEach
6666
void setUp() throws Exception {
67-
this.proxyFactory = new HttpServiceProxyFactory(this.client);
67+
this.proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
6868
this.proxyFactory.afterPropertiesSet();
6969
}
7070

@@ -174,10 +174,10 @@ void methodAnnotatedService() {
174174
}
175175

176176
@Test
177-
void typeAndMethodAnnotatedService() throws Exception {
178-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
179-
proxyFactory.setEmbeddedValueResolver(value -> (value.equals("${baseUrl}") ? "/base" : value));
180-
proxyFactory.afterPropertiesSet();
177+
void typeAndMethodAnnotatedService() {
178+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client)
179+
.embeddedValueResolver(value -> (value.equals("${baseUrl}") ? "/base" : value))
180+
.build();
181181

182182
MethodLevelAnnotatedService service = proxyFactory.createClient(TypeAndMethodLevelAnnotatedService.class);
183183

spring-web/src/test/java/org/springframework/web/service/invoker/NamedValueArgumentResolverTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ class NamedValueArgumentResolverTests {
6161

6262
@BeforeEach
6363
void setUp() throws Exception {
64-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
65-
proxyFactory.addCustomArgumentResolver(this.argumentResolver);
64+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client)
65+
.customArgumentResolver(this.argumentResolver)
66+
.build();
6667
proxyFactory.afterPropertiesSet();
6768

6869
this.service = proxyFactory.createClient(Service.class);

spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PathVariableArgumentResolverTests {
4141

4242
@BeforeEach
4343
void setUp() throws Exception {
44-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
44+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
4545
proxyFactory.afterPropertiesSet();
4646
this.service = proxyFactory.createClient(Service.class);
4747
}

spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class RequestAttributeArgumentResolverTests {
4040

4141
@BeforeEach
4242
void setUp() throws Exception {
43-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
44-
proxyFactory.afterPropertiesSet();
43+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
4544
this.service = proxyFactory.createClient(Service.class);
4645
}
4746

spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public class RequestBodyArgumentResolverTests {
4545

4646
@BeforeEach
4747
void setUp() throws Exception {
48-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
49-
proxyFactory.afterPropertiesSet();
48+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
5049
this.service = proxyFactory.createClient(Service.class);
5150
}
5251

spring-web/src/test/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolverTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class RequestHeaderArgumentResolverTests {
4343

4444
@BeforeEach
4545
void setUp() throws Exception {
46-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
47-
proxyFactory.afterPropertiesSet();
46+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
4847
this.service = proxyFactory.createClient(Service.class);
4948
}
5049

spring-web/src/test/java/org/springframework/web/service/invoker/RequestParamArgumentResolverTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public class RequestParamArgumentResolverTests {
4545

4646
@BeforeEach
4747
void setUp() throws Exception {
48-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
49-
proxyFactory.afterPropertiesSet();
48+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
5049
this.service = proxyFactory.createClient(Service.class);
5150
}
5251

spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public class UrlArgumentResolverTests {
4040

4141
@BeforeEach
4242
void setUp() throws Exception {
43-
HttpServiceProxyFactory proxyFactory = new HttpServiceProxyFactory(this.client);
44-
proxyFactory.afterPropertiesSet();
43+
HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory.builder(this.client).build();
4544
this.service = proxyFactory.createClient(Service.class);
4645
}
4746

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ else if (requestValues.getBody() != null) {
124124
}
125125

126126

127+
/**
128+
* Create a {@link WebClientAdapter} for the given {@code WebClient} instance.
129+
* @param webClient the client to use
130+
* @return the created adapter instance
131+
*/
132+
public static WebClientAdapter forClient(WebClient webClient) {
133+
return new WebClientAdapter(webClient);
134+
}
135+
127136
/**
128137
* Static method to create a {@link HttpServiceProxyFactory} configured to
129138
* use the given {@link WebClient} instance. Effectively a shortcut for:
@@ -133,7 +142,11 @@ else if (requestValues.getBody() != null) {
133142
* </pre>
134143
* @param webClient the client to use
135144
* @return the created {@code HttpServiceProxyFactory} instance
145+
* @deprecated in favor of using {@link #forClient(WebClient)} and
146+
* {@link HttpServiceProxyFactory#builder(HttpClientAdapter)}
136147
*/
148+
@SuppressWarnings("removal")
149+
@Deprecated(since = "6.0.0-RC1", forRemoval = true)
137150
public static HttpServiceProxyFactory createHttpServiceProxyFactory(WebClient webClient) {
138151
return new HttpServiceProxyFactory(new WebClientAdapter(webClient));
139152
}
@@ -143,18 +156,12 @@ public static HttpServiceProxyFactory createHttpServiceProxyFactory(WebClient we
143156
* a {@link WebClient.Builder} and uses it to create the client.
144157
* @param webClientBuilder a builder to create the client to use with
145158
* @return the created {@code HttpServiceProxyFactory} instance
159+
* @deprecated in favor of using {@link #forClient(WebClient)} and
160+
* {@link HttpServiceProxyFactory#builder(HttpClientAdapter)}
146161
*/
162+
@Deprecated(since = "6.0.0-RC1", forRemoval = true)
147163
public static HttpServiceProxyFactory createHttpServiceProxyFactory(WebClient.Builder webClientBuilder) {
148164
return createHttpServiceProxyFactory(webClientBuilder.build());
149165
}
150166

151-
/**
152-
* Create a {@link WebClientAdapter} for the given {@code WebClient} instance.
153-
* @param webClient the client to use
154-
* @return the created adapter instance
155-
*/
156-
public static WebClientAdapter forClient(WebClient webClient) {
157-
return new WebClientAdapter(webClient);
158-
}
159-
160167
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ private TestHttpService initHttpService() throws Exception {
105105
return initHttpService(webClient);
106106
}
107107

108-
private TestHttpService initHttpService(WebClient webClient) throws Exception {
109-
HttpServiceProxyFactory factory = WebClientAdapter.createHttpServiceProxyFactory(webClient);
110-
factory.afterPropertiesSet();
111-
return factory.createClient(TestHttpService.class);
108+
private TestHttpService initHttpService(WebClient webClient) {
109+
return HttpServiceProxyFactory.builder()
110+
.clientAdapter(WebClientAdapter.forClient(webClient))
111+
.build()
112+
.createClient(TestHttpService.class);
112113
}
113114

114115
private void prepareResponse(Consumer<MockResponse> consumer) {

src/docs/asciidoc/integration.adoc

+1-2
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ Two, create a proxy that will perform the declared HTTP exchanges:
390390
[source,java,indent=0,subs="verbatim,quotes"]
391391
----
392392
WebClient client = WebClient.builder().baseUrl("https://api.github.com/").build();
393-
HttpServiceProxyFactory factory = WebClientAdapter.createHttpServiceProxyFactory(client);
394-
factory.afterPropertiesSet();
393+
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();
395394
396395
RepositoryService service = factory.createClient(RepositoryService.class);
397396
----

0 commit comments

Comments
 (0)