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.TombstoneException; 009 010import org.slf4j.Logger; 011 012import javax.ws.rs.core.Response; 013import javax.ws.rs.ext.ExceptionMapper; 014import javax.ws.rs.ext.Provider; 015 016import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE; 017import static javax.ws.rs.core.Response.Status.GONE; 018import static javax.ws.rs.core.Response.status; 019import static org.slf4j.LoggerFactory.getLogger; 020 021/** 022 * @author cabeer 023 * @since 10/16/14 024 */ 025@Provider 026public class TombstoneExceptionMapper implements 027 ExceptionMapper<TombstoneException>, ExceptionDebugLogging { 028 029 private static final Logger LOGGER = 030 getLogger(TombstoneExceptionMapper.class); 031 032 @Override 033 public Response toResponse(final TombstoneException e) { 034 LOGGER.debug(e.getMessage()); 035 final Response.ResponseBuilder response = status(GONE) 036 .entity(e.getMessage()); 037 038 if (e.getURI() != null) { 039 response.link(e.getURI(), "hasTombstone"); 040 } 041 042 return response.type(TEXT_PLAIN_TYPE).build(); 043 } 044}