Conflict不会被ConflictExceptionMapper捕获的ConflictException抛出

时间:2017-03-13 17:38:29

标签: java jersey

我是泽西新手,我想在我的服务中抛出一个ConflictException(自定义), 并抓住它作出回应。

以下是我的代码..

public class ConflictException extends ClientErrorException {
    public ConflictException() {
        super(Response.Status.CONFLICT); // 409
    }
}

然后我想使用ExceptionMapper发送适当的响应。

@Provider
public class ConflictExceptionMapper implements ExceptionMapper<ConflictException> {
    @Override
    public Response toResponse(ConflictException exception) {
        return Response.status(Response.Status.CONFLICT).entity(new ResponseMessage( Collections.emptyList(), OperationResultStatus.Conflict,
                exception.getMessage())).build();
    }
}

不知何故,这个Mapper没有被触发。

我做错了什么......

更新!!!剪掉了我的主要课程。

final ResourceConfig rc = new ResourceConfig().packages(packages)
                // Now you can expect validation errors to be sent to the client.
                .property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true)
                // @ValidateOnExecution annotations on subclasses won't cause errors.
                .property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true)
                // Further configuration of ResourceConfig.
                //.property(ServerProperties.PROCESSING_RESPONSE_ERRORS_ENABLED, true)
                .register(new ClassBinder())
                .register(json)
                .register(ConstraintViolationExceptionMapper.class)
                .register(ConflictExceptionMapper.class);

0 个答案:

没有答案
相关问题