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
dc26b1ef
Unverified
Commit
dc26b1ef
authored
Aug 31, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1102 from lowzj/request-param-processor
* lowzj-request-param-processor: update RequestParamParameterProcessor to support map param
parents
c5b0ffe3
d356e571
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
11 deletions
+45
-11
RequestParamParameterProcessor.java
...flix/feign/annotation/RequestParamParameterProcessor.java
+12
-9
SpringMvcContract.java
...mework/cloud/netflix/feign/support/SpringMvcContract.java
+13
-1
SpringMvcContractTests.java
...k/cloud/netflix/feign/support/SpringMvcContractTests.java
+20
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/annotation/RequestParamParameterProcessor.java
View file @
dc26b1ef
...
...
@@ -47,15 +47,18 @@ public class RequestParamParameterProcessor implements AnnotatedParameterProcess
Annotation
annotation
)
{
RequestParam
requestParam
=
ANNOTATION
.
cast
(
annotation
);
String
name
=
requestParam
.
value
();
checkState
(
emptyToNull
(
name
)
!=
null
,
"RequestParam.value() was empty on parameter %s"
,
context
.
getParameterIndex
());
context
.
setParameterName
(
name
);
MethodMetadata
data
=
context
.
getMethodMetadata
();
Collection
<
String
>
query
=
context
.
setTemplateParameter
(
name
,
data
.
template
().
queries
().
get
(
name
));
data
.
template
().
query
(
name
,
query
);
if
(
emptyToNull
(
name
)
!=
null
)
{
context
.
setParameterName
(
name
);
MethodMetadata
data
=
context
.
getMethodMetadata
();
Collection
<
String
>
query
=
context
.
setTemplateParameter
(
name
,
data
.
template
().
queries
().
get
(
name
));
data
.
template
().
query
(
name
,
query
);
}
else
{
// supports `Map` types
MethodMetadata
data
=
context
.
getMethodMetadata
();
data
.
queryMapIndex
(
context
.
getParameterIndex
());
}
return
true
;
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/support/SpringMvcContract.java
View file @
dc26b1ef
...
...
@@ -18,6 +18,7 @@ package org.springframework.cloud.netflix.feign.support;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Type
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
...
...
@@ -27,6 +28,7 @@ import java.util.LinkedHashMap;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.cloud.netflix.feign.AnnotatedParameterProcessor
;
import
org.springframework.cloud.netflix.feign.annotation.PathVariableParameterProcessor
;
import
org.springframework.cloud.netflix.feign.annotation.RequestHeaderParameterProcessor
;
...
...
@@ -313,8 +315,9 @@ public class SpringMvcContract extends Contract.BaseContract
Object
defaultValue
=
AnnotationUtils
.
getDefaultValue
(
parameterAnnotation
);
if
(
defaultValue
instanceof
String
&&
defaultValue
.
equals
(
annotationAttributes
.
get
(
AnnotationUtils
.
VALUE
)))
{
Type
[]
parameterTypes
=
method
.
getGenericParameterTypes
();
String
[]
parameterNames
=
PARAMETER_NAME_DISCOVERER
.
getParameterNames
(
method
);
if
(
parameterNames
!=
null
&&
parameterNames
.
length
>
parameterIndex
)
{
if
(
shouldAddParameterName
(
parameterIndex
,
parameterTypes
,
parameterNames
)
)
{
annotationAttributes
.
put
(
AnnotationUtils
.
VALUE
,
parameterNames
[
parameterIndex
]);
}
...
...
@@ -323,6 +326,15 @@ public class SpringMvcContract extends Contract.BaseContract
parameterAnnotation
.
annotationType
(),
null
);
}
private
boolean
shouldAddParameterName
(
int
parameterIndex
,
Type
[]
parameterTypes
,
String
[]
parameterNames
)
{
// has a parameter name
return
parameterNames
!=
null
&&
parameterNames
.
length
>
parameterIndex
// has a type
&&
parameterTypes
!=
null
&&
parameterTypes
.
length
>
parameterIndex
// and it is a simple property
&&
BeanUtils
.
isSimpleProperty
(
parameterTypes
[
parameterIndex
].
getClass
());
}
private
class
SimpleAnnotatedParameterContext
implements
AnnotatedParameterProcessor
.
AnnotatedParameterContext
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/support/SpringMvcContractTests.java
View file @
dc26b1ef
...
...
@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.feign.support;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -263,6 +264,19 @@ public class SpringMvcContractTests {
}
@Test
public
void
testProcessAnnotations_MapParams
()
throws
Exception
{
Method
method
=
TestTemplate_MapParams
.
class
.
getDeclaredMethod
(
"getTest"
,
Map
.
class
);
MethodMetadata
data
=
this
.
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
assertEquals
(
"/test"
,
data
.
template
().
url
());
assertEquals
(
"GET"
,
data
.
template
().
method
());
assertNotNull
(
data
.
queryMapIndex
());
assertEquals
(
0
,
data
.
queryMapIndex
().
intValue
());
}
@Test
public
void
testProcessHeaders
()
throws
Exception
{
Method
method
=
TestTemplate_Headers
.
class
.
getDeclaredMethod
(
"getTest"
,
String
.
class
);
...
...
@@ -279,7 +293,7 @@ public class SpringMvcContractTests {
Method
method
=
TestTemplate_Advanced
.
class
.
getDeclaredMethod
(
"getTestFallback"
,
String
.
class
,
String
.
class
,
Integer
.
class
);
assumeTrue
(
hasJava8ParameterNames
(
method
));
assumeTrue
(
"does not have java 8 parameter names"
,
hasJava8ParameterNames
(
method
));
MethodMetadata
data
=
this
.
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
...
...
@@ -361,6 +375,11 @@ public class SpringMvcContractTests {
ResponseEntity
<
TestObject
>
getTest
(
@RequestParam
(
"id"
)
List
<
String
>
id
);
}
public
interface
TestTemplate_MapParams
{
@RequestMapping
(
value
=
"/test"
,
method
=
RequestMethod
.
GET
)
ResponseEntity
<
TestObject
>
getTest
(
@RequestParam
Map
<
String
,
String
>
params
);
}
@JsonAutoDetect
@RequestMapping
(
"/advanced"
)
public
interface
TestTemplate_Advanced
{
...
...
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