Commit 79f939be by Spencer Gibb

Merge pull request #455 from jmnarloch/service-path

* service-path: Specifing only the serviceId causes NPE
parents 371f8b3b 798a19e4
...@@ -43,6 +43,7 @@ import org.springframework.util.StringUtils; ...@@ -43,6 +43,7 @@ import org.springframework.util.StringUtils;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
* @author Jakub Narloch
*/ */
public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
ResourceLoaderAware, BeanClassLoaderAware { ResourceLoaderAware, BeanClassLoaderAware {
...@@ -115,13 +116,13 @@ public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ...@@ -115,13 +116,13 @@ public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
private void validate(Map<String, Object> attributes) { private void validate(Map<String, Object> attributes) {
if (StringUtils.hasText((String) attributes.get("value"))) { if (StringUtils.hasText((String) attributes.get("value"))) {
Assert.isTrue(!StringUtils.hasText((String) attributes.get("name")), Assert.isTrue(!StringUtils.hasText((String) attributes.get("serviceId")),
"Either name or value can be specified, but not both"); "Either serviceId or value can be specified, but not both");
} }
} }
private String getServiceId(Map<String, Object> attributes) { private String getServiceId(Map<String, Object> attributes) {
String name = (String) attributes.get("name"); String name = (String) attributes.get("serviceId");
if (!StringUtils.hasText(name)) { if (!StringUtils.hasText(name)) {
name = (String) attributes.get("value"); name = (String) attributes.get("value");
} }
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
package org.springframework.cloud.netflix.feign.valid; package org.springframework.cloud.netflix.feign.valid;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
...@@ -65,6 +66,7 @@ import feign.RequestTemplate; ...@@ -65,6 +66,7 @@ import feign.RequestTemplate;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
* @author Jakub Narloch
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = FeignClientTests.Application.class) @SpringApplicationConfiguration(classes = FeignClientTests.Application.class)
...@@ -81,6 +83,9 @@ public class FeignClientTests { ...@@ -81,6 +83,9 @@ public class FeignClientTests {
private TestClient testClient; private TestClient testClient;
@Autowired @Autowired
private TestClientServiceId testClientServiceId;
@Autowired
private Client feignClient; private Client feignClient;
// @FeignClient(value = "http://localhost:9876", loadbalance = false) // @FeignClient(value = "http://localhost:9876", loadbalance = false)
...@@ -99,6 +104,12 @@ public class FeignClientTests { ...@@ -99,6 +104,12 @@ public class FeignClientTests {
public List<String> getHelloHeaders(); public List<String> getHelloHeaders();
} }
@FeignClient(serviceId = "localapp")
protected static interface TestClientServiceId {
@RequestMapping(method = RequestMethod.GET, value = "/hello")
public Hello getHello();
}
@Configuration @Configuration
@EnableAutoConfiguration @EnableAutoConfiguration
@RestController @RestController
...@@ -210,6 +221,14 @@ public class FeignClientTests { ...@@ -210,6 +221,14 @@ public class FeignClientTests {
assertThat(delegate, is(instanceOf(feign.Client.Default.class))); assertThat(delegate, is(instanceOf(feign.Client.Default.class)));
} }
@Test
public void testServiceId() {
assertNotNull("testClientServiceId was null", testClientServiceId);
final Hello hello = testClientServiceId.getHello();
assertNotNull("The hello response was null", hello);
assertEquals("first hello didn't match", new Hello("hello world 1"), hello);
}
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
......
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