001/* 002 * Copyright 2015-2024 Ping Identity Corporation 003 * 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License (GPLv2 only) 006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 007 * as published by the Free Software Foundation. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, see <http://www.gnu.org/licenses>. 016 */ 017 018package com.unboundid.scim2.server.providers; 019 020import com.unboundid.scim2.common.annotations.NotNull; 021import com.unboundid.scim2.common.exceptions.ScimException; 022import com.unboundid.scim2.server.utils.ServerUtils; 023 024import jakarta.ws.rs.core.Context; 025import jakarta.ws.rs.core.HttpHeaders; 026import jakarta.ws.rs.core.Response; 027import jakarta.ws.rs.ext.ExceptionMapper; 028import jakarta.ws.rs.ext.Provider; 029 030/** 031 * A JAX-RS ExceptionMapper for ScimExceptions. 032 */ 033@Provider 034public class ScimExceptionMapper implements ExceptionMapper<ScimException> 035{ 036 @NotNull 037 @Context 038 private HttpHeaders headers; 039 040 /** 041 * {@inheritDoc} 042 */ 043 @NotNull 044 public Response toResponse(@NotNull final ScimException throwable) 045 { 046 return ServerUtils.setAcceptableType( 047 Response.status(throwable.getScimError().getStatus()). 048 entity(throwable.getScimError()), 049 headers.getAcceptableMediaTypes()).build(); 050 } 051}