Announcement Announcement Module
Collapse
No announcement yet.
Exceptions thrown from Spring AspectJ annonotated Aspects and Jersery ExceptionMapper Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exceptions thrown from Spring AspectJ annonotated Aspects and Jersery ExceptionMapper

    I use Spring annotation based AOP for validating my Requests to the Jersery Resources. I have implemented an Aspect as follows. But this XBBridgeException is not caught by Jersey ExceptionMapper , instead it throws from the Servlet Container.

    Any tips on this?

    Code:
    @Aspect
    public class RequestValidationAspect {
    
        @Autowired
        private Validator validator;
    
        @Pointcut("execution(public * com.mycompany.facade.*.convertRequest(com.mycompany.BaseRequest+,..)) && args(req,..)")
        public void convertRequest(BaseRequest req) {
    
        }
    
        @Before("convertRequest(req)")
        public <T extends BaseRequest> void validateRequest(T req) throws XBBridgeException {
    
        Set<ConstraintViolation<T>> violations = null;
        try {
            violations = validator.validate(req, req.getValidatorGroup());
            if (!violations.isEmpty()) {
            throw new ValidationException("{validation exception}");
            }
        } catch (Throwable t) {
            t.printStackTrace();
            List<String> msgList = new ArrayList<>();
            String msg;
            if (t instanceof ValidationException) {
            msg = "{bad request}";
            for (ConstraintViolation<T> violation : violations) {
                msgList.add(violation.getPropertyPath().toString() + " " + violation.getMessage());
            }
            } else {
            msg = "{request:" + req.toString() + "}";
            msgList.add("Runtime error");
            }
            throw new XBBridgeException("request validation exception", new RequestValidationException(msg, msgList, t));
        }
        }
    
        public Validator getValidator() {
        return validator;
        }
    
        public void setValidator(Validator validator) {
        this.validator = validator;
        }
    
    }
Working...
X