Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the ability to automatically standup an HTTP proxy for the REST Client #41804

Merged
merged 2 commits into from
Jul 18, 2024
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 @@ -22,4 +22,29 @@ public class RestClientBuildConfig {
*/
@ConfigItem
public Optional<String> scope;

/**
* If set to true, then Quarkus will ensure that all calls from the rest client go through a local proxy
* server (that is managed by Quarkus).
* This can be very useful for capturing network traffic to a service that use HTTPS.
* <p>
* This property is not applicable to the RESTEasy Client, only the Quarkus Rest client (formerly RESTEasy Reactive client).
* <p>
* This property only applicable to dev and test mode.
*/
@ConfigItem(defaultValue = "false")
public boolean enableLocalProxy;

/**
* This setting is used to select which proxy provider to use if there are multiple ones.
* It only applies if {@code enable-local-proxy} is true.
* <p>
* The algorithm for picking between multiple provider is the following:
* <ul>
* <li>If only the default is around, use it (it's name is {@code default})</li>
* <li>If there is only one besides the default, use it</li>
* <li>If there are multiple ones, fail</li>
* </ul>
*/
public Optional<String> localProxyProvider;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class RestClientConfig {
EMPTY = new RestClientConfig();
EMPTY.url = Optional.empty();
EMPTY.uri = Optional.empty();
EMPTY.overrideUri = Optional.empty();
EMPTY.providers = Optional.empty();
EMPTY.connectTimeout = Optional.empty();
EMPTY.readTimeout = Optional.empty();
Expand Down Expand Up @@ -75,6 +76,15 @@ public class RestClientConfig {
@ConfigItem
public Optional<String> uri;

/**
* This property is only meant to be set by advanced configurations to override whatever value was set for the uri or url.
* The override is done using the REST Client class name configuration syntax.
* <p>
* This property is not applicable to the RESTEasy Client, only the Quarkus Rest client (formerly RESTEasy Reactive client).
*/
@ConfigItem
public Optional<String> overrideUri;

/**
* Map where keys are fully-qualified provider classnames to include in the client, and values are their integer
* priorities. The equivalent of the `@RegisterProvider` annotation.
Expand Down Expand Up @@ -314,6 +324,7 @@ public static RestClientConfig load(String configKey) {

instance.url = getConfigValue(configKey, "url", String.class);
instance.uri = getConfigValue(configKey, "uri", String.class);
instance.overrideUri = getConfigValue(configKey, "override-uri", String.class);
instance.providers = getConfigValue(configKey, "providers", String.class);
instance.connectTimeout = getConfigValue(configKey, "connect-timeout", Long.class);
instance.readTimeout = getConfigValue(configKey, "read-timeout", Long.class);
Expand Down Expand Up @@ -357,6 +368,7 @@ public static RestClientConfig load(Class<?> interfaceClass) {

instance.url = getConfigValue(interfaceClass, "url", String.class);
instance.uri = getConfigValue(interfaceClass, "uri", String.class);
instance.overrideUri = getConfigValue(interfaceClass, "override-uri", String.class);
instance.providers = getConfigValue(interfaceClass, "providers", String.class);
instance.connectTimeout = getConfigValue(interfaceClass, "connect-timeout", Long.class);
instance.readTimeout = getConfigValue(interfaceClass, "read-timeout", Long.class);
Expand Down Expand Up @@ -394,7 +406,7 @@ public static RestClientConfig load(Class<?> interfaceClass) {
return instance;
}

private static <T> Optional<T> getConfigValue(String configKey, String fieldName, Class<T> type) {
public static <T> Optional<T> getConfigValue(String configKey, String fieldName, Class<T> type) {
final Config config = ConfigProvider.getConfig();
Optional<T> optional = config.getOptionalValue(composePropertyKey(configKey, fieldName), type);
if (optional.isEmpty()) { // try to find property with quoted configKey
Expand All @@ -403,7 +415,7 @@ private static <T> Optional<T> getConfigValue(String configKey, String fieldName
return optional;
}

private static <T> Optional<T> getConfigValue(Class<?> clientInterface, String fieldName, Class<T> type) {
public static <T> Optional<T> getConfigValue(Class<?> clientInterface, String fieldName, Class<T> type) {
final Config config = ConfigProvider.getConfig();
// first try interface full name
Optional<T> optional = config.getOptionalValue(composePropertyKey('"' + clientInterface.getName() + '"', fieldName),
Expand Down
4 changes: 4 additions & 0 deletions extensions/resteasy-reactive/rest-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-tls-registry-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-http-proxy</artifactId>
</dependency>
<!-- test dependencies: -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.quarkus.rest.client.reactive.deployment;

import java.util.Objects;
import java.util.Optional;

import org.jboss.jandex.ClassInfo;

import io.quarkus.builder.item.MultiBuildItem;

/**
* Contains information about the REST Clients that have been discovered via
* {@link org.eclipse.microprofile.rest.client.inject.RegisterRestClient}
*/
public final class RegisteredRestClientBuildItem extends MultiBuildItem {

private final ClassInfo classInfo;
private final Optional<String> configKey;
private final Optional<String> defaultBaseUri;

public RegisteredRestClientBuildItem(ClassInfo classInfo, Optional<String> configKey, Optional<String> defaultBaseUri) {
this.classInfo = Objects.requireNonNull(classInfo);
this.configKey = Objects.requireNonNull(configKey);
this.defaultBaseUri = Objects.requireNonNull(defaultBaseUri);
}

public ClassInfo getClassInfo() {
return classInfo;
}

public Optional<String> getConfigKey() {
return configKey;
}

public Optional<String> getDefaultBaseUri() {
return defaultBaseUri;
}
}
Loading
Loading