Return valid empty JSON response when no recovery information

This is a fix to send back to the client a valid empty JSON response in
the case when we have no recovery information.

Closes #5743
This commit is contained in:
Andrew Selden 2014-04-09 19:02:41 -07:00
parent 1f7f72135a
commit 3121ad20dd
2 changed files with 19 additions and 20 deletions

View File

@ -89,7 +89,7 @@ public class RecoveryResponse extends BroadcastOperationResponse implements ToXC
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
if (hasRecoveries()) {
for (String index : shardResponses.keySet()) {
List<ShardRecoveryResponse> responses = shardResponses.get(index);
if (responses == null || responses.size() == 0) {
@ -106,6 +106,7 @@ public class RecoveryResponse extends BroadcastOperationResponse implements ToXC
builder.endArray();
builder.endObject();
}
}
return builder;
}

View File

@ -57,12 +57,10 @@ public class RestRecoveryAction extends BaseRestHandler {
client.admin().indices().recoveries(recoveryRequest, new RestBuilderListener<RecoveryResponse>(channel) {
@Override
public RestResponse buildResponse(RecoveryResponse response, XContentBuilder builder) throws Exception {
if (response.hasRecoveries()) {
response.detailed(recoveryRequest.detailed());
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
}
return new BytesRestResponse(OK, builder);
}
});