Example usage for org.aspectj.lang ProceedingJoinPoint proceed

List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint proceed.

Prototype

public Object proceed() throws Throwable;

Source Link

Document

Proceed with the next advice or target method invocation

Usage

From source file:com.maydesk.base.util.AspectChangedValueHandler.java

License:Mozilla Public License

@Around(value = "execution(* storeInputProperty(..))")
public void handleStoreInputProperty(ProceedingJoinPoint point) throws Throwable {
    point.proceed();
    if (point.getArgs()[1] instanceof IChangeSupportable) {
        IChangeSupportable cs = (IChangeSupportable) point.getArgs()[1];
        String propertyName = (String) point.getArgs()[2];
        System.out.println("XXX " + propertyName + " XXXXXXXXXXXXXXXXXXXXXXXXX");
        if (propertyName.equals(cs.getPropertyName())) {
            Object newInput = point.getArgs()[4];
            ((Component) cs).processInput(propertyName, newInput);
            Object newValue = cs.getValue();
            PDBinding changeSupport = cs.getChangeSupport();
            if (changeSupport != null) {
                changeSupport.doChange(cs, newValue);
            }//  w w w .j ava2  s  .  c  o m
        }
    }
}

From source file:com.maydesk.base.util.AspectExceptionHandler.java

License:Mozilla Public License

@Around(value = "execution(* actionPerformed(..))")
public void handleUnexpectedExceptionInActionListeners(ProceedingJoinPoint point) throws Throwable {
    try {/*  ww  w .j av a2s. c o  m*/
        long time = System.currentTimeMillis();
        point.proceed();
        time = System.currentTimeMillis() - time;
        if (time > 3000) {
            String msg = "Long operation " + time + ": " + PDUserSession.getInstance().getUser() + " at "
                    + point;
            System.out.println(msg);
        }
    } catch (Exception e) {
        try {
            e.printStackTrace();

            // construct the message text
            String stage = "";
            if (PDDesktop.getInstance() != null) {
                stage = "Stage1"; //PDApplicationInstance.getActivePD().getEnvironment();
            }

            String msg = "An error has occurred: \n\n";
            msg += "User: " + PDUserSession.getInstance().getUser() + "\n";
            msg += "Stage: " + stage + "\n\n";
            msg += "Error: " + ExceptionUtils.getStackTrace(e);

            // send an email
            try {
                MDMailUtil.sendMail("mail@chrismay.de", "Error in MayDesk " + stage, msg, null);
            } catch (Exception ex) {
                System.out.println("Mail not configured!");
                ex.printStackTrace();
            }

            // show error dialog
            if (PDDesktop.getInstance() != null) {
                String msg2 = "An unexpected programm error occurred!\n\n";
                msg2 += "Error type: " + e.getMessage() + "\n\n";
                msg2 += "An email has been sent automatically to the admin; we will fix the error as soon as possible - sorry for the inconvenience";
                PDMessageBox.msgBox("Unexpected Error", msg2, 360, 240);
            }

            // rollback hibernate transaction
            ContainerContext context = (ContainerContext) ApplicationInstance.getActive()
                    .getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME);
            PDHibernateMasterFactory factory = (PDHibernateMasterFactory) context.getSession()
                    .getAttribute(MDServlet.HIBERNATE_FACTORY);
            if (factory.hasOpenSession()) {
                Session session = PDHibernateFactory.getSession();
                session.getTransaction().rollback();
                session.close();
            }
        } catch (Exception ex2) {
            ex2.printStackTrace();
        }
    }
}

From source file:com.mengge.events.DefaultAspect.java

License:Apache License

@Around(AROUND)
public Object doAround(ProceedingJoinPoint point) throws Throwable {
    Throwable t = null;// w w  w.j  a  v a 2s .  c  o  m
    Object result = null;
    try {
        result = point.proceed();
    } catch (Throwable e) {
        t = e;
    }
    if (t != null) {
        Throwable rootCause = getRootCause(t);
        listener.onException(rootCause, driver);
        throw rootCause;
    }

    if (result == null) { // maybe it was "void"
        return result;
    }
    if (List.class.isAssignableFrom(result.getClass())) {
        return returnProxyList((List<Object>) result);
    }

    return transformToListenable(result);
}

From source file:com.mir00r.aspect.EmpAspect.java

public void AroundAdvice(ProceedingJoinPoint proceedingJoinPoint) {
    try {/*from   w  w w . j a v a2s.co m*/
        System.out.println("Before advice ");
        proceedingJoinPoint.proceed();
        System.out.println("After Returning");
    } catch (Throwable e) {
        System.out.println("After Throwable");
    }
    System.out.println("Finally -----");

}

From source file:com.moz.fiji.mapreduce.util.MRLogTimerAspect.java

License:Apache License

/**
 * Advice around functions that match PointCut "profile".
 *
 * @param thisJoinPoint The JoinPoint that matched the pointcut.
 * @return Object returned by function which matched PointCut "profile".
 * @throws Throwable if there is an exception in the function the advice surrounds.
 *//*from  w w w .j  ava2 s  . c  om*/
