List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed
public Object proceed(Object[] args) throws Throwable;
From source file:com.seleniumtests.uipage.aspects.ReplayAction.java
License:Apache License
/** * Replay all actions annotated by ReplayOnError if the class is not a subclass of * HtmlElement/* w w w .j a v a 2s . c o m*/ * @param joinPoint * @throws Throwable */ @Around("!execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))" + "&& execution(@com.seleniumtests.uipage.ReplayOnError public * * (..)) && @annotation(replay)") public Object replay(ProceedingJoinPoint joinPoint, ReplayOnError replay) throws Throwable { int replayDelayMs = replay != null ? replay.replayDelayMs() : 100; Instant end = systemClock.instant() .plusSeconds(SeleniumTestsContextManager.getThreadContext().getReplayTimeout()); Object reply = null; String targetName = joinPoint.getTarget().toString(); TestAction currentAction = null; if (joinPoint.getTarget() instanceof GenericPictureElement) { String methodName = joinPoint.getSignature().getName(); List<String> pwdToReplace = new ArrayList<>(); String actionName = String.format("%s on %s %s", methodName, targetName, LogAction.buildArgString(joinPoint, pwdToReplace, new HashMap<>())); currentAction = new TestAction(actionName, false, pwdToReplace); // log action before its started. By default, it's OK. Then result may be overwritten if step fails // order of steps is the right one (first called is first displayed) if (isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { TestLogging.getParentTestStep().addAction(currentAction); } } boolean actionFailed = false; try { while (end.isAfter(systemClock.instant())) { try { reply = joinPoint.proceed(joinPoint.getArgs()); WaitHelper.waitForMilliSeconds(200); break; } catch (Throwable e) { // do not replay when error comes from test writing or configuration if (e instanceof ScenarioException || e instanceof ConfigurationException || e instanceof DatasetException) { throw e; } if (end.minusMillis(200).isAfter(systemClock.instant())) { WaitHelper.waitForMilliSeconds(replayDelayMs); continue; } else { throw e; } } } return reply; } catch (Throwable e) { actionFailed = true; throw e; } finally { if (currentAction != null && isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { currentAction.setFailed(actionFailed); if (joinPoint.getTarget() instanceof GenericPictureElement) { currentAction.setDurationToExclude( ((GenericPictureElement) joinPoint.getTarget()).getActionDuration()); } } } }
From source file:com.seleniumtests.uipage.aspects.SeleniumNativeActions.java
License:Apache License
/** * Intercept any call to findElement made from a PageObject subclass and returns a HtmlElement instead of a RemoteWebElement * This way, every action done on this element will benefit from HtmlElement mechanism * @param joinPoint//ww w . j a v a2 s. c om * @return * @throws Throwable */ @Around("this(com.seleniumtests.uipage.PageObject) && " + // caller is a PageObject "(call(public * org.openqa.selenium.WebDriver+.findElement (..))" + ")") public Object interceptFindHtmlElement(ProceedingJoinPoint joinPoint) throws Throwable { if (doOverride()) { return new HtmlElement("", (By) (joinPoint.getArgs()[0]), currentFrame); } else { return joinPoint.proceed(joinPoint.getArgs()); } }
From source file:com.seleniumtests.uipage.aspects.SeleniumNativeActions.java
License:Apache License
@Around("this(com.seleniumtests.uipage.PageObject) && " + // caller is a PageObject "(call(public * org.openqa.selenium.WebDriver+.findElements (..))" + ")") public Object interceptFindsHtmlElement(ProceedingJoinPoint joinPoint) throws Throwable { if (doOverride()) { return new HtmlElement("", (By) (joinPoint.getArgs()[0]), currentFrame).findElements(); } else {// ww w. j ava 2 s . c om return joinPoint.proceed(joinPoint.getArgs()); } }
From source file:com.seleniumtests.uipage.aspects.SeleniumNativeActions.java
License:Apache License
/** * Method interceptFindHtmlElement creates an HtmlElement from findElement, but does not handle frames. * Here, we record all switchTo().frame(WebElement) call to create a FrameElement chain * @param joinPoint//from ww w . ja v a 2 s.co m * @return * @throws Throwable */ @Around("this(com.seleniumtests.uipage.PageObject) && " + // caller is a PageObject "(call(public * org.openqa.selenium.support.ui.ExpectedConditions.frameToBeAvailableAndSwitchToIt (..))" + ")") public Object recordFrameSwitch(ProceedingJoinPoint joinPoint) throws Throwable { if (doOverride()) { Object frameArg = joinPoint.getArgs()[0]; FrameElement frameEl = getFrameElement(frameArg); if (frameEl == null) { return joinPoint.proceed(joinPoint.getArgs()); } if (currentFrame == null) { currentFrame = frameEl; } else { frameEl.setFrameElement(currentFrame); currentFrame = frameEl; } return new ExpectedCondition<WebDriver>() { @Override public WebDriver apply(WebDriver driver) { try { return driver; } catch (NoSuchFrameException e) { return null; } } @Override public String toString() { return "frame to be available: " + frameArg; } }; } else { return joinPoint.proceed(joinPoint.getArgs()); } }
From source file:com.seleniumtests.uipage.aspects.SeleniumNativeActions.java
License:Apache License
/** * Method interceptFindHtmlElement creates an HtmlElement from findElement, but does not handle frames. * Here, we record all switchTo().frame(WebElement) call to create a FrameElement chain * @param joinPoint/*www . j a va2s . co m*/ * @return * @throws Throwable */ @Around("this(com.seleniumtests.uipage.PageObject) && " + // caller is a PageObject "(call(public * org.openqa.selenium.WebDriver.TargetLocator+.frame (..))" + ")") public Object recordSwitchToFramCalls(ProceedingJoinPoint joinPoint) throws Throwable { if (doOverride()) { Object frameArg = joinPoint.getArgs()[0]; FrameElement frameEl = getFrameElement(frameArg); if (frameEl == null) { return joinPoint.proceed(joinPoint.getArgs()); } if (currentFrame == null) { currentFrame = frameEl; } else { frameEl.setFrameElement(currentFrame); currentFrame = frameEl; } return null; } else { return joinPoint.proceed(joinPoint.getArgs()); } }
From source file:com.seleniumtests.uipage.aspects.SeleniumNativeActions.java
License:Apache License
@Around("this(com.seleniumtests.uipage.PageObject) && " + // caller is a PageObject "(call(public * org.openqa.selenium.WebDriver.TargetLocator+.defaultContent (..))" + ")") public Object recordSwitchDefaultContext(ProceedingJoinPoint joinPoint) throws Throwable { currentFrame = null;/*from ww w . j av a2 s.c om*/ return joinPoint.proceed(joinPoint.getArgs()); }
From source file:com.seleniumtests.uipage.aspects.SeleniumNativeActions.java
License:Apache License
@Around("this(com.seleniumtests.uipage.PageObject) && " + // caller is a PageObject "(call(public * org.openqa.selenium.WebDriver.TargetLocator+.parentFrame (..))" + ")") public Object recordSwitchParentFrame(ProceedingJoinPoint joinPoint) throws Throwable { if (currentFrame == null || !doOverride()) { return joinPoint.proceed(joinPoint.getArgs()); } else {//from w ww . ja v a 2 s . c o m currentFrame = currentFrame.getFrameElement(); } return null; }
From source file:com.sharksharding.core.shard.SQLExecute.java
License:Apache License
/** * ??,?/*from ww w.jav a 2 s .c o m*/ * * @author gaoxianglong * * @param proceedingJoinPoint * ? * * @param indexType * truemaster?,falseslave? * * @exception Throwable * * @return Object */ protected Object execute(ProceedingJoinPoint proceedingJoinPoint, boolean indexType) { Object obj = null; if (null != proceedingJoinPoint) { Object[] params = proceedingJoinPoint.getArgs(); if (0 > params.length) return obj; Object param = params[0]; /* * org.springframework.jdbc.core.JdbcTemplateupdate*()query*() * ?SQL */ if (param instanceof String) { String sql = param.toString(); logger.info("before sql-->" + sql); /* sharding? */ if (sharkInfo.getIsShard()) { if (sharkInfo.getShardMode()) { params = route.dbRouteByOne(sql, params, indexType); } else { params = route.dbRouteByMany(sql, params, indexType); } sql = params[0].toString(); } else { /* ?master/slave??? */ final int index = ResolveIndex.getIndex(sharkInfo.getWr_index(), indexType); SetDatasource.setIndex(index, dataSourceHolder); } logger.info("after sql-->" + sql); } try { obj = proceedingJoinPoint.proceed(params); } catch (Throwable e) { e.printStackTrace(); } } return obj; }
From source file:com.spidertracks.datanucleus.spring.ConsistencyLevelAspect.java
License:Open Source License
/** * Validates any method that has the valid annotation on it and is wired as * a spring service/*from w w w . j a va 2 s .c o m*/ * * @param jp * @throws Throwable */ @Around("@annotation(com.spidertracks.datanucleus.spring.Consistency)") public Object setConsistency(ProceedingJoinPoint pjp) throws Throwable { logger.debug("Invoking before advice for @Consistency annotation. Target object is {} on method {}", pjp.getTarget(), pjp.getSignature()); MethodSignature sig = (MethodSignature) pjp.getSignature(); Object[] args = pjp.getArgs(); Method signatureMethod = sig.getMethod(); Class<?>[] signatureTypes = signatureMethod.getParameterTypes(); // we do this because we want to get the best match from the child // classes Class<?>[] runtimeArgs = new Class<?>[signatureTypes.length]; for (int i = 0; i < signatureTypes.length; i++) { if (args[i] != null) { runtimeArgs[i] = args[i].getClass(); } else { runtimeArgs[i] = signatureTypes[i]; } } Class<?> runtimeClass = pjp.getTarget().getClass(); // check if this is annotated, if not proceed and execute it ConsistencyLevel level = consistency(runtimeClass, signatureMethod.getName(), runtimeArgs); if (level == null) { return pjp.proceed(args); } Stack<ConsistencyLevel> stack = threadStack.get(); stack.push(level); com.spidertracks.datanucleus.client.Consistency.set(level); Object result = null; try { result = pjp.proceed(args); } finally { stack.pop(); if (stack.size() > 0) { com.spidertracks.datanucleus.client.Consistency.set(stack.peek()); } else { com.spidertracks.datanucleus.client.Consistency.remove(); } } return result; }
From source file:com.spstudio.modules.permission.controller.LoginControlAspect.java
@Around("@annotation(com.spstudio.modules.permission.controller.UserSessionValidator)") public Object sessionValidationAdvice(ProceedingJoinPoint pjp) throws GenericException, Throwable { Object args[] = pjp.getArgs(); Object result = null;//from w w w . j av a 2 s. co m String targetName = pjp.getTarget().getClass().getSimpleName(); String methodName = pjp.getSignature().getName(); logger.info("----------------MethodName-----------------"); logger.info("Class:" + targetName + " Method:" + methodName); //HttpSession session = SysContent.getSession(); if (session.getAttribute("username") != null) { //Logic to check user priviledge Privilege checkingFuncationPrivilege = permissionService.findPrivilegeByFuncationName(methodName); String userName = (String) session.getAttribute("username"); LoginUser loginUser = permissionService.getLoginUserByLoginName(userName); if (loginUser != null) { Set<Privilege> permissionedPrivileges = permissionService.listPrivilegsByLoginUser(loginUser); if (permissionedPrivileges.contains(checkingFuncationPrivilege)) { result = pjp.proceed(args); } else { throw new InsufficientPriviledgeException("403", "no permission"); } } else { throw new InsufficientPriviledgeException("403", "no permission"); } return result; } else { // System.out.println(((MethodSignature)pjp.getSignature()).getReturnType().getSimpleName().toString()); String redirectStr = "login"; String returnType = ((MethodSignature) pjp.getSignature()).getReturnType().getSimpleName().toString(); if (returnType.equals("String")) { return redirectStr; } else if (returnType.equals("Map")) { Map<String, Object> resMap = new HashMap<>(); resMap.put("resCode", MessageContent.MSG_CODE_SESSIONOUTOFDATE); resMap.put("resMsg", MessageContent.MSG_SESSIONOUTOFDATE); return resMap; } else { throw new SessionTimeOutException(MessageContent.MSG_CODE_SESSIONOUTOFDATE, MessageContent.MSG_SESSIONOUTOFDATE); } } }