Skip to content

Commit 4a438b9

Browse files
authored
FEATURE: base feign-vertx on Vertx WebClient instead of bare vertx (#2756)
* FEATURE: base feign-vertx on Vertx WebClient instead of bare vertx * REFACTOR: vertx tests
1 parent be8925a commit 4a438b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2058
-248
lines changed

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@
357357
<version>${project.version}</version>
358358
</dependency>
359359

360+
<dependency>
361+
<groupId>${project.groupId}</groupId>
362+
<artifactId>feign-vertx</artifactId>
363+
<version>${project.version}</version>
364+
</dependency>
365+
360366
<dependency>
361367
<groupId>${project.groupId}</groupId>
362368
<artifactId>feign-micrometer</artifactId>

vertx/README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Implementation of Feign on Vertx. Brings you the best of two worlds together :
44
concise syntax of Feign to write client side API on fast, asynchronous and
5-
non-blocking HTTP client of Vertx.
5+
non-blocking WebClient of Vertx.
66

77
## Installation
88

@@ -14,7 +14,6 @@ non-blocking HTTP client of Vertx.
1414
<dependency>
1515
<groupId>io.github.openfeign</groupId>
1616
<artifactId>feign-vertx</artifactId>
17-
<version>14.0</version>
1817
</dependency>
1918
...
2019
</dependencies>
@@ -23,14 +22,14 @@ non-blocking HTTP client of Vertx.
2322
### With Gradle
2423

2524
```groovy
26-
compile group: 'io.github.openfeign', name: 'feign-vertx', version: '14.0'
25+
compile group: 'io.github.openfeign', name: 'feign-vertx'
2726
```
2827

2928
## Compatibility
3029

3130
Feign | Vertx
3231
---------------------- | ----------------------
33-
14.x | 4.x
32+
14.x | 4.x - 5.x
3433

3534
## Usage
3635

@@ -62,15 +61,15 @@ interface IcecreamServiceApi {
6261
Build the client :
6362

6463
```java
65-
Vertx vertx = Vertx.vertx(); // get Vertx instance
64+
WebClient webClient = WebClient.create(vertx); // create Vert.x WebClient
6665

6766
/* Create instance of your API */
6867
IcecreamServiceApi icecreamApi = VertxFeign
6968
.builder()
70-
.vertx(vertx) // provide vertx instance
69+
.webClient(webClient) // provide WebClient instance
7170
.encoder(new JacksonEncoder())
7271
.decoder(new JacksonDecoder())
73-
.target(IcecreamServiceApi.class, "http://www.icecreame.com");
72+
.target(IcecreamServiceApi.class, "https://www.icecream.com");
7473

7574
/* Execute requests asynchronously */
7675
Future<Collection<Flavor>> flavorsFuture = icecreamApi.getAvailableFlavors();

vertx/feign-vertx/pom.xml

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright © 2012 The Feign Authors (feign@commonhaus.dev)
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>io.github.openfeign</groupId>
23+
<artifactId>feign-vertx-parent</artifactId>
24+
<version>13.6-SNAPSHOT</version>
25+
</parent>
26+
27+
<artifactId>feign-vertx</artifactId>
28+
29+
<name>Feign Vertx</name>
30+
<description>Implementation of Feign on Vertx web client.</description>
31+
32+
<properties>
33+
<jackson.version>2.18.2</jackson.version>
34+
</properties>
35+
36+
<dependencyManagement>
37+
<dependencies>
38+
<dependency>
39+
<groupId>com.fasterxml.jackson</groupId>
40+
<artifactId>jackson-bom</artifactId>
41+
<version>${jackson.version}</version>
42+
<type>pom</type>
43+
<scope>import</scope>
44+
</dependency>
45+
</dependencies>
46+
</dependencyManagement>
47+
48+
<dependencies>
49+
50+
<!-- Feign -->
51+
<dependency>
52+
<groupId>io.github.openfeign</groupId>
53+
<artifactId>feign-core</artifactId>
54+
</dependency>
55+
56+
<!-- Vertx -->
57+
<dependency>
58+
<groupId>io.vertx</groupId>
59+
<artifactId>vertx-core</artifactId>
60+
<version>${vertx.version}</version>
61+
<scope>provided</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>io.vertx</groupId>
66+
<artifactId>vertx-web-client</artifactId>
67+
<version>${vertx.version}</version>
68+
<scope>provided</scope>
69+
</dependency>
70+
71+
<!-- Tests -->
72+
<dependency>
73+
<groupId>io.vertx</groupId>
74+
<artifactId>vertx-junit5</artifactId>
75+
<version>${vertx.version}</version>
76+
<scope>test</scope>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>org.assertj</groupId>
81+
<artifactId>assertj-core</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>io.github.openfeign</groupId>
87+
<artifactId>feign-jackson</artifactId>
88+
<scope>test</scope>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>com.fasterxml.jackson.core</groupId>
93+
<artifactId>jackson-annotations</artifactId>
94+
<scope>test</scope>
95+
</dependency>
96+
97+
<dependency>
98+
<groupId>com.fasterxml.jackson.datatype</groupId>
99+
<artifactId>jackson-datatype-jsr310</artifactId>
100+
<scope>test</scope>
101+
</dependency>
102+
103+
<dependency>
104+
<groupId>io.github.openfeign</groupId>
105+
<artifactId>feign-slf4j</artifactId>
106+
<scope>test</scope>
107+
</dependency>
108+
109+
<dependency>
110+
<groupId>org.slf4j</groupId>
111+
<artifactId>slf4j-log4j12</artifactId>
112+
<scope>test</scope>
113+
</dependency>
114+
115+
<dependency>
116+
<groupId>com.github.tomakehurst</groupId>
117+
<artifactId>wiremock-jre8</artifactId>
118+
<scope>test</scope>
119+
<exclusions>
120+
<exclusion>
121+
<groupId>org.junit</groupId>
122+
<artifactId>junit-bom</artifactId>
123+
</exclusion>
124+
</exclusions>
125+
</dependency>
126+
</dependencies>
127+
128+
<build>
129+
<plugins>
130+
<plugin>
131+
<groupId>org.apache.maven.plugins</groupId>
132+
<artifactId>maven-jar-plugin</artifactId>
133+
<executions>
134+
<execution>
135+
<goals>
136+
<goal>test-jar</goal>
137+
</goals>
138+
</execution>
139+
</executions>
140+
</plugin>
141+
</plugins>
142+
</build>
143+
</project>

vertx/src/main/java/feign/VertxFeign.java renamed to vertx/feign-vertx/src/main/java/feign/VertxFeign.java

+22-50
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
import feign.querymap.FieldQueryMapEncoder;
2626
import feign.vertx.VertxDelegatingContract;
2727
import feign.vertx.VertxHttpClient;
28-
import io.vertx.core.Vertx;
29-
import io.vertx.core.http.HttpClient;
30-
import io.vertx.core.http.HttpClientOptions;
31-
import io.vertx.core.http.HttpClientRequest;
28+
import io.vertx.core.buffer.Buffer;
29+
import io.vertx.ext.web.client.HttpRequest;
30+
import io.vertx.ext.web.client.WebClient;
3231
import java.lang.reflect.InvocationHandler;
3332
import java.lang.reflect.Method;
3433
import java.lang.reflect.Proxy;
@@ -92,7 +91,7 @@ public <T> T newInstance(final Target<T> target) {
9291

9392
/** VertxFeign builder. */
9493
public static final class Builder extends Feign.Builder {
95-
private Vertx vertx;
94+
private WebClient webClient;
9695
private final List<RequestInterceptor> requestInterceptors = new ArrayList<>();
9796
private Logger.Level logLevel = Logger.Level.NONE;
9897
private Contract contract = new VertxDelegatingContract(new Contract.Default());
@@ -103,10 +102,9 @@ public static final class Builder extends Feign.Builder {
103102
private QueryMapEncoder queryMapEncoder = new FieldQueryMapEncoder();
104103
private List<Capability> capabilities = new ArrayList<>();
105104
private ErrorDecoder errorDecoder = new ErrorDecoder.Default();
106-
private HttpClientOptions options = new HttpClientOptions();
107105
private long timeout = -1;
108106
private boolean decode404;
109-
private UnaryOperator<HttpClientRequest> requestPreProcessor = UnaryOperator.identity();
107+
private UnaryOperator<HttpRequest<Buffer>> requestPreProcessor = UnaryOperator.identity();
110108

111109
/** Unsupported operation. */
112110
@Override
@@ -122,13 +120,13 @@ public Builder invocationHandlerFactory(
122120
}
123121

124122
/**
125-
* Sets a vertx instance to use to make the client.
123+
* Sets a vertx WebClient.
126124
*
127-
* @param vertx vertx instance
125+
* @param webClient vertx WebClient
128126
* @return this builder
129127
*/
130-
public Builder vertx(final Vertx vertx) {
131-
this.vertx = checkNotNull(vertx, "Argument vertx must be not null");
128+
public Builder webClient(final WebClient webClient) {
129+
this.webClient = checkNotNull(webClient, "Argument webClient must be not null");
132130
return this;
133131
}
134132

@@ -263,34 +261,6 @@ public Builder errorDecoder(final ErrorDecoder errorDecoder) {
263261
return this;
264262
}
265263

266-
/**
267-
* Sets request options using Vert.x {@link HttpClientOptions}.
268-
*
269-
* @param options {@code HttpClientOptions} for full customization of the underlying Vert.x
270-
* {@link HttpClient}
271-
* @return this builder
272-
*/
273-
public Builder options(final HttpClientOptions options) {
274-
this.options = checkNotNull(options, "Argument options must be not null");
275-
return this;
276-
}
277-
278-
/**
279-
* Sets request options using Feign {@link Request.Options}.
280-
*
281-
* @param options Feign {@code Request.Options} object
282-
* @return this builder
283-
*/
284-
@Override
285-
public Builder options(final Request.Options options) {
286-
checkNotNull(options, "Argument options must be not null");
287-
this.options =
288-
new HttpClientOptions()
289-
.setConnectTimeout(options.connectTimeoutMillis())
290-
.setIdleTimeout(options.readTimeoutMillis());
291-
return this;
292-
}
293-
294264
/**
295265
* Configures the amount of time in milliseconds after which if the request does not return any
296266
* data within the timeout period an {@link java.util.concurrent.TimeoutException} fails the
@@ -307,22 +277,22 @@ public Builder timeout(long timeout) {
307277
}
308278

309279
/**
310-
* Defines operation to execute on each {@link HttpClientRequest} before it is sent. Used to
311-
* make setup on request level.
280+
* Defines operation to execute on each {@link HttpRequest} before it sent. Used to make setup
281+
* on request level.
312282
*
313283
* <p>Example:
314284
*
315285
* <pre>
316286
* var client = VertxFeign
317287
* .builder()
318288
* .vertx(vertx)
319-
* .requestPreProcessor(req -&#62; req.putHeader("version", "v1"));
289+
* .requestPreProcessor(req -&#62; req.ssl(true));
320290
* </pre>
321291
*
322292
* @param requestPreProcessor operation to execute on each request
323293
* @return updated request
324294
*/
325-
public Builder requestPreProcessor(UnaryOperator<HttpClientRequest> requestPreProcessor) {
295+
public Builder requestPreProcessor(UnaryOperator<HttpRequest<Buffer>> requestPreProcessor) {
326296
this.requestPreProcessor =
327297
checkNotNull(requestPreProcessor, "Argument requestPreProcessor must be not null");
328298
return this;
@@ -389,19 +359,24 @@ public <T> T target(final Target<T> target) {
389359
return build().newInstance(target);
390360
}
391361

362+
@Override
363+
public Feign.Builder options(final Request.Options options) {
364+
throw new UnsupportedOperationException(
365+
"Options should be provided directly during construction of Vertx WebClient.");
366+
}
367+
392368
@Override
393369
public VertxFeign internalBuild() {
394-
checkNotNull(this.vertx, "Vertx instance wasn't provided in VertxFeign builder");
370+
checkNotNull(
371+
this.webClient, "Vertx WebClient instance wasn't provided in VertxFeign builder");
395372

396-
final VertxHttpClient client =
397-
new VertxHttpClient(vertx, options, timeout, requestPreProcessor);
373+
final VertxHttpClient client = new VertxHttpClient(webClient, timeout, requestPreProcessor);
398374
final VertxMethodHandler.Factory methodHandlerFactory =
399375
new VertxMethodHandler.Factory(
400376
client, retryer, requestInterceptors, logger, logLevel, decode404);
401377
final ParseHandlersByName handlersByName =
402378
new ParseHandlersByName(
403379
contract,
404-
options,
405380
encoder,
406381
decoder,
407382
queryMapEncoder,
@@ -417,7 +392,6 @@ public VertxFeign internalBuild() {
417392

418393
private static final class ParseHandlersByName {
419394
private final Contract contract;
420-
private final HttpClientOptions options;
421395
private final Encoder encoder;
422396
private final Decoder decoder;
423397
private final QueryMapEncoder queryMapEncoder;
@@ -427,15 +401,13 @@ private static final class ParseHandlersByName {
427401

428402
private ParseHandlersByName(
429403
final Contract contract,
430-
final HttpClientOptions options,
431404
final Encoder encoder,
432405
final Decoder decoder,
433406
final QueryMapEncoder queryMapEncoder,
434407
final List<Capability> capabilities,
435408
final ErrorDecoder errorDecoder,
436409
final VertxMethodHandler.Factory factory) {
437410
this.contract = contract;
438-
this.options = options;
439411
this.factory = factory;
440412
this.encoder = encoder;
441413
this.decoder = decoder;

0 commit comments

Comments
 (0)