@Around("execution(* com.moz.fiji.mapreduce.impl.HFileWriterContext.put(..)) || "
        + "execution(* com.moz.fiji.mapreduce.framework.FijiTableInputFormat.FijiTableRecordReader.nextKeyValue(..))")
public Object aroundProfileMethods(final ProceedingJoinPoint thisJoinPoint) throws Throwable {
    final long start, end;
    start = System.nanoTime();
    Object returnanswer = thisJoinPoint.proceed();
    end = System.nanoTime();
    String funcSig = thisJoinPoint.getSignature().toLongString();

    final LoggingInfo existing = mSignatureTimeMap.putIfAbsent(funcSig, new LoggingInfo(end - start, 1));
    if (existing != null) {
        existing.increment(end - start);
    }
    return returnanswer;
}

From source file:com.moz.fiji.schema.util.LogTimerAspect.java

License:Apache License

/**
 * Advice around functions that match PointCut "profile".
 *
 * @param thisJoinPoint The JoinPoint that matched the pointcut.
 * @return Object returned by function which matched PointCut "profile".
 * @throws Throwable if there is an exception in the function the advice surrounds.
 *//*from w  w w. j  ava 2  s . com*/
@Around("execution(* com.moz.fiji.schema.FijiCellDecoder.*(..)) || "
        + "execution(* com.moz.fiji.schema.FijiCellEncoder.*(..)) || "
        + "execution(* com.moz.fiji.schema.FijiMetaTable.*(..)) || "
        + "execution(* com.moz.fiji.schema.FijiSchemaTable.*(..)) || "
        + "execution(* com.moz.fiji.schema.FijiPutter.put(..))")
public Object aroundProfileMethods(final ProceedingJoinPoint thisJoinPoint) throws Throwable {
    final long start, end;
    start = System.nanoTime();
    Object returnanswer = thisJoinPoint.proceed();
    end = System.nanoTime();
    String funcSig = thisJoinPoint.getSignature().toLongString();
    if (!mSignatureTimeMap.containsKey(funcSig)) {
        mSignatureTimeMap.put(funcSig, new LoggingInfo(end - start, 1));
    } else {
        mSignatureTimeMap.get(funcSig).increment(end - start);
    }
    return returnanswer;
}

From source file:com.mpobjects.rtcalltree.rec.AspectJRecorder.java

License:Apache License

public Object record(ProceedingJoinPoint aJoinPoint) throws Throwable {
    final MutableCalltreeEntry entry = createEntry(aJoinPoint);
    final CalltreeRecord record = calltreeRecordProvider.getRecord();
    record.start(entry);//from   www .j a  v  a2  s  . com
    try {
        return aJoinPoint.proceed();
    } catch (Throwable e) {
        throw e;
    } finally {
        record.stop(entry);
    }
}

From source file:com.mycom.products.mywebsite.backend.aspect.AjaxExceptionHandlerAspect.java

License:Open Source License

@SuppressWarnings("unchecked")
@Around(value = "methodAnnotatedWithHandleAjaxException(ajaxException) && publicMethod() && !initBinderMethod()")
public @ResponseBody Map<String, Object> handleExeptionforajaxMethods(ProceedingJoinPoint joinPoint,
        HandleAjaxException ajaxException) throws Throwable {
    Map<String, Object> response = new HashMap<>();
    try {//from   w  w w  .  j  av  a2s. c  o m
        response = (Map<String, Object>) joinPoint.proceed();
    } catch (Exception e) {
        errorLogger.error(BaseBean.LOG_BREAKER_OPEN);
        errorLogger.error(e.getMessage(), e);
        errorLogger.error(BaseBean.LOG_BREAKER_CLOSE);
        response.put("status", HttpStatus.BAD_REQUEST);
        // default title and message
        String title = "Bad Request";
        String message = messageSource.getMessage("Serverity.common.Page.AjaxError");

        if (e instanceof ServletRequestBindingException) {
            title = "";
            message = e.getMessage();
            // send an e-mail to authorized person
        } else if (e instanceof DuplicatedEntryException) {
            title = "Duplicated";
            message = messageSource.getMessage("Serverity.common.Page.DuplicatedRecordErrorMessage");

        } else if (e instanceof ConsistencyViolationException) {
            title = "Rejected";
            message = messageSource.getMessage("Serverity.common.Page.ConsistencyViolationErrorMessage");

        }
        response.put("pageMessage", new PageMessage(title, message, PageMessageStyle.ERROR.getValue()));
    }
    return response;

}

From source file:com.mycom.products.mywebsite.backend.aspect.ServletExceptionHandlerAspect.java

License:Open Source License

