001    /*
002     * The contents of this file are subject to the terms
003     * of the Common Development and Distribution License
004     * (the "License").  You may not use this file except
005     * in compliance with the License.
006     *
007     * You can obtain a copy of the license at
008     * http://www.opensource.org/licenses/cddl1.php
009     * See the License for the specific language governing
010     * permissions and limitations under the License.
011     */
012    
013    package javax.ws.rs.ext;
014    
015    import javax.ws.rs.core.Response;
016    
017    /**
018     * Contract for a provider that maps Java exceptions to 
019     * {@link javax.ws.rs.core.Response}. An implementation of this interface must 
020     * be annotated with {@link Provider}.
021     * 
022     * @see Provider
023     * @see javax.ws.rs.core.Response
024     */
025    public interface ExceptionMapper<E extends Throwable> {
026    
027        /**
028         * Map an exception to a {@link javax.ws.rs.core.Response}. Returning 
029         * {@code null} results in a {@link javax.ws.rs.core.Response.Status#NO_CONTENT}
030         * response. Throwing a runtime exception results in a 
031         * {@link javax.ws.rs.core.Response.Status#INTERNAL_SERVER_ERROR} response
032         * @param exception the exception to map to a response
033         * @return a response mapped from the supplied exception
034         */
035        Response toResponse(E exception);
036    }