Created
January 22, 2016 05:09
-
-
Save abhirockzz/f605c2eadd3e8169b163 to your computer and use it in GitHub Desktop.
Overriding the default exception mapper supplied by JAX-RS implementations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Provider | |
public class BeanValConstrainViolationExceptionMapper implements ExceptionMapper<ConstraintViolationException>{ | |
@Override | |
public Response toResponse(ConstraintViolationException e) { | |
System.out.println("BeanValConstrainViolationExceptionMapper in action"); | |
ConstraintViolation cv = (ConstraintViolation) e.getConstraintViolations().toArray()[0]; | |
//oh yeah... you need to shell out some $$$ ! | |
return Response.status(Response.Status.PAYMENT_REQUIRED) | |
.entity(new ConstraintViolationEntity(cv.getMessage())) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment