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.GONE;
010import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
011import static org.slf4j.LoggerFactory.getLogger;
012
013import javax.ws.rs.core.Response;
014import javax.ws.rs.ext.ExceptionMapper;
015import javax.ws.rs.ext.Provider;
016
017import org.fcrepo.kernel.api.exception.SessionMissingException;
018
019import org.slf4j.Logger;
020
021/**
022 * If a session is requested that has been closed (or never existed), just
023 * return an HTTP 410 Gone.
024 *
025 * @author awoods
026 */
027@Provider
028public class SessionMissingExceptionMapper implements
029        ExceptionMapper<SessionMissingException>, ExceptionDebugLogging {
030
031    private static final Logger LOGGER =
032            getLogger(SessionMissingExceptionMapper.class);
033
034
035    @Override
036    public Response toResponse(final SessionMissingException e) {
037        debugException(this, e, LOGGER);
038        return status(GONE).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build();
039    }
040}