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
afb43c58
Commit
afb43c58
authored
Jul 21, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Actually fix the feign client validation issue
We need to still assert that the FeignClient is valid (no name and value specified together for instance). Added missing tests.
parent
85ef54a9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
7 deletions
+49
-7
FeignClientsRegistrar.java
...gframework/cloud/netflix/feign/FeignClientsRegistrar.java
+3
-6
FeignClientValidationTests.java
...oud/netflix/feign/invalid/FeignClientValidationTests.java
+46
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsRegistrar.java
View file @
afb43c58
...
@@ -155,8 +155,6 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
...
@@ -155,8 +155,6 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
Map
<
String
,
Object
>
attributes
=
annotationMetadata
Map
<
String
,
Object
>
attributes
=
annotationMetadata
.
getAnnotationAttributes
(
.
getAnnotationAttributes
(
FeignClient
.
class
.
getCanonicalName
());
FeignClient
.
class
.
getCanonicalName
());
// Spring 4.2 didn't do this for us. With 4.3 it's idempotent.
attributes
=
AnnotationAttributes
.
fromMap
(
attributes
);
String
name
=
getClientName
(
attributes
);
String
name
=
getClientName
(
attributes
);
registerClientConfiguration
(
registry
,
name
,
registerClientConfiguration
(
registry
,
name
,
...
@@ -192,10 +190,9 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
...
@@ -192,10 +190,9 @@ 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"
)))
{
AnnotationAttributes
annotation
=
AnnotationAttributes
.
fromMap
(
attributes
);
Assert
.
isTrue
(!
StringUtils
.
hasText
((
String
)
attributes
.
get
(
"serviceId"
)),
// This blows up if an aliased property is overspecified
"Either name (serviceId) or value can be specified, but not both"
);
annotation
.
getAliasedString
(
"name"
,
FeignClient
.
class
,
null
);
}
}
}
private
String
getName
(
Map
<
String
,
Object
>
attributes
)
{
private
String
getName
(
Map
<
String
,
Object
>
attributes
)
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/invalid/FeignClientValidationTests.java
View file @
afb43c58
...
@@ -40,6 +40,50 @@ public class FeignClientValidationTests {
...
@@ -40,6 +40,50 @@ public class FeignClientValidationTests {
public
ExpectedException
expected
=
ExpectedException
.
none
();
public
ExpectedException
expected
=
ExpectedException
.
none
();
@Test
@Test
public
void
testNameAndValue
()
{
this
.
expected
.
expectMessage
(
"only one is permitted"
);
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
NameAndValueConfiguration
.
class
);
assertNotNull
(
context
.
getBean
(
NameAndValueConfiguration
.
Client
.
class
));
context
.
close
();
}
@Configuration
@Import
(
FeignAutoConfiguration
.
class
)
@EnableFeignClients
(
clients
=
NameAndValueConfiguration
.
Client
.
class
)
protected
static
class
NameAndValueConfiguration
{
@FeignClient
(
value
=
"foo"
,
name
=
"bar"
)
interface
Client
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/"
)
String
get
();
}
}
@Test
public
void
testServiceIdAndValue
()
{
this
.
expected
.
expectMessage
(
"only one is permitted"
);
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
NameAndValueConfiguration
.
class
);
assertNotNull
(
context
.
getBean
(
NameAndServiceIdConfiguration
.
Client
.
class
));
context
.
close
();
}
@Configuration
@Import
(
FeignAutoConfiguration
.
class
)
@EnableFeignClients
(
clients
=
NameAndServiceIdConfiguration
.
Client
.
class
)
protected
static
class
NameAndServiceIdConfiguration
{
@FeignClient
(
serviceId
=
"foo"
,
name
=
"bar"
)
interface
Client
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/"
)
String
get
();
}
}
@Test
public
void
testNotLegalHostname
()
{
public
void
testNotLegalHostname
()
{
this
.
expected
.
expectMessage
(
"not legal hostname (foo_bar)"
);
this
.
expected
.
expectMessage
(
"not legal hostname (foo_bar)"
);
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
...
@@ -115,7 +159,8 @@ public class FeignClientValidationTests {
...
@@ -115,7 +159,8 @@ public class FeignClientValidationTests {
return
new
Dummy
();
return
new
Dummy
();
}
}
class
Dummy
{
}
class
Dummy
{
}
}
}
}
}
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