Browse Source

Whitespace

pull/6/head
Dave Syer 9 years ago
parent
commit
2670890845
  1. 39
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java

39
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java

@ -38,39 +38,44 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory @@ -38,39 +38,44 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory
private final SpringClientFactory clientFactory;
private LoadBalancerClient loadBalancer;
private LoadBalancerClient loadBalancer;
public RibbonClientHttpRequestFactory(SpringClientFactory clientFactory, LoadBalancerClient loadBalancer) {
public RibbonClientHttpRequestFactory(SpringClientFactory clientFactory,
LoadBalancerClient loadBalancer) {
this.clientFactory = clientFactory;
this.loadBalancer = loadBalancer;
this.loadBalancer = loadBalancer;
}
@Override
@SuppressWarnings("deprecation")
public ClientHttpRequest createRequest(URI originalUri, HttpMethod httpMethod)
throws IOException {
String serviceId = originalUri.getHost();
if (serviceId == null) {
throw new IOException("Invalid hostname in the URI [" + originalUri.toASCIIString() + "]");
}
ServiceInstance instance = loadBalancer.choose(serviceId);
String serviceId = originalUri.getHost();
if (serviceId == null) {
throw new IOException(
"Invalid hostname in the URI [" + originalUri.toASCIIString() + "]");
}
ServiceInstance instance = this.loadBalancer.choose(serviceId);
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);
//@formatter:off
IClientConfig clientConfig = this.clientFactory.getClientConfig(instance.getServiceId());
RestClient client = this.clientFactory.getClient(instance.getServiceId(), RestClient.class);
URI uri = this.loadBalancer.reconstructURI(instance, originalUri);
IClientConfig clientConfig = this.clientFactory
.getClientConfig(instance.getServiceId());
RestClient client = this.clientFactory.getClient(instance.getServiceId(),
RestClient.class);
HttpRequest.Verb verb = HttpRequest.Verb.valueOf(httpMethod.name());
RibbonLoadBalancerContext context = this.clientFactory.getLoadBalancerContext(serviceId);
RibbonLoadBalancerContext context = this.clientFactory
.getLoadBalancerContext(serviceId);
Server server = null;
if (instance instanceof RibbonServer) {
server = ((RibbonServer)instance).getServer();
server = ((RibbonServer) instance).getServer();
}
RibbonStatsRecorder statsRecorder = new RibbonStatsRecorder(context, server);
//@formatter:on
RibbonStatsRecorder statsRecorder = new RibbonStatsRecorder(context, server);
return new RibbonHttpRequest(uri, verb, client, clientConfig, statsRecorder);
}

Loading…
Cancel
Save