|
|
@ -40,7 +40,8 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory |
|
|
|
|
|
|
|
|
|
|
|
private LoadBalancerClient loadBalancer; |
|
|
|
private LoadBalancerClient loadBalancer; |
|
|
|
|
|
|
|
|
|
|
|
public RibbonClientHttpRequestFactory(SpringClientFactory clientFactory, LoadBalancerClient loadBalancer) { |
|
|
|
public RibbonClientHttpRequestFactory(SpringClientFactory clientFactory, |
|
|
|
|
|
|
|
LoadBalancerClient loadBalancer) { |
|
|
|
this.clientFactory = clientFactory; |
|
|
|
this.clientFactory = clientFactory; |
|
|
|
this.loadBalancer = loadBalancer; |
|
|
|
this.loadBalancer = loadBalancer; |
|
|
|
} |
|
|
|
} |
|
|
@ -51,18 +52,22 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory |
|
|
|
throws IOException { |
|
|
|
throws IOException { |
|
|
|
String serviceId = originalUri.getHost(); |
|
|
|
String serviceId = originalUri.getHost(); |
|
|
|
if (serviceId == null) { |
|
|
|
if (serviceId == null) { |
|
|
|
throw new IOException("Invalid hostname in the URI [" + originalUri.toASCIIString() + "]"); |
|
|
|
throw new IOException( |
|
|
|
|
|
|
|
"Invalid hostname in the URI [" + originalUri.toASCIIString() + "]"); |
|
|
|
} |
|
|
|
} |
|
|
|
ServiceInstance instance = loadBalancer.choose(serviceId); |
|
|
|
ServiceInstance instance = this.loadBalancer.choose(serviceId); |
|
|
|
if (instance == null) { |
|
|
|
if (instance == null) { |
|
|
|
throw new IllegalStateException("No instances available for " + serviceId); |
|
|
|
throw new IllegalStateException("No instances available for " + serviceId); |
|
|
|
} |
|
|
|
} |
|
|
|
URI uri = this.loadBalancer.reconstructURI(instance, originalUri); |
|
|
|
URI uri = this.loadBalancer.reconstructURI(instance, originalUri); |
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
IClientConfig clientConfig = this.clientFactory.getClientConfig(instance.getServiceId()); |
|
|
|
IClientConfig clientConfig = this.clientFactory |
|
|
|
RestClient client = this.clientFactory.getClient(instance.getServiceId(), RestClient.class); |
|
|
|
.getClientConfig(instance.getServiceId()); |
|
|
|
|
|
|
|
RestClient client = this.clientFactory.getClient(instance.getServiceId(), |
|
|
|
|
|
|
|
RestClient.class); |
|
|
|
HttpRequest.Verb verb = HttpRequest.Verb.valueOf(httpMethod.name()); |
|
|
|
HttpRequest.Verb verb = HttpRequest.Verb.valueOf(httpMethod.name()); |
|
|
|
RibbonLoadBalancerContext context = this.clientFactory.getLoadBalancerContext(serviceId); |
|
|
|
RibbonLoadBalancerContext context = this.clientFactory |
|
|
|
|
|
|
|
.getLoadBalancerContext(serviceId); |
|
|
|
|
|
|
|
|
|
|
|
Server server = null; |
|
|
|
Server server = null; |
|
|
|
if (instance instanceof RibbonServer) { |
|
|
|
if (instance instanceof RibbonServer) { |
|
|
@ -70,7 +75,7 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RibbonStatsRecorder statsRecorder = new RibbonStatsRecorder(context, server); |
|
|
|
RibbonStatsRecorder statsRecorder = new RibbonStatsRecorder(context, server); |
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
return new RibbonHttpRequest(uri, verb, client, clientConfig, statsRecorder); |
|
|
|
return new RibbonHttpRequest(uri, verb, client, clientConfig, statsRecorder); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|