Skip to content

Commit

Permalink
Merge pull request #27521 from quarkusio/revert-26495-issue_26116
Browse files Browse the repository at this point in the history
Revert "Allow to provide custom HTTP options in REST Client Reactive"
  • Loading branch information
geoand authored Aug 26, 2022
2 parents 885e25e + d58a209 commit 538835a
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 354 deletions.
72 changes: 0 additions & 72 deletions docs/src/main/asciidoc/rest-client-reactive.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -328,78 +328,6 @@ public class ExtensionsResource {
}
----

== Use Custom HTTP Options

The REST Client Reactive internally uses https://vertx.io/docs/apidocs/io/vertx/core/http/HttpClient.html[the Vert.x HTTP Client] to make the network connections. The REST Client Reactive extensions allows configuring some settings via properties, for example:

- `quarkus.rest-client.client-prefix.connect-timeout` to configure the connect timeout in milliseconds.
- `quarkus.rest-client.client-prefix.max-redirects` to limit the number of redirects.

However, there are many more options within the Vert.x HTTP Client to configure the connections. See all the options in the Vert.x HTTP Client Options API in https://vertx.io/docs/apidocs/io/vertx/core/http/HttpClientOptions.html[this link].

To fully customize the Vert.x HTTP Client instance that the REST Client Reactive is internally using, you can provide your custom HTTP Client Options instance via CDI or when programmatically creating your client.

Let's see an example about how to provide the HTTP Client Options via CDI:

[source,java]
----
package org.acme.rest.client;
import javax.enterprise.inject.Produces;
import io.vertx.core.http.HttpClientOptions;
import io.quarkus.arc.Unremovable;
public static class Configuration {
@Produces
@Unremovable
public HttpClientOptions customHttpClientOptions() {
HttpClientOptions options = new HttpClientOptions();
// ...
return options;
}
}
----

Now, all the REST Clients will be using your custom HTTP Client Options.

Another approach is to provide the custom HTTP Client options when creating the client programmatically:

[source,java]
----
package org.acme.rest.client;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.net.URI;
import java.util.Set;
import io.vertx.core.http.HttpClientOptions;
@Path("/extension")
public class ExtensionsResource {
private final ExtensionsService extensionsService;
public ExtensionsResource() {
HttpClientOptions httpOptions = new HttpClientOptions();
// configure the options
// ...
extensionsService = RestClientBuilder.newBuilder()
.baseUri(URI.create("https://stage.code.quarkus.io/api"))
.register(httpOptions) <1>
.build(ExtensionsService.class);
}
// ...
}
----

<1> the client will use the registered HTTP Client options over the HTTP Client options provided via CDI if any.

== Update the test

Next, we need to update the functional test to reflect the changes made to the endpoint.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import io.quarkus.rest.client.reactive.runtime.ProxyAddressUtil.HostAndPort;
import io.quarkus.restclient.config.RestClientLoggingConfig;
import io.quarkus.restclient.config.RestClientsConfig;
import io.vertx.core.http.HttpClientOptions;

/**
* Builder implementation for MicroProfile Rest Client
Expand Down Expand Up @@ -289,13 +288,6 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
register(mapper.getKey(), mapper.getValue());
}

if (!getConfiguration().isRegistered(HttpClientOptions.class)) {
InstanceHandle<HttpClientOptions> httpClientOptions = Arc.container().instance(HttpClientOptions.class);
if (httpClientOptions.isAvailable()) {
clientBuilder.register(httpClientOptions.get());
}
}

Object defaultMapperDisabled = getConfiguration().getProperty(DEFAULT_MAPPER_DISABLED);
Boolean globallyDisabledMapper = ConfigProvider.getConfig()
.getOptionalValue(DEFAULT_MAPPER_DISABLED, Boolean.class).orElse(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ public class QuarkusRestClientProperties {
* maximum number of redirects for a client call. Works only if the client has `followingRedirects enabled
*/
public static final String MAX_REDIRECTS = "io.quarkus.rest.client.max-redirects";
/**
* maximum length of all headers for HTTP/1.x.
*/
public static final String MAX_HEADER_SIZE = "io.quarkus.rest.client.max-header-size";
/**
* maximum length of the initial line for HTTP/1.x.
*/
public static final String MAX_INITIAL_LINE_LENGTH = "io.quarkus.rest.client.max-initial-line-length";

