Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
6a826441
Commit
6a826441
authored
Dec 05, 2016
by
Ryan Baxter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don’t add URL protocol when url is set using EL. Fixes #1522.
parent
ac3401bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
FeignClientsRegistrar.java
...gframework/cloud/netflix/feign/FeignClientsRegistrar.java
+1
-1
FeignHttpClientUrlTests.java
...ramework/cloud/netflix/feign/FeignHttpClientUrlTests.java
+45
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsRegistrar.java
View file @
6a826441
...
@@ -243,7 +243,7 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
...
@@ -243,7 +243,7 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
private
String
getUrl
(
Map
<
String
,
Object
>
attributes
)
{
private
String
getUrl
(
Map
<
String
,
Object
>
attributes
)
{
String
url
=
resolve
((
String
)
attributes
.
get
(
"url"
));
String
url
=
resolve
((
String
)
attributes
.
get
(
"url"
));
if
(
StringUtils
.
hasText
(
url
))
{
if
(
StringUtils
.
hasText
(
url
)
&&
!(
url
.
startsWith
(
"#{"
)
&&
url
.
endsWith
(
"}"
))
)
{
if
(!
url
.
contains
(
"://"
))
{
if
(!
url
.
contains
(
"://"
))
{
url
=
"http://"
+
url
;
url
=
"http://"
+
url
;
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/FeignHttpClientUrlTests.java
View file @
6a826441
...
@@ -30,6 +30,7 @@ import org.junit.BeforeClass;
...
@@ -30,6 +30,7 @@ import org.junit.BeforeClass;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
...
@@ -75,6 +76,11 @@ public class FeignHttpClientUrlTests {
...
@@ -75,6 +76,11 @@ public class FeignHttpClientUrlTests {
@Autowired
@Autowired
private
UrlClient
urlClient
;
private
UrlClient
urlClient
;
@Autowired
private
BeanUrlClient
beanClient
;
@Autowired
BeanUrlClientNoProtocol
beanClientNoProtocol
;
// this tests that
// this tests that
@FeignClient
(
name
=
"localappurl"
,
url
=
"http://localhost:${server.port}/"
)
@FeignClient
(
name
=
"localappurl"
,
url
=
"http://localhost:${server.port}/"
)
protected
interface
UrlClient
{
protected
interface
UrlClient
{
...
@@ -82,17 +88,41 @@ public class FeignHttpClientUrlTests {
...
@@ -82,17 +88,41 @@ public class FeignHttpClientUrlTests {
Hello
getHello
();
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
@Configuration
@EnableAutoConfiguration
@EnableAutoConfiguration
@RestController
@RestController
@EnableFeignClients
(
clients
=
{
UrlClient
.
class
})
@EnableFeignClients
(
clients
=
{
UrlClient
.
class
,
BeanUrlClient
.
class
,
BeanUrlClientNoProtocol
.
class
})
protected
static
class
TestConfig
{
protected
static
class
TestConfig
{
@Value
(
"${server.port}"
)
private
int
port
;
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hello"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hello"
)
public
Hello
getHello
()
{
public
Hello
getHello
()
{
return
new
Hello
(
"hello world 1"
);
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
@Bean
public
Targeter
feignTargeter
()
{
public
Targeter
feignTargeter
()
{
return
new
Targeter
()
{
return
new
Targeter
()
{
...
@@ -122,6 +152,20 @@ public class FeignHttpClientUrlTests {
...
@@ -122,6 +152,20 @@ public class FeignHttpClientUrlTests {
assertEquals
(
"first hello didn't match"
,
new
Hello
(
"hello world 1"
),
hello
);
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
@Data
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment