Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.kiwiproject.jersey.client;
import static java.util.Objects.nonNull;
import static org.kiwiproject.base.KiwiPreconditions.checkArgumentNotNull;
import static org.kiwiproject.base.KiwiPreconditions.requireNotNull;
import com.google.common.annotations.VisibleForTesting;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.client.WebTarget;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.kiwiproject.jersey.client.exception.MissingServiceRuntimeException;
import org.kiwiproject.registry.client.RegistryClient;
import org.kiwiproject.registry.model.Port.PortType;
import org.kiwiproject.registry.model.ServiceInstance;
import org.kiwiproject.registry.util.ServiceInstancePaths;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* An extension of the JAX-RS {@link Client} interface that provides additional {@code target(...)} methods
* that will find service instances from a registry, e.g. Consul.
*/
@Slf4j
public class RegistryAwareClient implements Client, AutoCloseable {
@Delegate
private final Client client;
@VisibleForTesting
@Getter(AccessLevel.PACKAGE)
private final RegistryClient registryClient;
private final AtomicBoolean closed;
/**
* Creates a new {@link RegistryAwareClient} with the given {@link Client} and {@link RegistryClient}.
*
* @param client the Jersey client to use
* @param registryClient the registry lookup client
*/
public RegistryAwareClient(Client client, RegistryClient registryClient) {
this(client, registryClient, null);
}
/**
* Creates a new {@link RegistryAwareClient} with the given {@link Client}, {@link RegistryClient}
* and {@link Supplier} that will be used to automatically attach request headers to all requests
* made by this client.
*
* If {@code headersSupplier} is {@code null}, it is ignored.
*
* @param client the Jersey client to use
* @param registryClient the registry lookup client
* @param headersSupplier a supplier of headers to attach to requests, may be {@code null}
*/
public RegistryAwareClient(Client client,
RegistryClient registryClient,
@Nullable Supplier