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
000fee96
Commit
000fee96
authored
Mar 04, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use "=" as separator in @RequestMapping(headers=...)
Consistent with Spring MVC (and untested up to now apparently). Fixes gh-874
parent
718cafcd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
13 deletions
+34
-13
SpringMvcContract.java
...mework/cloud/netflix/feign/support/SpringMvcContract.java
+11
-10
SpringMvcContractTests.java
...k/cloud/netflix/feign/support/SpringMvcContractTests.java
+23
-3
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/support/SpringMvcContract.java
View file @
000fee96
...
@@ -36,14 +36,14 @@ import org.springframework.core.annotation.AnnotationUtils;
...
@@ -36,14 +36,14 @@ import org.springframework.core.annotation.AnnotationUtils;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
feign.Contract
;
import
feign.Feign
;
import
feign.MethodMetadata
;
import
static
feign
.
Util
.
checkState
;
import
static
feign
.
Util
.
checkState
;
import
static
feign
.
Util
.
emptyToNull
;
import
static
feign
.
Util
.
emptyToNull
;
import
static
org
.
springframework
.
core
.
annotation
.
AnnotatedElementUtils
.
findMergedAnnotation
;
import
static
org
.
springframework
.
core
.
annotation
.
AnnotatedElementUtils
.
findMergedAnnotation
;
import
feign.Contract
;
import
feign.Feign
;
import
feign.MethodMetadata
;
/**
/**
* @author Spencer Gibb
* @author Spencer Gibb
*/
*/
...
@@ -79,10 +79,11 @@ public class SpringMvcContract extends Contract.BaseContract {
...
@@ -79,10 +79,11 @@ public class SpringMvcContract extends Contract.BaseContract {
@Override
@Override
public
MethodMetadata
parseAndValidateMetadata
(
Class
<?>
targetType
,
Method
method
)
{
public
MethodMetadata
parseAndValidateMetadata
(
Class
<?>
targetType
,
Method
method
)
{
processedMethods
.
put
(
Feign
.
configKey
(
targetType
,
method
),
method
);
this
.
processedMethods
.
put
(
Feign
.
configKey
(
targetType
,
method
),
method
);
MethodMetadata
md
=
super
.
parseAndValidateMetadata
(
targetType
,
method
);
MethodMetadata
md
=
super
.
parseAndValidateMetadata
(
targetType
,
method
);
RequestMapping
classAnnotation
=
findMergedAnnotation
(
targetType
,
RequestMapping
.
class
);
RequestMapping
classAnnotation
=
findMergedAnnotation
(
targetType
,
RequestMapping
.
class
);
if
(
classAnnotation
!=
null
)
{
if
(
classAnnotation
!=
null
)
{
// Prepend path from class annotation if specified
// Prepend path from class annotation if specified
if
(
classAnnotation
.
value
().
length
>
0
)
{
if
(
classAnnotation
.
value
().
length
>
0
)
{
...
@@ -169,7 +170,7 @@ public class SpringMvcContract extends Contract.BaseContract {
...
@@ -169,7 +170,7 @@ public class SpringMvcContract extends Contract.BaseContract {
AnnotatedParameterProcessor
.
AnnotatedParameterContext
context
=
new
SimpleAnnotatedParameterContext
(
AnnotatedParameterProcessor
.
AnnotatedParameterContext
context
=
new
SimpleAnnotatedParameterContext
(
data
,
paramIndex
);
data
,
paramIndex
);
Method
method
=
processedMethods
.
get
(
data
.
configKey
());
Method
method
=
this
.
processedMethods
.
get
(
data
.
configKey
());
for
(
Annotation
parameterAnnotation
:
annotations
)
{
for
(
Annotation
parameterAnnotation
:
annotations
)
{
AnnotatedParameterProcessor
processor
=
this
.
annotatedArgumentProcessors
AnnotatedParameterProcessor
processor
=
this
.
annotatedArgumentProcessors
.
get
(
parameterAnnotation
.
annotationType
());
.
get
(
parameterAnnotation
.
annotationType
());
...
@@ -213,9 +214,9 @@ public class SpringMvcContract extends Contract.BaseContract {
...
@@ -213,9 +214,9 @@ public class SpringMvcContract extends Contract.BaseContract {
// TODO: only supports one header value per key
// TODO: only supports one header value per key
if
(
annotation
.
headers
()
!=
null
&&
annotation
.
headers
().
length
>
0
)
{
if
(
annotation
.
headers
()
!=
null
&&
annotation
.
headers
().
length
>
0
)
{
for
(
String
header
:
annotation
.
headers
())
{
for
(
String
header
:
annotation
.
headers
())
{
int
colon
=
header
.
indexOf
(
':
'
);
int
index
=
header
.
indexOf
(
'=
'
);
md
.
template
().
header
(
header
.
substring
(
0
,
colon
),
md
.
template
().
header
(
header
.
substring
(
0
,
index
),
header
.
substring
(
colon
+
2
));
header
.
substring
(
index
+
1
).
trim
(
));
}
}
}
}
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/support/SpringMvcContractTests.java
View file @
000fee96
...
@@ -183,6 +183,18 @@ public class SpringMvcContractTests {
...
@@ -183,6 +183,18 @@ public class SpringMvcContractTests {
}
}
@Test
@Test
public
void
testProcessHeaders
()
throws
Exception
{
Method
method
=
TestTemplate_Headers
.
class
.
getDeclaredMethod
(
"getTest"
,
String
.
class
);
MethodMetadata
data
=
this
.
contract
.
parseAndValidateMetadata
(
method
.
getDeclaringClass
(),
method
);
assertEquals
(
"/test/{id}"
,
data
.
template
().
url
());
assertEquals
(
"GET"
,
data
.
template
().
method
());
assertEquals
(
"bar"
,
data
.
template
().
headers
().
get
(
"X-Foo"
).
iterator
().
next
());
}
@Test
public
void
testProcessAnnotations_Fallback
()
throws
Exception
{
public
void
testProcessAnnotations_Fallback
()
throws
Exception
{
Method
method
=
TestTemplate_Advanced
.
class
.
getDeclaredMethod
(
"getTestFallback"
,
Method
method
=
TestTemplate_Advanced
.
class
.
getDeclaredMethod
(
"getTestFallback"
,
String
.
class
,
String
.
class
,
Integer
.
class
);
String
.
class
,
String
.
class
,
Integer
.
class
);
...
@@ -219,10 +231,12 @@ public class SpringMvcContractTests {
...
@@ -219,10 +231,12 @@ public class SpringMvcContractTests {
org
.
springframework
.
util
.
Assert
.
isTrue
(
m
.
getParameterTypes
().
length
>
0
,
org
.
springframework
.
util
.
Assert
.
isTrue
(
m
.
getParameterTypes
().
length
>
0
,
"method has no parameters"
);
"method has no parameters"
);
if
(
EXECUTABLE_TYPE
!=
null
)
{
if
(
EXECUTABLE_TYPE
!=
null
)
{
Method
getParameters
=
ReflectionUtils
.
findMethod
(
EXECUTABLE_TYPE
,
"getParameters"
);
Method
getParameters
=
ReflectionUtils
.
findMethod
(
EXECUTABLE_TYPE
,
"getParameters"
);
try
{
try
{
Object
[]
parameters
=
(
Object
[])
getParameters
.
invoke
(
m
);
Object
[]
parameters
=
(
Object
[])
getParameters
.
invoke
(
m
);
Method
isNamePresent
=
ReflectionUtils
.
findMethod
(
parameters
[
0
].
getClass
(),
"isNamePresent"
);
Method
isNamePresent
=
ReflectionUtils
.
findMethod
(
parameters
[
0
].
getClass
(),
"isNamePresent"
);
return
Boolean
.
TRUE
.
equals
(
isNamePresent
.
invoke
(
parameters
[
0
]));
return
Boolean
.
TRUE
.
equals
(
isNamePresent
.
invoke
(
parameters
[
0
]));
}
}
catch
(
IllegalAccessException
|
IllegalArgumentException
catch
(
IllegalAccessException
|
IllegalArgumentException
...
@@ -243,6 +257,11 @@ public class SpringMvcContractTests {
...
@@ -243,6 +257,11 @@ public class SpringMvcContractTests {
TestObject
postTest
(
@RequestBody
TestObject
object
);
TestObject
postTest
(
@RequestBody
TestObject
object
);
}
}
public
interface
TestTemplate_Headers
{
@RequestMapping
(
value
=
"/test/{id}"
,
method
=
RequestMethod
.
GET
,
headers
=
"X-Foo=bar"
)
ResponseEntity
<
TestObject
>
getTest
(
@PathVariable
(
"id"
)
String
id
);
}
@JsonAutoDetect
@JsonAutoDetect
@RequestMapping
(
"/advanced"
)
@RequestMapping
(
"/advanced"
)
public
interface
TestTemplate_Advanced
{
public
interface
TestTemplate_Advanced
{
...
@@ -253,7 +272,8 @@ public class SpringMvcContractTests {
...
@@ -253,7 +272,8 @@ public class SpringMvcContractTests {
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
"amount"
)
Integer
amount
);
@PathVariable
(
"id"
)
String
id
,
@RequestParam
(
"amount"
)
Integer
amount
);
@RequestMapping
(
path
=
"/test2"
,
method
=
RequestMethod
.
PUT
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@RequestMapping
(
path
=
"/test2"
,
method
=
RequestMethod
.
PUT
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
ResponseEntity
<
TestObject
>
getTest2
(
@RequestHeader
(
name
=
"Authorization"
)
String
auth
,
ResponseEntity
<
TestObject
>
getTest2
(
@RequestHeader
(
name
=
"Authorization"
)
String
auth
,
@RequestParam
(
name
=
"amount"
)
Integer
amount
);
@RequestParam
(
name
=
"amount"
)
Integer
amount
);
@ExceptionHandler
@ExceptionHandler
...
...
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