Preconditions.checkState(!requestInfos.isEmpty());
HttpRequest batchRequest = requestFactory.buildPostRequest(this.batchUrl, null);
HttpExecuteInterceptor originalInterceptor = batchRequest.getInterceptor();
batchRequest.setInterceptor(new BatchInterceptor(originalInterceptor));
int retriesRemaining = batchRequest.getNumberOfRetries();
BackOffPolicy backOffPolicy = batchRequest.getBackOffPolicy();
if (backOffPolicy != null) {
// Reset the BackOffPolicy at the start of each execute.
backOffPolicy.reset();
}
do {
retryAllowed = retriesRemaining > 0;
batchRequest.setContent(new MultipartMixedContent(requestInfos, "__END_OF_PART__"));
HttpResponse response = batchRequest.execute();
BatchUnparsedResponse batchResponse;
try {
// Find the boundary from the Content-Type header.
String boundary = "--" + response.getMediaType().getParameter("boundary");
// Parse the content stream.
InputStream contentStream = response.getContent();
batchResponse =
new BatchUnparsedResponse(contentStream, boundary, requestInfos, retryAllowed);
while (batchResponse.hasNext) {
batchResponse.parseNextResponse();
}
} finally {
response.disconnect();
}
List<RequestInfo<?, ?>> unsuccessfulRequestInfos = batchResponse.unsuccessfulRequestInfos;
if (!unsuccessfulRequestInfos.isEmpty()) {
requestInfos = unsuccessfulRequestInfos;
// backOff if required.
if (batchResponse.backOffRequired && backOffPolicy != null) {
long backOffTime = backOffPolicy.getNextBackOffMillis();
if (backOffTime != BackOffPolicy.STOP) {
sleep(backOffTime);
}
}
} else {