@Override public Response toResponse(final InvalidChecksumException e) { LOGGER.error("InvalidChecksumException intercepted by InvalidChecksumExceptionMapper: {}\n", e.getMessage()); debugException(this, e, LOGGER); return status(CONFLICT).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); } }
final StringBuilder error = new StringBuilder(); checksumErrors.forEach((key, value) -> error.append(String.format(template, key, value))); throw new InvalidChecksumException(error.toString());
private void verifyChecksums(final Collection<URI> checksums) throws InvalidChecksumException, RepositoryException { Property property = null; if (isProxy()) { property = getProperty(PROXY_FOR); } else if (isRedirect()) { property = getProperty(REDIRECTS_TO); } // what else could it be? final Map<URI, URI> checksumErrors = new HashMap<>(); final CacheEntry cacheEntry = CacheEntryFactory.forProperty(property); // Loop through provided checksums validating against computed values for (final URI check : checksums) { final String algorithm = ContentDigest.getAlgorithm(check); for (final FixityResult result : cacheEntry.checkFixity(algorithm)) { if (!result.matches(check)) { LOGGER.debug("Failed checksum test"); checksumErrors.put(check, result.getComputedChecksum()); } } } // Throw an exception if any checksum errors occurred if (!checksumErrors.isEmpty()) { final String template = "Checksum Mismatch of %1$s and %2$s\n"; final StringBuilder error = new StringBuilder(); checksumErrors.forEach((key, value) -> error.append(String.format(template, key, value))); throw new InvalidChecksumException(error.toString()); } }