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 static javax.ws.rs.core.Response.status; 009import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 010import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET; 011import static org.slf4j.LoggerFactory.getLogger; 012 013import org.fcrepo.kernel.api.exception.InvalidMementoPathException; 014import org.slf4j.Logger; 015 016import javax.servlet.ServletContext; 017import javax.ws.rs.core.Context; 018import javax.ws.rs.core.Link; 019import javax.ws.rs.core.Response; 020import javax.ws.rs.core.UriInfo; 021import javax.ws.rs.ext.Provider; 022/** 023 * @author lsitu 024 * @since 2018-08-10 025 */ 026@Provider 027public class InvalidMementoPathExceptionMapper 028 extends ConstraintExceptionMapper<InvalidMementoPathException> 029 implements ExceptionDebugLogging { 030 031 private static final Logger LOGGER = getLogger(InvalidMementoPathExceptionMapper.class); 032 033 @Context 034 private UriInfo uriInfo; 035 036 @Context 037 private ServletContext context; 038 039 @Override 040 public Response toResponse(final InvalidMementoPathException e) { 041 debugException(this, e, LOGGER); 042 final Link link = buildConstraintLink(e, context, uriInfo); 043 final String msg = e.getMessage(); 044 return status(BAD_REQUEST).entity(msg).links(link).type(TEXT_PLAIN_WITH_CHARSET).build(); 045 } 046 047}