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