Move requests.add(request) into finally block.

This avoids "IllegalStateException: Expectations already declared" when
a MockRestServiceServer is used after one request throws an exception.

Issues: SPR-16132
This commit is contained in:
Eric Pabst
2017-10-30 08:53:13 -06:00
parent 49787493a6
commit 43d88e4a25
2 changed files with 25 additions and 3 deletions

View File

@@ -80,9 +80,12 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect
if (requests.isEmpty()) {
afterExpectationsDeclared();
}
ClientHttpResponse response = validateRequestInternal(request);
requests.add(request);
return response;
try {
return validateRequestInternal(request);
}
finally {
requests.add(request);
}
}
}