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
private final SpringClientFactory clientFactory; 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.clientFactory = clientFactory;
this.loadBalancer = loadBalancer; this.loadBalancer = loadBalancer;
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public ClientHttpRequest createRequest(URI originalUri, HttpMethod httpMethod) public ClientHttpRequest createRequest(URI originalUri, HttpMethod httpMethod)
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) {
server = ((RibbonServer)instance).getServer(); server = ((RibbonServer) instance).getServer();
} }
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);
} }

Loading…
Cancel
Save