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
1e12b745
Commit
1e12b745
authored
Oct 20, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Feign support for Spring MVC parameter and header annotations.
Specifically RequestParam, PathVariable and RequestHeader fixes gh-36
parent
31732b21
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
SpringMvcContract.java
...pringframework/cloud/netflix/feign/SpringMvcContract.java
+55
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/SpringMvcContract.java
View file @
1e12b745
...
...
@@ -6,11 +6,16 @@ import static feign.Util.emptyToNull;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Map
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
feign.Contract
;
import
feign.MethodMetadata
;
import
org.springframework.web.bind.annotation.RequestParam
;
/**
* @author Spencer Gibb
...
...
@@ -78,7 +83,57 @@ public class SpringMvcContract extends Contract.BaseContract {
@Override
protected
boolean
processAnnotationsOnParameter
(
MethodMetadata
data
,
Annotation
[]
annotations
,
int
paramIndex
)
{
boolean
isHttpAnnotation
=
false
;
//TODO: support spring parameter annotations?
for
(
Annotation
parameterAnnotation
:
annotations
)
{
Class
<?
extends
Annotation
>
annotationType
=
parameterAnnotation
.
annotationType
();
if
(
annotationType
==
PathVariable
.
class
)
{
String
name
=
PathVariable
.
class
.
cast
(
parameterAnnotation
).
value
();
checkState
(
emptyToNull
(
name
)
!=
null
,
"PathVariable annotation was empty on param %s."
,
paramIndex
);
nameParam
(
data
,
name
,
paramIndex
);
isHttpAnnotation
=
true
;
String
varName
=
'{'
+
name
+
'}'
;
if
(
data
.
template
().
url
().
indexOf
(
varName
)
==
-
1
&&
!
searchMapValues
(
data
.
template
().
queries
(),
varName
)
&&
!
searchMapValues
(
data
.
template
().
headers
(),
varName
))
{
data
.
formParams
().
add
(
name
);
}
}
else
if
(
annotationType
==
RequestParam
.
class
)
{
String
name
=
RequestParam
.
class
.
cast
(
parameterAnnotation
).
value
();
checkState
(
emptyToNull
(
name
)
!=
null
,
"QueryParam.value() was empty on parameter %s"
,
paramIndex
);
Collection
<
String
>
query
=
addTemplatedParam
(
data
.
template
().
queries
().
get
(
name
),
name
);
data
.
template
().
query
(
name
,
query
);
nameParam
(
data
,
name
,
paramIndex
);
isHttpAnnotation
=
true
;
}
else
if
(
annotationType
==
RequestHeader
.
class
)
{
String
name
=
RequestHeader
.
class
.
cast
(
parameterAnnotation
).
value
();
checkState
(
emptyToNull
(
name
)
!=
null
,
"HeaderParam.value() was empty on parameter %s"
,
paramIndex
);
Collection
<
String
>
header
=
addTemplatedParam
(
data
.
template
().
headers
().
get
(
name
),
name
);
data
.
template
().
header
(
name
,
header
);
nameParam
(
data
,
name
,
paramIndex
);
isHttpAnnotation
=
true
;
}
/* else if (annotationType == FormParam.class) {
String name = FormParam.class.cast(parameterAnnotation).value();
checkState(emptyToNull(name) != null, "FormParam.value() was empty on parameter %s", paramIndex);
data.formParams().add(name);
nameParam(data, name, paramIndex);
isHttpAnnotation = true;
}*/
}
return
isHttpAnnotation
;
}
private
<
K
,
V
>
boolean
searchMapValues
(
Map
<
K
,
Collection
<
V
>>
map
,
V
search
)
{
Collection
<
Collection
<
V
>>
values
=
map
.
values
();
if
(
values
==
null
)
return
false
;
for
(
Collection
<
V
>
entry
:
values
)
{
if
(
entry
.
contains
(
search
))
return
true
;
}
return
false
;
}
}
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