Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import io.vertx.ext.web.client.HttpRequest;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
{{#useVertx5}}
import io.vertx.core.http.PoolOptions;
{{/useVertx5}}

{{#jsr310}}
import java.time.OffsetDateTime;
Expand All @@ -56,6 +59,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
protected final Vertx vertx;
protected final JsonObject config;
protected final String identifier;
{{#useVertx5}}
protected final JsonObject poolConfig;
{{/useVertx5}}

protected MultiMap defaultHeaders = MultiMap.caseInsensitiveMultiMap();
protected MultiMap defaultCookies = MultiMap.caseInsensitiveMultiMap();
Expand All @@ -66,9 +72,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
protected String downloadsDir = "";
protected int timeout = -1;

{{#useVertx5}}
public ApiClient(Vertx vertx, JsonObject config) {
this(vertx, config, new JsonObject());
}

{{/useVertx5}}
public ApiClient(Vertx vertx, JsonObject config{{#useVertx5}}, JsonObject poolConfig{{/useVertx5}}) {
Objects.requireNonNull(vertx, "Vertx must not be null");
Objects.requireNonNull(config, "Config must not be null");
{{#useVertx5}}
Objects.requireNonNull(poolConfig, "PoolConfig must not be null");
{{/useVertx5}}

this.vertx = vertx;

Expand Down Expand Up @@ -109,6 +124,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
this.config = config;
this.identifier = UUID.randomUUID().toString();
this.timeout = config.getInteger("timeout", -1);
{{#useVertx5}}
this.poolConfig = poolConfig;
{{/useVertx5}}
}

public Vertx getVertx() {
Expand All @@ -128,7 +146,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
String webClientIdentifier = "web-client-" + identifier;
WebClient webClient = this.vertx.getOrCreateContext().get(webClientIdentifier);
if (webClient == null) {
webClient = buildWebClient(vertx, config);
webClient = buildWebClient(vertx, config{{#useVertx5}}, poolConfig{{/useVertx5}});
this.vertx.getOrCreateContext().put(webClientIdentifier, webClient);
}
return webClient;
Expand Down Expand Up @@ -707,13 +725,13 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
* @param vertx Vertx
* @return WebClient
*/
protected WebClient buildWebClient(Vertx vertx, JsonObject config) {
protected WebClient buildWebClient(Vertx vertx, JsonObject config{{#useVertx5}}, JsonObject poolConfig{{/useVertx5}}) {

if (!config.containsKey("userAgent")) {
config.put("userAgent", "{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{artifactVersion}}}/java{{/httpUserAgent}}");
}

return WebClient.create(vertx, new WebClientOptions(config));
return WebClient.create(vertx, new WebClientOptions(config){{#useVertx5}}, new PoolOptions(poolConfig){{/useVertx5}});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import io.vertx.core.http.PoolOptions;

import java.time.OffsetDateTime;
import java.text.DateFormat;
Expand All @@ -60,6 +61,7 @@ public class ApiClient extends JavaTimeFormatter {
protected final Vertx vertx;
protected final JsonObject config;
protected final String identifier;
protected final JsonObject poolConfig;

protected MultiMap defaultHeaders = MultiMap.caseInsensitiveMultiMap();
protected MultiMap defaultCookies = MultiMap.caseInsensitiveMultiMap();
Expand All @@ -71,8 +73,13 @@ public class ApiClient extends JavaTimeFormatter {
protected int timeout = -1;

public ApiClient(Vertx vertx, JsonObject config) {
this(vertx, config, new JsonObject());
}

public ApiClient(Vertx vertx, JsonObject config, JsonObject poolConfig) {
Objects.requireNonNull(vertx, "Vertx must not be null");
Objects.requireNonNull(config, "Config must not be null");
Objects.requireNonNull(poolConfig, "PoolConfig must not be null");

this.vertx = vertx;

Expand Down Expand Up @@ -112,6 +119,7 @@ public ApiClient(Vertx vertx, JsonObject config) {
this.config = config;
this.identifier = UUID.randomUUID().toString();
this.timeout = config.getInteger("timeout", -1);
this.poolConfig = poolConfig;
}

public Vertx getVertx() {
Expand All @@ -131,7 +139,7 @@ public synchronized WebClient getWebClient() {
String webClientIdentifier = "web-client-" + identifier;
WebClient webClient = this.vertx.getOrCreateContext().get(webClientIdentifier);
if (webClient == null) {
webClient = buildWebClient(vertx, config);
webClient = buildWebClient(vertx, config, poolConfig);
this.vertx.getOrCreateContext().put(webClientIdentifier, webClient);
}
return webClient;
Expand Down Expand Up @@ -650,13 +658,13 @@ protected <T> Handler<AsyncResult<HttpResponse<Buffer>>> buildResponseHandler(Ty
* @param vertx Vertx
* @return WebClient
*/
protected WebClient buildWebClient(Vertx vertx, JsonObject config) {
protected WebClient buildWebClient(Vertx vertx, JsonObject config, JsonObject poolConfig) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Changing the protected buildWebClient hook from 2 args to 3 args breaks downstream overrides and can silently drop custom WebClient configuration.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/vertx5-supportVertxFuture/src/main/java/org/openapitools/client/ApiClient.java, line 661:

<comment>Changing the protected `buildWebClient` hook from 2 args to 3 args breaks downstream overrides and can silently drop custom WebClient configuration.</comment>

<file context>
@@ -650,13 +658,13 @@ protected <T> Handler<AsyncResult<HttpResponse<Buffer>>> buildResponseHandler(Ty
      * @return WebClient
      */
-    protected WebClient buildWebClient(Vertx vertx, JsonObject config) {
+    protected WebClient buildWebClient(Vertx vertx, JsonObject config, JsonObject poolConfig) {
 
         if (!config.containsKey("userAgent")) {
</file context>


if (!config.containsKey("userAgent")) {
config.put("userAgent", "OpenAPI-Generator/1.0.0/java");
}

return WebClient.create(vertx, new WebClientOptions(config));
return WebClient.create(vertx, new WebClientOptions(config), new PoolOptions(poolConfig));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import io.vertx.core.http.PoolOptions;

import java.time.OffsetDateTime;
import java.text.DateFormat;
Expand All @@ -60,6 +61,7 @@ public class ApiClient extends JavaTimeFormatter {
protected final Vertx vertx;
protected final JsonObject config;
protected final String identifier;
protected final JsonObject poolConfig;

protected MultiMap defaultHeaders = MultiMap.caseInsensitiveMultiMap();
protected MultiMap defaultCookies = MultiMap.caseInsensitiveMultiMap();
Expand All @@ -71,8 +73,13 @@ public class ApiClient extends JavaTimeFormatter {
protected int timeout = -1;

public ApiClient(Vertx vertx, JsonObject config) {
this(vertx, config, new JsonObject());
}

public ApiClient(Vertx vertx, JsonObject config, JsonObject poolConfig) {
Objects.requireNonNull(vertx, "Vertx must not be null");
Objects.requireNonNull(config, "Config must not be null");
Objects.requireNonNull(poolConfig, "PoolConfig must not be null");

this.vertx = vertx;

Expand Down Expand Up @@ -112,6 +119,7 @@ public ApiClient(Vertx vertx, JsonObject config) {
this.config = config;
this.identifier = UUID.randomUUID().toString();
this.timeout = config.getInteger("timeout", -1);
this.poolConfig = poolConfig;
}

public Vertx getVertx() {
Expand All @@ -131,7 +139,7 @@ public synchronized WebClient getWebClient() {
String webClientIdentifier = "web-client-" + identifier;
WebClient webClient = this.vertx.getOrCreateContext().get(webClientIdentifier);
if (webClient == null) {
webClient = buildWebClient(vertx, config);
webClient = buildWebClient(vertx, config, poolConfig);
this.vertx.getOrCreateContext().put(webClientIdentifier, webClient);
}
return webClient;
Expand Down Expand Up @@ -650,13 +658,13 @@ protected <T> Handler<AsyncResult<HttpResponse<Buffer>>> buildResponseHandler(Ty
* @param vertx Vertx
* @return WebClient
*/
protected WebClient buildWebClient(Vertx vertx, JsonObject config) {
protected WebClient buildWebClient(Vertx vertx, JsonObject config, JsonObject poolConfig) {

if (!config.containsKey("userAgent")) {
config.put("userAgent", "OpenAPI-Generator/1.0.0/java");
}

return WebClient.create(vertx, new WebClientOptions(config));
return WebClient.create(vertx, new WebClientOptions(config), new PoolOptions(poolConfig));
}


Expand Down
Loading