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
9e0d8cae
Commit
9e0d8cae
authored
Feb 29, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support HttpEntity not just ResponseEntity
fixes gh-859
parent
b6fef047
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
19 deletions
+43
-19
ResponseEntityDecoder.java
...rk/cloud/netflix/feign/support/ResponseEntityDecoder.java
+14
-8
FeignClientTests.java
...framework/cloud/netflix/feign/valid/FeignClientTests.java
+29
-11
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/support/ResponseEntityDecoder.java
View file @
9e0d8cae
...
@@ -5,6 +5,7 @@ import java.lang.reflect.ParameterizedType;
...
@@ -5,6 +5,7 @@ import java.lang.reflect.ParameterizedType;
import
java.lang.reflect.Type
;
import
java.lang.reflect.Type
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.LinkedMultiValueMap
;
...
@@ -33,13 +34,13 @@ public class ResponseEntityDecoder implements Decoder {
...
@@ -33,13 +34,13 @@ public class ResponseEntityDecoder implements Decoder {
public
Object
decode
(
final
Response
response
,
Type
type
)
throws
IOException
,
public
Object
decode
(
final
Response
response
,
Type
type
)
throws
IOException
,
FeignException
{
FeignException
{
if
(
isParameterize
Response
Entity
(
type
))
{
if
(
isParameterize
Http
Entity
(
type
))
{
type
=
((
ParameterizedType
)
type
).
getActualTypeArguments
()[
0
];
type
=
((
ParameterizedType
)
type
).
getActualTypeArguments
()[
0
];
Object
decodedObject
=
decoder
.
decode
(
response
,
type
);
Object
decodedObject
=
decoder
.
decode
(
response
,
type
);
return
createResponse
(
decodedObject
,
response
);
return
createResponse
(
decodedObject
,
response
);
}
}
else
if
(
is
Response
Entity
(
type
))
{
else
if
(
is
Http
Entity
(
type
))
{
return
createResponse
(
null
,
response
);
return
createResponse
(
null
,
response
);
}
}
else
{
else
{
...
@@ -47,14 +48,19 @@ public class ResponseEntityDecoder implements Decoder {
...
@@ -47,14 +48,19 @@ public class ResponseEntityDecoder implements Decoder {
}
}
}
}
private
boolean
isParameterizeResponseEntity
(
Type
type
)
{
private
boolean
isParameterizeHttpEntity
(
Type
type
)
{
return
type
instanceof
ParameterizedType
if
(
type
instanceof
ParameterizedType
)
{
&&
((
ParameterizedType
)
type
).
getRawType
().
equals
(
ResponseEntity
.
class
);
return
isHttpEntity
(((
ParameterizedType
)
type
).
getRawType
());
}
return
false
;
}
}
private
boolean
isResponseEntity
(
Type
type
)
{
private
boolean
isHttpEntity
(
Type
type
)
{
if
(
type
instanceof
Class
)
{
return
type
instanceof
Class
&&
type
.
equals
(
ResponseEntity
.
class
);
Class
c
=
(
Class
)
type
;
return
HttpEntity
.
class
.
isAssignableFrom
(
c
);
}
return
false
;
}
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/valid/FeignClientTests.java
View file @
9e0d8cae
...
@@ -54,6 +54,7 @@ import org.springframework.cloud.netflix.ribbon.RibbonClients;
...
@@ -54,6 +54,7 @@ import org.springframework.cloud.netflix.ribbon.RibbonClients;
import
org.springframework.cloud.netflix.ribbon.StaticServerList
;
import
org.springframework.cloud.netflix.ribbon.StaticServerList
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.annotation.DirtiesContext
;
...
@@ -87,6 +88,11 @@ import rx.Observable;
...
@@ -87,6 +88,11 @@ import rx.Observable;
@DirtiesContext
@DirtiesContext
public
class
FeignClientTests
{
public
class
FeignClientTests
{
public
static
final
String
HELLO_WORLD_1
=
"hello world 1"
;
public
static
final
String
OI_TERRA_2
=
"oi terra 2"
;
public
static
final
String
MYHEADER1
=
"myheader1"
;
public
static
final
String
MYHEADER2
=
"myheader2"
;
@Value
(
"${local.server.port}"
)
@Value
(
"${local.server.port}"
)
private
int
port
=
0
;
private
int
port
=
0
;
...
@@ -130,6 +136,9 @@ public class FeignClientTests {
...
@@ -130,6 +136,9 @@ public class FeignClientTests {
@RequestMapping
(
method
=
RequestMethod
.
HEAD
,
value
=
"/head"
)
@RequestMapping
(
method
=
RequestMethod
.
HEAD
,
value
=
"/head"
)
ResponseEntity
head
();
ResponseEntity
head
();
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hello"
)
HttpEntity
<
Hello
>
getHelloEntity
();
}
}
public
static
class
TestClientConfig
{
public
static
class
TestClientConfig
{
...
@@ -139,7 +148,7 @@ public class FeignClientTests {
...
@@ -139,7 +148,7 @@ public class FeignClientTests {
return
new
RequestInterceptor
()
{
return
new
RequestInterceptor
()
{
@Override
@Override
public
void
apply
(
RequestTemplate
template
)
{
public
void
apply
(
RequestTemplate
template
)
{
template
.
header
(
"myheader1"
,
"myheader1value"
);
template
.
header
(
MYHEADER1
,
"myheader1value"
);
}
}
};
};
}
}
...
@@ -149,7 +158,7 @@ public class FeignClientTests {
...
@@ -149,7 +158,7 @@ public class FeignClientTests {
return
new
RequestInterceptor
()
{
return
new
RequestInterceptor
()
{
@Override
@Override
public
void
apply
(
RequestTemplate
template
)
{
public
void
apply
(
RequestTemplate
template
)
{
template
.
header
(
"myheader2"
,
"myheader2value"
);
template
.
header
(
MYHEADER2
,
"myheader2value"
);
}
}
};
};
}
}
...
@@ -220,7 +229,7 @@ public class FeignClientTests {
...
@@ -220,7 +229,7 @@ public class FeignClientTests {
@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
);
}
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hellos"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hellos"
)
...
@@ -232,14 +241,14 @@ public class FeignClientTests {
...
@@ -232,14 +241,14 @@ public class FeignClientTests {
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hellostrings"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hellostrings"
)
public
List
<
String
>
getHelloStrings
()
{
public
List
<
String
>
getHelloStrings
()
{
ArrayList
<
String
>
hellos
=
new
ArrayList
<>();
ArrayList
<
String
>
hellos
=
new
ArrayList
<>();
hellos
.
add
(
"hello world 1"
);
hellos
.
add
(
HELLO_WORLD_1
);
hellos
.
add
(
"oi terra 2"
);
hellos
.
add
(
OI_TERRA_2
);
return
hellos
;
return
hellos
;
}
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/helloheaders"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/helloheaders"
)
public
List
<
String
>
getHelloHeaders
(
@RequestHeader
(
"myheader1"
)
String
myheader1
,
public
List
<
String
>
getHelloHeaders
(
@RequestHeader
(
MYHEADER1
)
String
myheader1
,
@RequestHeader
(
"myheader2"
)
String
myheader2
)
{
@RequestHeader
(
MYHEADER2
)
String
myheader2
)
{
ArrayList
<
String
>
headers
=
new
ArrayList
<>();
ArrayList
<
String
>
headers
=
new
ArrayList
<>();
headers
.
add
(
myheader1
);
headers
.
add
(
myheader1
);
headers
.
add
(
myheader2
);
headers
.
add
(
myheader2
);
...
@@ -281,8 +290,8 @@ public class FeignClientTests {
...
@@ -281,8 +290,8 @@ public class FeignClientTests {
private
static
ArrayList
<
Hello
>
getHelloList
()
{
private
static
ArrayList
<
Hello
>
getHelloList
()
{
ArrayList
<
Hello
>
hellos
=
new
ArrayList
<>();
ArrayList
<
Hello
>
hellos
=
new
ArrayList
<>();
hellos
.
add
(
new
Hello
(
"hello world 1"
));
hellos
.
add
(
new
Hello
(
HELLO_WORLD_1
));
hellos
.
add
(
new
Hello
(
"oi terra 2"
));
hellos
.
add
(
new
Hello
(
OI_TERRA_2
));
return
hellos
;
return
hellos
;
}
}
...
@@ -299,7 +308,7 @@ public class FeignClientTests {
...
@@ -299,7 +308,7 @@ public class FeignClientTests {
public
void
testSimpleType
()
{
public
void
testSimpleType
()
{
Hello
hello
=
this
.
testClient
.
getHello
();
Hello
hello
=
this
.
testClient
.
getHello
();
assertNotNull
(
"hello was null"
,
hello
);
assertNotNull
(
"hello was null"
,
hello
);
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
@Test
...
@@ -332,7 +341,7 @@ public class FeignClientTests {
...
@@ -332,7 +341,7 @@ public class FeignClientTests {
assertNotNull
(
"testClientServiceId was null"
,
this
.
testClientServiceId
);
assertNotNull
(
"testClientServiceId was null"
,
this
.
testClientServiceId
);
final
Hello
hello
=
this
.
testClientServiceId
.
getHello
();
final
Hello
hello
=
this
.
testClientServiceId
.
getHello
();
assertNotNull
(
"The hello response was null"
,
hello
);
assertNotNull
(
"The hello response was null"
,
hello
);
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
@Test
...
@@ -368,6 +377,15 @@ public class FeignClientTests {
...
@@ -368,6 +377,15 @@ public class FeignClientTests {
}
}
@Test
@Test
public
void
testHttpEntity
()
{
HttpEntity
<
Hello
>
entity
=
testClient
.
getHelloEntity
();
assertNotNull
(
"entity was null"
,
entity
);
Hello
hello
=
entity
.
getBody
();
assertNotNull
(
"hello was null"
,
hello
);
assertEquals
(
"first hello didn't match"
,
new
Hello
(
HELLO_WORLD_1
),
hello
);
}
@Test
public
void
testDecodeNotFound
()
{
public
void
testDecodeNotFound
()
{
ResponseEntity
response
=
decodingTestClient
.
notFound
();
ResponseEntity
response
=
decodingTestClient
.
notFound
();
assertNotNull
(
"response was null"
,
response
);
assertNotNull
(
"response was null"
,
response
);
...
...
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