use of com.zimbra.common.httpclient.InputStreamRequestHttpRetryHandler in project zm-mailbox by Zimbra.
the class HttpStoreManager method writeStreamToStore.
@Override
public String writeStreamToStore(InputStream in, long actualSize, Mailbox mbox) throws IOException, ServiceException {
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw ServiceException.FAILURE("SHA-256 digest not found", e);
}
ByteUtil.PositionInputStream pin = new ByteUtil.PositionInputStream(new DigestInputStream(in, digest));
HttpClientBuilder clientBuilder = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
clientBuilder.setRetryHandler(new InputStreamRequestHttpRetryHandler());
HttpClient client = clientBuilder.build();
HttpPost post = new HttpPost(getPostUrl(mbox));
try {
InputStreamEntity entity = new InputStreamEntity(pin, actualSize, ContentType.APPLICATION_OCTET_STREAM);
post.setEntity(entity);
HttpResponse httpResp = HttpClientUtil.executeMethod(client, post);
int statusCode = httpResp.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED || statusCode == HttpStatus.SC_NO_CONTENT) {
return getLocator(post, ByteUtil.encodeFSSafeBase64(digest.digest()), pin.getPosition(), mbox, httpResp);
} else {
throw ServiceException.FAILURE("error POSTing blob: " + httpResp.getStatusLine().getReasonPhrase(), null);
}
} catch (HttpException e) {
throw new IOException("error POSTing blob: " + e.getMessage());
} finally {
post.releaseConnection();
}
}
Aggregations