Commit 8f6cd86e by Spencer Gibb

Merge pull request #704 from hscholz/master

* pull704: Explicitly set target to feign client name.
parents 2acd353c abd32fbf
...@@ -18,9 +18,6 @@ package org.springframework.cloud.netflix.feign; ...@@ -18,9 +18,6 @@ package org.springframework.cloud.netflix.feign;
import java.util.Map; import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
...@@ -36,11 +33,14 @@ import feign.Logger; ...@@ -36,11 +33,14 @@ import feign.Logger;
import feign.Request; import feign.Request;
import feign.RequestInterceptor; import feign.RequestInterceptor;
import feign.Retryer; import feign.Retryer;
import feign.Target;
import feign.Target.HardCodedTarget;
import feign.codec.Decoder; import feign.codec.Decoder;
import feign.codec.Encoder; import feign.codec.Encoder;
import feign.codec.ErrorDecoder; import feign.codec.ErrorDecoder;
import feign.hystrix.HystrixFeign;
import feign.slf4j.Slf4jLogger; import feign.slf4j.Slf4jLogger;
import lombok.Data;
import lombok.EqualsAndHashCode;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
...@@ -120,10 +120,10 @@ class FeignClientFactoryBean implements FactoryBean<Object>, InitializingBean, A ...@@ -120,10 +120,10 @@ class FeignClientFactoryBean implements FactoryBean<Object>, InitializingBean, A
return factory.getInstance(this.name, type); return factory.getInstance(this.name, type);
} }
protected <T> T loadBalance(Feign.Builder builder, FeignClientFactory factory, Class<T> type, String url) { protected <T> T loadBalance(Feign.Builder builder, FeignClientFactory factory, Target<T> target) {
Client client = getOptional(factory, Client.class); Client client = getOptional(factory, Client.class);
if (client != null) { if (client != null) {
return builder.client(client).target(type, url); return builder.client(client).target(target);
} }
throw new IllegalStateException("No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-ribbon?"); throw new IllegalStateException("No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-ribbon?");
...@@ -140,12 +140,12 @@ class FeignClientFactoryBean implements FactoryBean<Object>, InitializingBean, A ...@@ -140,12 +140,12 @@ class FeignClientFactoryBean implements FactoryBean<Object>, InitializingBean, A
} else { } else {
url = this.name; url = this.name;
} }
return loadBalance(feign(factory), factory, this.type, url); return loadBalance(feign(factory), factory, new HardCodedTarget<>(this.type, this.name, url));
} }
if (StringUtils.hasText(this.url) && !this.url.startsWith("http")) { if (StringUtils.hasText(this.url) && !this.url.startsWith("http")) {
this.url = "http://" + this.url; this.url = "http://" + this.url;
} }
return feign(factory).target(this.type, this.url); return feign(factory).target(new HardCodedTarget<>(this.type, this.name, this.url));
} }
@Override @Override
......
...@@ -279,6 +279,7 @@ public class FeignClientTests { ...@@ -279,6 +279,7 @@ public class FeignClientTests {
public void testHystrixCommand() { public void testHystrixCommand() {
HystrixCommand<List<Hello>> command = this.testClient.getHellosHystrix(); HystrixCommand<List<Hello>> command = this.testClient.getHellosHystrix();
assertNotNull("command was null", command); assertNotNull("command was null", command);
assertEquals("Hystrix command group name should match the name of the feign client", "localapp", command.getCommandGroup().name());
List<Hello> hellos = command.execute(); List<Hello> hellos = command.execute();
assertNotNull("hellos was null", hellos); assertNotNull("hellos was null", hellos);
assertEquals("hellos didn't match", hellos, getHelloList()); assertEquals("hellos didn't match", hellos, getHelloList());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment