@Test public void toResponseStandard() { RollbackExceptionMapper mapper = new RollbackExceptionMapper(); RollbackException e = new RollbackException("Standard Rollback Exception"); Response r = mapper.toResponse(e); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), r.getStatus()); assertNotNull(r.getEntity()); StandardError error = (StandardError) r.getEntity(); assertEquals("Standard Rollback Exception", error.getMessage()); }
@Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; }
RollbackExceptionMapper implements ExceptionMapper<RollbackException> { @Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; } }
RollbackExceptionMapper implements ExceptionMapper<RollbackException> { @Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; }  }
RollbackExceptionMapper implements ExceptionMapper<RollbackException> { @Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; }  @Override Response toResponse(RollbackException exception); }
RollbackExceptionMapper implements ExceptionMapper<RollbackException> { @Override public Response toResponse(RollbackException exception) { Response response = null; if (exception.getCause() instanceof ConstraintViolationException) { ConstraintViolationException e = (ConstraintViolationException) exception.getCause(); List<StandardError> errors = new ArrayList<StandardError>(); for (ConstraintViolation<?> cv : e.getConstraintViolations()) { errors.add(new StandardError(cv)); } response = Response.status(Response.Status.BAD_REQUEST).entity(errors) .type(MediaType.APPLICATION_JSON).build(); } else { response = Response.status(Response.Status.BAD_REQUEST).entity(new StandardError(exception)) .type(MediaType.APPLICATION_JSON).build(); } return response; }  @Override Response toResponse(RollbackException exception);  }