public static final String READ_TIMEOUT = "io.quarkus.rest.client.read-timeout";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -60,6 +59,7 @@ public class ClientBuilderImpl extends ClientBuilder {
private Integer loggingBodySize = 100;
private MultiQueryParamMode multiQueryParamMode;

private HttpClientOptions httpClientOptions = new HttpClientOptions();
private ClientLogger clientLogger = new DefaultClientLogger();
private String userAgent = "Resteasy Reactive Client";

Expand Down Expand Up @@ -136,6 +136,11 @@ public ClientBuilder proxyUser(String proxyUser) {
return this;
}

public ClientBuilder httpClientOptions(HttpClientOptions httpClientOptions) {
this.httpClientOptions = httpClientOptions;
return this;
}

public ClientBuilder followRedirects(boolean followRedirects) {
this.followRedirects = followRedirects;
return this;
Expand Down Expand Up @@ -166,8 +171,7 @@ public ClientImpl build() {
Buffer keyStore = asBuffer(this.keyStore, keystorePassword);
Buffer trustStore = asBuffer(this.trustStore, EMPTY_CHAR_ARARAY);

HttpClientOptions options = Optional.ofNullable(configuration.getInstance(HttpClientOptions.class))
.orElseGet(HttpClientOptions::new);
HttpClientOptions options = httpClientOptions == null ? new HttpClientOptions() : httpClientOptions;

if (trustAll) {
options.setTrustAll(true);
Expand Down Expand Up @@ -239,7 +243,7 @@ public ClientImpl build() {

clientLogger.setBodySize(loggingBodySize);

return new ClientImpl(options,
return new ClientImpl(httpClientOptions,
configuration,
CLIENT_CONTEXT_RESOLVER.resolve(Thread.currentThread().getContextClassLoader()),
hostnameVerifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECTION_POOL_SIZE;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECTION_TTL;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.CONNECT_TIMEOUT;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.MAX_HEADER_SIZE;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.MAX_INITIAL_LINE_LENGTH;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.MAX_REDIRECTS;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.NAME;
import static org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties.SHARED;
Expand Down Expand Up @@ -98,6 +96,8 @@ public ClientImpl(HttpClientOptions options, ConfigurationImpl configuration, Cl
ClientLogger clientLogger, String userAgent) {
this.userAgent = userAgent;
configuration = configuration != null ? configuration : new ConfigurationImpl(RuntimeType.CLIENT);
// TODO: ssl context
// TODO: hostnameVerifier
this.configuration = configuration;
this.clientContext = clientContext;
this.hostnameVerifier = hostnameVerifier;
Expand Down Expand Up @@ -128,16 +128,6 @@ public Vertx get() {
options.setMaxRedirects((Integer) maxRedirects);
}

Object maxHeaderSize = configuration.getProperty(MAX_HEADER_SIZE);
if (maxHeaderSize != null) {
options.setMaxHeaderSize((Integer) maxHeaderSize);
}

Object maxInitialLineLength = configuration.getProperty(MAX_INITIAL_LINE_LENGTH);
if (maxInitialLineLength != null) {
options.setMaxInitialLineLength((Integer) maxInitialLineLength);
}

Object connectionTTL = configuration.getProperty(CONNECTION_TTL);
if (connectionTTL != null) {
options.setKeepAliveTimeout((int) connectionTTL);
Expand Down
Loading

0 comments on commit 538835a

Please sign in to comment.