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.InterruptedRuntimeException; 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.SERVICE_UNAVAILABLE; 016import static javax.ws.rs.core.Response.status; 017import static org.slf4j.LoggerFactory.getLogger; 018import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET; 019 020/** 021 * If an HTTP request's processing is interrupted, return an HTTP 503 Service Unavailable. 022 * 023 * @author Mike Durbin 024 */ 025@Provider 026public class InterruptedExceptionMapper implements 027 ExceptionMapper<InterruptedRuntimeException>, ExceptionDebugLogging { 028 029 private static final Logger LOGGER = getLogger(InterruptedExceptionMapper.class); 030 031 @Override 032 public Response toResponse(final InterruptedRuntimeException e) { 033 LOGGER.warn("Service interrupted", e); 034 return status(SERVICE_UNAVAILABLE).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); 035 } 036}