Commit edb14e2a by Ryan Baxter Committed by GitHub

Merge pull request #1528 from ryanjbaxter/feign-url-protocol-1522

Don’t add URL protocol when url is set using EL
parents ac3401bc 6a826441
......@@ -243,7 +243,7 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
private String getUrl(Map<String, Object> attributes) {
String url = resolve((String) attributes.get("url"));
if (StringUtils.hasText(url)) {
if (StringUtils.hasText(url) && !(url.startsWith("#{") && url.endsWith("}"))) {
if (!url.contains("://")) {
url = "http://" + url;
}
......
......@@ -30,6 +30,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
......@@ -75,6 +76,11 @@ public class FeignHttpClientUrlTests {
@Autowired
private UrlClient urlClient;
@Autowired
private BeanUrlClient beanClient;
@Autowired BeanUrlClientNoProtocol beanClientNoProtocol;
// this tests that
@FeignClient(name = "localappurl", url = "http://localhost:${server.port}/")
protected interface UrlClient {
......@@ -82,17 +88,41 @@ public class FeignHttpClientUrlTests {
Hello getHello();
}
@FeignClient(name = "beanappurl", url = "#{SERVER_URL}")
protected interface BeanUrlClient {
@RequestMapping(method = RequestMethod.GET, value = "/hello")
Hello getHello();
}
@FeignClient(name = "beanappurlnoprotocol", url = "#{SERVER_URL_NO_PROTOCOL}")
protected interface BeanUrlClientNoProtocol {
@RequestMapping(method = RequestMethod.GET, value = "/hello")
Hello getHello();
}
@Configuration
@EnableAutoConfiguration
@RestController
@EnableFeignClients(clients = { UrlClient.class })
@EnableFeignClients(clients = { UrlClient.class, BeanUrlClient.class, BeanUrlClientNoProtocol.class })
protected static class TestConfig {
@Value("${server.port}")
private int port;
@RequestMapping(method = RequestMethod.GET, value = "/hello")
public Hello getHello() {
return new Hello("hello world 1");
}
@Bean(name="SERVER_URL")
public String serverUrl() {
return "http://localhost:" + port + "/";
}
@Bean(name="SERVER_URL_NO_PROTOCOL")
public String serverUrlNoProtocol() {
return "localhost:" + port + "/";
}
@Bean
public Targeter feignTargeter() {
return new Targeter() {
......@@ -122,6 +152,20 @@ public class FeignHttpClientUrlTests {
assertEquals("first hello didn't match", new Hello("hello world 1"), hello);
}
@Test
public void testBeanUrl() {
Hello hello = this.beanClient.getHello();
assertNotNull("hello was null", hello);
assertEquals("first hello didn't match", new Hello("hello world 1"), hello);
}
@Test
public void testBeanUrlNoProtocol() {
Hello hello = this.beanClientNoProtocol.getHello();
assertNotNull("hello was null", hello);
assertEquals("first hello didn't match", new Hello("hello world 1"), hello);
}
@Data
@AllArgsConstructor
@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