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
dd4b967f
Unverified
Commit
dd4b967f
authored
Mar 13, 2018
by
Ryan Baxter
Committed by
GitHub
Mar 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix NPE when empty body during retry (#2775)
parent
b99faba3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletion
+38
-1
RetryableFeignLoadBalancer.java
...loud/netflix/feign/ribbon/RetryableFeignLoadBalancer.java
+1
-1
RetryableFeignLoadBalancerTests.java
...netflix/feign/ribbon/RetryableFeignLoadBalancerTests.java
+37
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/RetryableFeignLoadBalancer.java
View file @
dd4b967f
...
...
@@ -137,7 +137,7 @@ public class RetryableFeignLoadBalancer extends FeignLoadBalancer implements Ser
}
Response
response
=
request
.
client
().
execute
(
feignRequest
,
options
);
if
(
retryPolicy
.
retryableStatusCode
(
response
.
status
()))
{
byte
[]
byteArray
=
StreamUtils
.
copyToByteArray
(
response
.
body
().
asInputStream
());
byte
[]
byteArray
=
response
.
body
()
==
null
?
new
byte
[]{}
:
StreamUtils
.
copyToByteArray
(
response
.
body
().
asInputStream
());
response
.
close
();
throw
new
RibbonResponseStatusCodeException
(
RetryableFeignLoadBalancer
.
this
.
clientName
,
response
,
byteArray
,
request
.
getUri
());
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/ribbon/RetryableFeignLoadBalancerTests.java
View file @
dd4b967f
...
...
@@ -79,6 +79,7 @@ import static org.junit.Assert.assertEquals;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyBoolean
;
import
static
org
.
mockito
.
Matchers
.
anyInt
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
...
...
@@ -228,6 +229,42 @@ public class RetryableFeignLoadBalancerTests {
}
@Test
public
void
executeRetryOnStatusCodeWithEmptyBody
()
throws
Exception
{
int
retriesNextServer
=
0
;
when
(
this
.
config
.
get
(
MaxAutoRetriesNextServer
,
DEFAULT_MAX_AUTO_RETRIES_NEXT_SERVER
)).
thenReturn
(
retriesNextServer
);
doReturn
(
new
Server
(
"foo"
,
80
)).
when
(
lb
).
chooseServer
(
anyObject
());
RibbonLoadBalancerContext
lbContext
=
new
RibbonLoadBalancerContext
(
lb
,
config
);
SpringClientFactory
clientFactory
=
mock
(
SpringClientFactory
.
class
);
IClientConfig
config
=
mock
(
IClientConfig
.
class
);
doReturn
(
1
).
when
(
config
).
get
(
eq
(
CommonClientConfigKey
.
MaxAutoRetries
),
anyInt
());
doReturn
(
retriesNextServer
).
when
(
config
).
get
(
eq
(
CommonClientConfigKey
.
MaxAutoRetriesNextServer
),
anyInt
());
doReturn
(
true
).
when
(
config
).
get
(
eq
(
CommonClientConfigKey
.
OkToRetryOnAllOperations
),
eq
(
false
));
doReturn
(
defaultConnectTimeout
).
when
(
config
).
get
(
eq
(
CommonClientConfigKey
.
ConnectTimeout
));
doReturn
(
defaultReadTimeout
).
when
(
config
).
get
(
eq
(
CommonClientConfigKey
.
ReadTimeout
));
doReturn
(
"404"
).
when
(
config
).
getPropertyAsString
(
eq
(
RibbonLoadBalancedRetryPolicy
.
RETRYABLE_STATUS_CODES
),
eq
(
""
));
doReturn
(
config
).
when
(
clientFactory
).
getClientConfig
(
eq
(
"default"
));
doReturn
(
lbContext
).
when
(
clientFactory
).
getLoadBalancerContext
(
any
(
String
.
class
));
RibbonLoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
=
new
RibbonLoadBalancedRetryPolicyFactory
(
clientFactory
);
HttpRequest
springRequest
=
mock
(
HttpRequest
.
class
);
Request
feignRequest
=
Request
.
create
(
"GET"
,
"http://foo"
,
new
HashMap
<
String
,
Collection
<
String
>>(),
new
byte
[]{},
StandardCharsets
.
UTF_8
);
Client
client
=
mock
(
Client
.
class
);
FeignLoadBalancer
.
RibbonRequest
request
=
new
FeignLoadBalancer
.
RibbonRequest
(
client
,
feignRequest
,
new
URI
(
"http://foo"
));
Response
response
=
Response
.
builder
().
status
(
404
).
headers
(
new
HashMap
<
String
,
Collection
<
String
>>()).
build
();
Response
fourOFourResponse
=
Response
.
builder
().
status
(
404
).
headers
(
new
HashMap
<
String
,
Collection
<
String
>>()).
build
();
doReturn
(
fourOFourResponse
).
doReturn
(
response
).
when
(
client
).
execute
(
any
(
Request
.
class
),
any
(
Request
.
Options
.
class
));
MyBackOffPolicyFactory
backOffPolicyFactory
=
new
MyBackOffPolicyFactory
();
RetryableFeignLoadBalancer
feignLb
=
new
RetryableFeignLoadBalancer
(
lb
,
config
,
inspector
,
loadBalancedRetryPolicyFactory
,
backOffPolicyFactory
);
FeignLoadBalancer
.
RibbonResponse
ribbonResponse
=
feignLb
.
execute
(
request
,
null
);
assertEquals
(
404
,
ribbonResponse
.
toResponse
().
status
());
assertEquals
(
new
Integer
(
0
),
ribbonResponse
.
toResponse
().
body
().
length
());
verify
(
client
,
times
(
2
)).
execute
(
any
(
Request
.
class
),
any
(
Request
.
Options
.
class
));
assertEquals
(
1
,
backOffPolicyFactory
.
getCount
());
}
@Test
public
void
getRequestSpecificRetryHandler
()
throws
Exception
{
RibbonLoadBalancerContext
lbContext
=
new
RibbonLoadBalancerContext
(
lb
,
config
);
SpringClientFactory
clientFactory
=
mock
(
SpringClientFactory
.
class
);
...
...
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