private static RemoteHashResponse doRetrieveChecksumItem(ProxyRepository proxy, ResourceStoreRequest request,
StorageItem artifact, String inspector, String attrname,
String noattrname)
throws ItemNotFoundException, LocalStorageException
{
final RepositoryItemUid itemUid = artifact.getRepositoryItemUid();
itemUid.getLock().lock(Action.read);
try {
final Attributes attributes = artifact.getRepositoryItemAttributes();
if (attributes == null) {
throw new LocalStorageException("Null item repository attributes");
}
if (Boolean.parseBoolean(attributes.get(noattrname)) && !request.isRequestAsExpired()) {
throw new ItemNotFoundException(request);
}
String hash = attributes.get(attrname);
if (hash == null || request.isRequestAsExpired()) {
try {
final StorageFileItem remoteItem =
(StorageFileItem) proxy.getRemoteStorage().retrieveItem(proxy, request, proxy.getRemoteUrl());
hash = MUtils.readDigestFromFileItem(remoteItem); // closes http input stream
}
catch (ItemNotFoundException e) {
// fall through
}
catch (RemoteAccessException e) {
// fall through
}
catch (RemoteStorageException e) {
// this is (potentially) transient network or remote server problem will be cached
// there is no automatic retry for this hash time
// either expire the artifact or request the hash asExpired to retry
}
doStoreChechsumItem(proxy, artifact, attrname, noattrname, hash);
}
if (hash != null) {
return new RemoteHashResponse(inspector, hash, newHashItem(proxy, request, artifact, hash));
}
else {
throw new ItemNotFoundException(request);
}
}
catch (IOException e) {
throw new LocalStorageException(e);
}
finally {
itemUid.getLock().unlock();
}
}