
artoria.feign.ConfigurableFeignClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artoria-extend Show documentation
Show all versions of artoria-extend Show documentation
Artoria is a java technology framework based on the facade pattern.
The newest version!
package artoria.feign;
import feign.Client;
import feign.Request;
import feign.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import java.io.IOException;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import static artoria.common.Constants.EMPTY_STRING;
import static artoria.common.Constants.QUESTION_MARK;
import static artoria.util.StringUtils.isNotBlank;
/**
* The configurable feign client.
* @author Kahle
* TODO: 2023/6/2 Deletable
*/
@Deprecated
public class ConfigurableFeignClient extends LoadBalancerFeignClient {
private static final Logger log = LoggerFactory.getLogger(ConfigurableFeignClient.class);
private final Map configInfo;
private final Client delegate;
public ConfigurableFeignClient(Client delegate,
CachingSpringLoadBalancerFactory lbClientFactory,
SpringClientFactory clientFactory,
Map configInfo) {
super(delegate, lbClientFactory, clientFactory);
if (configInfo == null) { configInfo = Collections.emptyMap(); }
this.configInfo = configInfo;
this.delegate = delegate;
}
@Override
public Response execute(Request request, Request.Options options) throws IOException {
// Variable definition.
URI nowUri = URI.create(request.url());
String query = nowUri.getQuery();
String path = nowUri.getPath();
String host = nowUri.getHost();
String target;
query = isNotBlank(query)
? QUESTION_MARK + query : EMPTY_STRING;
// Check whether configuration information exists.
boolean existConfig = isNotBlank(target = configInfo.get(host))
|| isNotBlank(target = configInfo.get(host + path));
// Go to the address information in the configuration.
if (existConfig) {
// Rebuild the request object.
String url = target + path + query;
request = Request.create(request.httpMethod(), url,
request.headers(), request.body(), request.charset(), request.requestTemplate());
log.info("Feign executing {} {}", request.httpMethod(), request.url());
return delegate.execute(request, options);
}
return super.execute(request, options);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy