我有以下泽西终点:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/sessionlog")
@Consumes(MediaType.APPLICATION_JSON)
public Response getSessionLog(@HeaderParam(CLIENT_HEADER_PARAM) String clientId,
@QueryParam("sessionId") Long sessionId,
@QueryParam("callback") String callback) {
}
我想创建一个处理程序,拦截可能在此端点内发生的任何异常以及应用程序上的所有其他端点。我不想抛出任何东西,在try ... catch中包装代码,我只是希望这个处理程序接受任何异常,理想情况下,响应特殊响应。如何实现?
我试过这个
@Provider
public class RestExceptionMapper implements ExceptionMapper<Exception> {
public Response toResponse(Exception exception){
return Response.status(Response.Status.NOT_FOUND).
entity(new ErrorResponse(exception.getClass().toString(),
exception.getMessage()) ).
build();
}
}
但是我想创建一个try..catch ...在我的端点中抛出免费代码。感谢