001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.http.commons.exceptionhandlers; 007 008import org.fcrepo.kernel.api.exception.InvalidChecksumException; 009import org.slf4j.Logger; 010 011import javax.ws.rs.core.Response; 012import javax.ws.rs.ext.ExceptionMapper; 013import javax.ws.rs.ext.Provider; 014 015import static javax.ws.rs.core.Response.Status.CONFLICT; 016import static javax.ws.rs.core.Response.status; 017import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET; 018import static org.slf4j.LoggerFactory.getLogger; 019 020/** 021 * Translate InvalidChecksumException errors into reasonable 022 * HTTP error codes 023 * 024 * @author awoods 025 * @author ajs6f 026 * @author cbeer 027 */ 028@Provider 029public class InvalidChecksumExceptionMapper implements 030 ExceptionMapper<InvalidChecksumException>, ExceptionDebugLogging { 031 032 private static final Logger LOGGER = 033 getLogger(InvalidChecksumExceptionMapper.class); 034 035 @Override 036 public Response toResponse(final InvalidChecksumException e) { 037 LOGGER.debug("Invalid checksum", e); 038 039 return status(CONFLICT).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); 040 } 041}