@Around(value = "methodAnnotatedWithHandleServletException(servletException) && publicMethod() && !initBinderMethod()")
public String handleExeptionforServletMethods(ProceedingJoinPoint joinPoint,
        HandleServletException servletException) throws Throwable {
    String pageSuccessReturn = null;
    String errorView = servletException.errorView();
    PageMode pageMode = servletException.pageMode();
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    ValidateEntity validationMapper = method.getAnnotation(ValidateEntity.class);
    Model model = null;/*from   www  . j  a  v a2 s.c o m*/
    Errors errors = null;
    Object validationTarget = null;
    Object[] arguments = joinPoint.getArgs();
    for (Object arg : arguments) {
        if (arg != null) {
            if (arg instanceof BindingAwareModelMap) {
                model = (Model) arg;
            }
            if (validationMapper != null && arg instanceof BeanPropertyBindingResult) {
                errors = (Errors) arg;
            }
            if (validationMapper != null && arg instanceof BaseBean) {
                validationTarget = arg;
            }
        }
    }
    try {
        if (validationMapper != null) {
            BaseValidator validator = appContext.getBean(validationMapper.validator());
            validator.setPageMode(pageMode);
            validator.validate(validationTarget, errors);
            if (errors.hasErrors()) {
                throw new ValidationFailedException(BaseBean.LOG_PREFIX + "Validation failed for '"
                        + validationTarget.getClass().getSimpleName() + "'." + BaseBean.LOG_SUFFIX);
            }
        }
        pageSuccessReturn = (String) joinPoint.proceed();
    } catch (Exception e) {
        errorLogger.error(BaseBean.LOG_BREAKER_OPEN);
        errorLogger.error(e.getMessage(), e);
        if (errorLogger.isDebugEnabled()) {
            if (e instanceof ValidationFailedException) {
                Map<String, String> validationErrors = new HashMap<>();
                List<FieldError> errorFields = errors.getFieldErrors();
                errorFields.forEach(item -> {
                    if (!validationErrors.containsKey(item.getField())) {
                        validationErrors.put(item.getField(), item.getDefaultMessage());
                    }
                });
                validationErrors.entrySet().forEach(entry -> {
                    errorLogger.debug(entry.getKey() + " ==> " + entry.getValue());
                });
            }
        }
        errorLogger.error(BaseBean.LOG_BREAKER_CLOSE);
        if (model != null) {
            model.addAttribute("pageMode", pageMode);
        }
        if (e instanceof ValidationFailedException) {
            if (errorView.length() == 0) {
                errorView = "error/500";
            } else {
                if (model != null && errors != null) {
                    model.addAttribute("pageMode", pageMode);
                    Map<String, String> validationErrors = new HashMap<>();
                    List<FieldError> errorFields = errors.getFieldErrors();
                    errorFields.forEach(item -> {
                        if (!validationErrors.containsKey(item.getField())) {
                            validationErrors.put(item.getField(), item.getDefaultMessage());
                        }
                    });
                    model.addAttribute("validationErrors", validationErrors);
                    model.addAttribute("pageMessage",
                            new PageMessage("Validation Error",
                                    messageSource.getMessage("Validation.common.Page.ValidationErrorMessage"),
                                    PageMessageStyle.ERROR.getValue()));
                }
            }
        } else if (e instanceof DuplicatedEntryException) {
            if (errorView.length() == 0) {
                errorView = "error/208";
            } else {
                if (model != null) {
                    model.addAttribute("pageMessage",
                            new PageMessage("Duplicated",
                                    messageSource
                                            .getMessage("Serverity.common.Page.DuplicatedRecordErrorMessage"),
                                    PageMessageStyle.ERROR.getValue()));
                }
            }
        } else if (e instanceof ConsistencyViolationException) {
            if (errorView.length() == 0) {
                errorView = "error/226";
            } else {
                if (model != null) {
                    model.addAttribute("pageMessage",
                            new PageMessage("Rejected",
                                    messageSource.getMessage(
                                            "Serverity.common.Page.ConsistencyViolationErrorMessage"),
                                    PageMessageStyle.ERROR.getValue()));
                }
            }
        } else if (e instanceof BusinessException) {
            if (errorView.length() == 0) {
                errorView = "error/500";
            } else {
                if (model != null) {
                    model.addAttribute("pageMessage",
                            new PageMessage("Application Error",
                                    messageSource.getMessage("Serverity.common.Page.ApplicationErrorMessage"),
                                    PageMessageStyle.ERROR.getValue()));
                }
            }
        } else {
            if (errorView.length() == 0) {
                errorView = "error/500";
            } else {
                if (model != null) {
                    model.addAttribute("pageMessage",
                            new PageMessage("Server Error",
                                    messageSource.getMessage("Serverity.common.Page.ServerErrorMessage"),
                                    PageMessageStyle.ERROR.getValue()));
                }
            }
        }
    }
    if (errorView.length() == 0) {
        errorView = "error/500";
    }
    return pageSuccessReturn == null ? errorView : pageSuccessReturn;

}

From source file:com.mycompany.aspect.InterceptorLog.java

@Around("execution(* execution(*com.mycompany.dao.SobaDaoImp.addStudentAround (..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("logAround() metoda je pozvana!");
    System.out.println("presretanje metode : " + joinPoint.getSignature().getName());
    System.out.println("presretanje : " + Arrays.toString(joinPoint.getArgs()));
    System.out.println("Around before metoda jepozvana");
    joinPoint.proceed();
    System.out.println("Around metoda je pozvana!");
    System.out.println("******");
}