public void onNoMoreChecksums()
throws ChecksumFailureException
throw new ChecksumFailureException( "Checksum validation failed, no checksums available" );
/**
* Creates a new exception with the specified cause. The resulting exception is not {@link #isRetryWorthy()
* retry-worthy}.
* @param cause The exception that caused this one, may be {@code null}.
public ChecksumFailureException( Throwable cause )
this( "Checksum validation failed" + getMessage( ": ", cause ), cause );
boolean retry = trial < lastTrial && e.isRetryWorthy();
if ( !retry && !checksumValidator.handle( e ) )
boolean retry = trial < lastTrial && e.isRetryWorthy();
if ( !retry && !checksumValidator.handle( e ) )
public void onNoMoreChecksums()
throws ChecksumFailureException
throw new ChecksumFailureException( "Checksum validation failed, no checksums available" );
/**
* Creates a new exception with the specified cause. The resulting exception is not {@link #isRetryWorthy()
* retry-worthy}.
* @param cause The exception that caused this one, may be {@code null}.
public ChecksumFailureException( Throwable cause )
this( "Checksum validation failed" + getMessage( ": ", cause ), cause );
private
boolean validateInlinedChecksums( Map<String, ?> actualChecksums, Map<String, ?> inlinedChecksums )
throws ChecksumFailureException
for ( Map.Entry<String, ?> entry : inlinedChecksums.entrySet() )
String algo = entry.getKey();
Object calculated = actualChecksums.get( algo );
if ( !( calculated instanceof String ) )
continue;
String actual = String.valueOf( calculated );
String expected = entry.getValue().toString();
checksumFiles.put( getChecksumFile( algo ), expected );
if ( !isEqualChecksum( expected, actual ) )
checksumPolicy.onChecksumMismatch( algo, ChecksumPolicy.KIND_UNOFFICIAL,
new ChecksumFailureException( expected, actual ) );
else if ( checksumPolicy.onChecksumMatch( algo, ChecksumPolicy.KIND_UNOFFICIAL ) )
return true;
return false;
public boolean onTransferChecksumFailure( ChecksumFailureException exception )
String msg =
"Could not validate integrity of download from " + resource.getRepositoryUrl() + resource.getResourceName();
if ( logger.isDebugEnabled() )
logger.warn( msg, exception );
logger.warn( msg + ": " + exception.getMessage() );
return true;
private boolean validateInlinedChecksums( Map<String, ?> actualChecksums, Map<String, ?> inlinedChecksums )
throws ChecksumFailureException
for ( Map.Entry<String, ?> entry : inlinedChecksums.entrySet() )
String algo = entry.getKey();
Object calculated = actualChecksums.get( algo );
if ( !( calculated instanceof
String ) )
continue;
String actual = String.valueOf( calculated );
String expected = entry.getValue().toString();
checksumFiles.put( getChecksumFile( algo ), expected );
if ( !isEqualChecksum( expected, actual ) )
checksumPolicy.onChecksumMismatch( algo, ChecksumPolicy.KIND_UNOFFICIAL,
new ChecksumFailureException( expected, actual ) );
else if ( checksumPolicy.onChecksumMatch( algo, ChecksumPolicy.KIND_UNOFFICIAL ) )
return true;
return false;
public boolean onTransferChecksumFailure( ChecksumFailureException exception )
String msg =
"Could not validate integrity of download from " + resource.getRepositoryUrl() + resource.getResourceName();
if ( logger.isDebugEnabled() )
logger.warn( msg, exception );
logger.warn( msg + ": " + exception.getMessage() );
return true;
throw new ChecksumFailureException( e );
throw new ChecksumFailureException( e );
throw new ChecksumFailureException( expected, actual );
String expected = ChecksumUtils.read(temporaryChecksumFile.file);
if (!expected.equalsIgnoreCase(actual)) {
throw new ChecksumFailureException(expected, actual);
throw new ChecksumFailureException(e);
if ( !verified )
throw new ChecksumFailureException( sum, crcs.get( entry.getKey() ).toString() );
throw new ChecksumFailureException( "no supported algorithms found" );
private void validateChecksums(File temporaryFileInLocalRepository, File fileInLocalRepository, String uri, TransferResource transferResource) throws Exception {
boolean failOnInvalidOrMissingCheckums = RepositoryPolicy.CHECKSUM_POLICY_FAIL.equals(checksumPolicy);
try {
Map<String, Object> checksums = ChecksumUtils.calc(temporaryFileInLocalRepository, checksumAlgos.keySet());
if (!verifyChecksums(temporaryFileInLocalRepository, fileInLocalRepository, uri, checksums)) {
throw new ChecksumFailureException("Checksum validation failed" + ", no checksums available from the repository");
} catch (Exception e) {
transferCorrupted(download, newEvent(transferResource, e, RequestType.GET, EventType.CORRUPTED).build());
if (failOnInvalidOrMissingCheckums) {
transferFailed(download, newEvent(transferResource, e, RequestType.GET, EventType.FAILED).build());
throw e;
if
( calculated instanceof Exception )
checksumPolicy.onChecksumError( algo, 0, new ChecksumFailureException( (Exception) calculated ) );
continue;
checksumPolicy.onChecksumError( algo, 0, new ChecksumFailureException( e ) );
continue;
checksumPolicy.onChecksumMismatch( algo, 0, new ChecksumFailureException( expected, actual ) );
checksumPolicy.onChecksumError( algo, 0, new ChecksumFailureException( e ) );
if
( calculated instanceof Exception )
checksumPolicy.onChecksumError( algo, 0, new ChecksumFailureException( (Exception) calculated ) );
continue;
checksumPolicy.onChecksumError( algo, 0, new ChecksumFailureException( e ) );
continue;
checksumPolicy.onChecksumMismatch( algo, 0, new ChecksumFailureException( expected, actual ) );
checksumPolicy.onChecksumError( algo, 0, new ChecksumFailureException( e ) );
throw new ChecksumFailureException( "Checksum validation failed"
+ ", no checksums available from the repository" );