List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] 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 {// w ww. j a va 2 s. co m currentFrame = currentFrame.getFrameElement(); } return null; }
From source file:com.sharksharding.core.shard.SQLExecute.java
License:Apache License
/** * ??,?/*from w ww.j ava2s . com*/ * * @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.shigengyu.hyperion.logging.services.WorkflowExecutionServiceLoggingAspect.java
License:Apache License
@Around("execution(* com.shigengyu.hyperion.services.WorkflowExecutionService.execute(..))") public TransitionExecutionResult aroundExecute(ProceedingJoinPoint joinPoint) { try {//from w w w. java 2 s . c o m WorkflowInstance workflowInstance = (WorkflowInstance) joinPoint.getArgs()[0]; Object transition = joinPoint.getArgs()[1]; LOGGER.debug("Before executing transition [{}] on workflow instance [{}]", transition, workflowInstance); TransitionExecutionResult result = (TransitionExecutionResult) joinPoint.proceed(); LOGGER.debug("After executing transition [{}] on workflow instance [{}]", transition, workflowInstance); return result; } catch (WorkflowExecutionException e) { LOGGER.error(ExceptionUtils.getFullStackTrace(e)); throw e; } catch (Throwable e) { LOGGER.error(ExceptionUtils.getFullStackTrace(e)); throw new RuntimeException("Unexcepted exception type caught when executing workflow transition.", e); } }
From source file:com.skplanet.tcloud.common.OmcLogAdvice.java
License:Open Source License
/** * <pre>//from w w w . ja v a2 s.c o m * ? ?? ?? ? . * </pre> * @param joinPoint AOP ? ?(logging,exception,etc...) ? ? ? * @return {@link Object} * @throws Throwable */ public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable { long startTime = System.currentTimeMillis(); // String startTimeStr = ""; // Map<String, Object> inResutlMap = new HashMap<String, Object>(); // Map<String, Object> outResutlMap = new HashMap<String, Object>(); // Map<String, Object> etcResutlMap = new HashMap<String, Object>(); // StopWatch stopWatch = new StopWatch(); // ? Signature signature = joinPoint.getSignature(); // String targetClassName = joinPoint.getTarget().getClass().getName(); // Class Name Object returnObj = null; // String hostAddress = ""; HttpServletRequest request = null; String key1 = ""; try { // Service ? - ETC SimpleDateFormat sdfYMDHMS = new SimpleDateFormat("yyyyMMddHHmmss"); startTimeStr = sdfYMDHMS.format(new Date(startTime)); etcResutlMap.put("serviceName", OmcLogAdvice.JobConstants.SERVICE_NAME); etcResutlMap.put("startTimeStr", startTimeStr); // etcResutlMap.put("hostName", hostName+" / "+hostAddress); etcResutlMap.put("hostName", localHostName); etcResutlMap.put("direction", OmcLogAdvice.JobConstants.DIRECTION_REP); // Service inResutlMap = getMakeIn(targetClassName, signature.getName(), joinPoint.getArgs(), request); stopWatch.start(joinPoint.toShortString()); // ? // Access ? IP? ? . // if (isAccessIp(inResutlMap.get("sysModule"), inResutlMap.get("clientIp"))) { if (true) { returnObj = joinPoint.proceed(); // Service ? if (stopWatch.isRunning()) { stopWatch.stop(); // ? } // Service outResutlMap = getMakeOut(returnObj, inResutlMap); outResutlMap.put("totalTimeSeconds", stopWatch.getTotalTimeMillis()); // if (inResutlMap.get("requestUrl").toString().contains("regMemberTOI") || // sjsim@20120920 inResutlMap.get("requestUrl").toString().contains("regIdpMemberTOI") || inResutlMap.get("requestUrl").toString().contains("modifyMemberIdTOI") || inResutlMap.get("requestUrl").toString().contains("ssoLoginTOI") || inResutlMap.get("signatureName").toString().contains("getSendEmail")) { // sjsim@20130207 String keyStr = inResutlMap.get("key1").toString(); if (JobConstants.SERVICE_RESULT_CODE_SUCC.equals(outResutlMap.get("resultCode"))) { if (keyStr.length() >= 5) { if (!keyStr.subSequence(0, 5).equals("memNo")) { ModelAndView mav = (ModelAndView) returnObj; String memNo = mav.getModel().get("memNo").toString(); inResutlMap.put("key1", "memNo=" + memNo); } } } else { if (keyStr.length() >= 7) { if (!keyStr.subSequence(0, 7).equals("loginId")) { ModelAndView mav = (ModelAndView) returnObj; String loginId = mav.getModel().get("loginId").toString(); inResutlMap.put("key1", "loginId=" + loginId); } } } } else if (JobConstants.SERVICE_SYS_NAME_REQUEST.equals(inResutlMap.get("signatureName"))) { if (JobConstants.SERVICE_RESULT_CODE_SUCC.equals(outResutlMap.get("resultCode"))) { if (!inResutlMap.get("key1").toString().subSequence(0, 5).equals("memNo")) { ModelAndView mav = (ModelAndView) returnObj; String memNo = mav.getModel().get("memNo").toString(); key1 = "memNo=" + memNo; inResutlMap.put("key1", key1); } } else { if (!inResutlMap.get("key1").toString().subSequence(0, 7).equals("loginId")) { ModelAndView mav = (ModelAndView) returnObj; String loginId = mav.getModel().get("loginId").toString(); key1 = "loginId=" + loginId; inResutlMap.put("key1", key1); } } // ? ? ? KEY1 ? sjsim@20130104 // ? ? , ? Key1 ? ? 2013.01.22. jhkwon } else if ("joinMdn".equals(signature.getName()) || "loginMdn".equals(signature.getName()) || "secedeMdn".equals(signature.getName())) { ModelAndView mav = (ModelAndView) returnObj; String memNo = mav.getModel().get("memNo").toString(); key1 = "memNo=" + memNo; inResutlMap.put("key1", key1); } else if ("loginMdnEx".equals(signature.getName())) { ModelAndView mav = (ModelAndView) returnObj; String memNo = mav.getModel().get("memNo").toString(); key1 = "memNo=" + memNo; inResutlMap.put("key1", key1); String userMdn = "userMdn=" + StringUtils.defaultString(mav.getModel().get("userMdn").toString()); String etc = userMdn; inResutlMap.put("etc", etc); } else if ("getSmsKey".equals(signature.getName()) || "getSmsKeyTOI".equals(signature.getName())) { ModelAndView mav = (ModelAndView) returnObj; String gubun = ","; String mdn = key1 + gubun + "mdn=" + StringUtils.defaultString(mav.getModel().get("mdn").toString()); String userMdnType = "userMdnType=" + StringUtils.defaultString(mav.getModel().get("userMdnType").toString()); //String smsAuthKey = "smsAuthKey="+StringUtils.defaultString(mav.getModel().get("smsAuthKey").toString()); //String etc=mdn+gubun+userMdnType+gubun+smsAuthKey; String etc = mdn + gubun + userMdnType + gubun; inResutlMap.put("etc", etc); } else if (inResutlMap.get("signatureName").toString().contains("startup")) { // dikey@20130220 for (Object object : joinPoint.getArgs()) { if (object instanceof HttpServletRequest) { request = (HttpServletRequest) object; } } // key1? ? ?? key2? T store? ? mdn if (request != null) { String etc = (String) inResutlMap.get("etc"); String deviceId = request.getParameter("deviceId") == null ? "" : request.getParameter("deviceId"); etc = etc + "|deviceId=" + deviceId; String userAgent = null; userAgent = request.getHeader("user-agent"); if (userAgent != null && !userAgent.trim().isEmpty()) { if (userAgent.contains("T store")) { etc = etc + new StringBuffer("|mdn=").append( request.getParameter("mdn") == null ? "" : request.getParameter("mdn")) .toString(); } } /* * Tstore -Tcloud? * - T store? T cloud? ? ?? T cloud ? UV - * startup.do ? etc? tctd-src? ?? append * 2013-11-26 jung-su.jang */ ModelAndView mav = (ModelAndView) returnObj; if (mav != null && mav.getModel() != null && mav.getModel().get("tcdSrc") != null) { String tcdSrc = mav.getModel().get("tcdSrc").toString(); etc += tcdSrc != null ? "|tcd-src=" + tcdSrc : ""; } String referer = request.getParameter("referer") == null ? "" : request.getParameter("referer"); etc = etc + "|referer=" + referer; String pushId = request.getParameter("pushId"); if (pushId != null && !"".equals(pushId)) { etc = etc + "|pushId=" + pushId; } inResutlMap.put("etc", etc); } } else if ("deviceToDevice".equals(signature.getName())) { // sjsim@20130402 String etc = (String) inResutlMap.get("etc"); ModelAndView mav = (ModelAndView) returnObj; String medTyCd = mav.getModel().get("medTyCd").toString(); etc += "|medTyCd=" + medTyCd; inResutlMap.put("etc", etc); } else if ("omcLog".equals(signature.getName()) || "omcDetailLog".equals(signature.getName())) { // dikey@20130423 ModelAndView mav = (ModelAndView) returnObj; inResutlMap.put("key2", mav.getModel().get("key2").toString()); } String requestUrl = inResutlMap.get("requestUrl") == null ? "" : inResutlMap.get("requestUrl").toString(); if (requestUrl.contains("regMemberTOI.do") || requestUrl.contains("mdnJoin.do") || requestUrl.contains("regIdpMemberTOI.do")) { ModelAndView mav = (ModelAndView) returnObj; if (mav.getModel().get("key2") != null) inResutlMap.put("key2", mav.getModel().get("key2").toString()); } /* Tstore-Tcloud ? omc ?? ?? ?? * ? requestHeader? ? ? ?? ?? ? * ? ? put 2013-11-14 jung-su.Jang */ if ("sync".equals(signature.getName())) { HttpServletRequest syncRequest = null; Object[] args = joinPoint.getArgs(); for (Object object : args) { if (object instanceof HttpServletRequest) { syncRequest = (HttpServletRequest) object; } } String tcdSrc = (String) syncRequest.getAttribute("tcdSrc"); if (tcdSrc != null && !"".equals(tcdSrc)) { String etc = (String) inResutlMap.get("etc"); etc += "|tcd-src=" + tcdSrc; inResutlMap.put("etc", etc); } } if ("startupsc".equals(signature.getName())) { ModelAndView mav = (ModelAndView) returnObj; if (mav != null && mav.getModel() != null) { inResutlMap.put("sessionID", mav.getModel().get("sessionID") != null && mav.getModel().get("sessionID").toString() != null ? mav.getModel().get("sessionID").toString() : ""); inResutlMap.put("key1", "memNo=" + mav.getModel().get("key1") != null && mav.getModel().get("key1").toString() != null ? mav.getModel().get("key1").toString() : "memNo="); inResutlMap.put("etc", mav.getModel().get("etc") != null && mav.getModel().get("etc").toString() != null ? mav.getModel().get("etc").toString() : "tcd-src=1"); } } if ("checkJoinMdn".equals(signature.getName())) { ModelAndView mav = (ModelAndView) returnObj; if (mav != null && mav.getModel() != null) { inResutlMap.put("etc", "uesrMdn=" + StringUtils.defaultString(mav.getModel().get("userMdn").toString())); } } // ? ? ?? log . /* Tstore-Tcloud ? mdnJoinNew ? ? OMC ? ?? * && !"mdnJoinNew".equals(signature.getName()) * 2013.11.18 jung-su.Jang */ // ? ? ?? log . if (!"".equals(inResutlMap.get("sysModule")) && !(inResutlMap.get("sysModule").equals(JobConstants.SERVICE_SYS_NAME_SAMPLE)) && !"mdnJoinNew".equals(signature.getName()) && !"mdnJoinNewForm".equals(signature.getName())) { //logger.info(makeLogString(inResutlMap, outResutlMap, etcResutlMap, true)); // artf120005 Token Expire ? OMC Log ? by jaeyeon.hwang 2014.03.13 if (!CodeMessage.RESPONSE_CODE_EXPIRED_TOKEN.equals(outResutlMap.get("resultCode"))) { logger.info(getFilterOmc(makeLogString(inResutlMap, outResutlMap, etcResutlMap, true))); } } } return returnObj; } catch (UserHandleableException ue) { if (!JobConstants.SERVICE_RESULT_UNAUTHORIZED_IP.equals(ue.getErrorCode())) { // IP? if (stopWatch.isRunning()) { stopWatch.stop(); // ? } outResutlMap.put("totalTimeSeconds", stopWatch.getTotalTimeMillis()); // outResutlMap.put("resultCode", ue.getErrorCode()); /* Tstore-Tcloud ? omc ?? ?? ?? * ? requestHeader? ? ? ?? ?? ? * ? ? put 2013-11-14 jung-su.Jang * */ if ("startupsc".equals(signature.getName()) || "mdnJoinNew".equals(signature.getName())) { inResutlMap.put("etc", "tcd-src=1"); if ("startupsc".equals(signature.getName())) { outResutlMap.put("resultCode", CodeMessage.RESPONSE_CODE_FAIL); logger.error(makeLogString(inResutlMap, outResutlMap, etcResutlMap, false)); } } /* artf113224 mdnLogin - TOKEN Expire ?? memNo by * Token Expired AOP ? OMC ? * jaeyeon.hwang 2014.02.18 */ if (!"startupsc".equals(signature.getName()) //artf120005 TokenExpire ? OMC Log by jaeyeon.hwang 2014.03.13 && !CodeMessage.RESPONSE_CODE_EXPIRED_TOKEN.equals(ue.getErrorCode())) { if (JobConstants.SERVICE_RESULT_CODE_FAIL.equals(ue.getErrorCode())) { logger.error(makeLogString(inResutlMap, outResutlMap, etcResutlMap, false)); } else { logger.error(makeLogString(inResutlMap, outResutlMap, etcResutlMap, true)); } } } throw new Exception(ue); } catch (Exception e) { if (stopWatch.isRunning()) { stopWatch.stop(); // ? } outResutlMap.put("totalTimeSeconds", stopWatch.getTotalTimeMillis()); // outResutlMap.put("resultCode", JobConstants.SERVICE_RESULT_CODE_FAIL); /* Tstore-Tcloud ? omc ?? ?? ?? * ? requestHeader? ? ? ?? ?? ? * ? ? put 2013-11-14 jung-su.Jang * */ if ("startupsc".equals(signature.getName()) || "mdnJoinNew".equals(signature.getName())) { inResutlMap.put("etc", "tcd-src=1"); if ("startupsc".equals(signature.getName())) { outResutlMap.put("resultCode", CodeMessage.RESPONSE_CODE_FAIL); } } else { logger.error(makeLogString(inResutlMap, outResutlMap, etcResutlMap, false)); } throw new Exception(e); } }
From source file:com.skplanet.tcloud.common.ParamAdvice.java
License:Open Source License
public Object doParamFilter(ProceedingJoinPoint joinPoint) throws Throwable { TCParam controllerTcParam = joinPoint.getTarget().getClass().getAnnotation(TCParam.class); String targetMethodName = StringUtils.nvlStr(joinPoint.getSignature().getName()); // ex) Object[] argObjs = joinPoint.getArgs(); // ? ? ?? //boolean isProceed = false; // ? String[] filterTypes = null;/* ww w. j ava 2 s . c o m*/ String[] methodNames = null; logger.debug("controllerTcParam : " + controllerTcParam + " >> targetMethodName : " + targetMethodName); try { if (controllerTcParam != null) { filterTypes = controllerTcParam.filterTypes(); methodNames = controllerTcParam.methodNames(); for (String methodName : methodNames) { if (targetMethodName.contains(methodName)) doParamProcess(filterTypes, argObjs); } } } catch (Exception e) { logger.error("? AOP !!!", e); } return joinPoint.proceed(); }
From source file:com.smallchill.core.aop.BeforeAop.java
License:Apache License
@Around("cutBefore()") public Object doBefore(ProceedingJoinPoint point) throws Throwable { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest();//from w w w .ja v a2 s. co m MethodSignature ms = (MethodSignature) point.getSignature(); Method method = ms.getMethod(); Object[] args = point.getArgs(); Class<?> clazz = point.getTarget().getClass(); Before before = method.getAnnotation(Before.class); Interceptor ic = before.value().newInstance(); Object result = ic.intercept(new Invocation(clazz, method, args, request)); if (null == result) { return point.proceed(); } else { return result; } }
From source file:com.solace.ExceptionHandlingAspect.java
License:Open Source License
/** * Will fire around methods decorated with {@link ExceptionHandled} in * following fashion:/*from w w w . j a v a 2s .c o m*/ * <p> * <ol> * <li>if {@link ExceptionHandled#logExceptionStack()} is true then a * uniform exception will be printed to {@link Logger#error(String)}</li> * <li>if {@link ExceptionHandled#handlers()} is not empty the exception * will be:</li> * <ol> * <li>evaluated to see if it is an instance of * {@link ExceptionHandledBy#handleFor()} <b>OR</b> if the exception is * derived from a class in {@link ExceptionHandledBy#handleFor()} if * {@link ExceptionHandledBy#checkForDerived()} is <b>true</b></li> * <li>if one or both of the previous conditions are met the exception will * be applied to each {@link IExceptionHandler} in * {@link ExceptionHandledBy#handlers()}</li> * <li>finally, if {@link ExceptionHandledBy#rethrowAs()} is set to a class * derived off of {@link Exception} the new exception will be created * through {@link Exception#Exception(String, Throwable)} and rethrown</li> * </ol> * </ol> * <p> * It should be noted that the rethrow could be held in * {@link ExceptionHandled} however, at this point, we don't quite know how * people will want to use the advice. Until Because of this we will set one * at the global level to be handled after all evaluations have occurred. * Now if, however, a nested {@link ExceptionHandledBy} has a rethrowAs set * the global will be missed as the rethrow will occur inside of the loop * evaluation. * * @param pjp * The ProceedingJoinPoint with metadata around the method that * will be called * @param exceptionHandled * A collection of exception types to be handled. If defined we * will proceed calls down to the ExceptionHandler. If none will * proceed then we automatically move forward. * @return the object returned by the joinpoint * @throws Throwable */ @SuppressWarnings("unchecked") @Around(value = "call(* *(..)) && @annotation(exceptionHandled)", argNames = "pjp,exceptionHandled") public Object handle(final ProceedingJoinPoint pjp, final ExceptionHandled exceptionHandled) throws Throwable { Object retVal = null; try { retVal = pjp.proceed(); } catch (Exception e) { if (exceptionHandled.logExceptionStack()) { Logger logger = null; if (pjp.getThis() == null) logger = Logger.getLogger("main"); else logger = Logger.getLogger(pjp.getThis().getClass()); logger.error("Exception caught:\nInput arguments: {}", e, buildArgsString(pjp.getArgs())); } for (ExceptionHandledBy by : exceptionHandled.handlers()) { for (Class<? extends Exception> eClass : by.handleFor()) { if (eClass.equals(e.getClass()) || (by.checkForDerived() && eClass.isAssignableFrom(e.getClass()))) { for (Class<? extends IExceptionHandler> handlerClass : by.handlers()) { IExceptionHandler handler = null; if ((handler = instances.get(handlerClass)) == null) { handler = handlerClass.newInstance(); instances.put(handlerClass, handler); } // invoke the IExceptionHandler by leveraging // the code from the JoinPoint // passed in the ProceedingJoinPoint instance handler.handle(pjp.getThis(), e.getMessage(), e, pjp.getArgs()); } if (Exception.class.isAssignableFrom(by.rethrowAs())) { Class<? extends Exception> rethrowClass = (Class<? extends Exception>) by.rethrowAs(); LOGGER.debug("Rethrowing as {}", rethrowClass.toString()); Constructor<? extends Exception> ctor = rethrowClass.getConstructor(String.class, Throwable.class); Exception rethrow = ctor.newInstance(e.getMessage(), e); throw rethrow; } } } } if (Exception.class.isAssignableFrom(exceptionHandled.rethrowAs())) { Class<? extends Exception> rethrowClass = (Class<? extends Exception>) exceptionHandled.rethrowAs(); LOGGER.debug("Global rethrow as {}", rethrowClass.toString()); Constructor<? extends Exception> ctor = rethrowClass.getConstructor(String.class, Throwable.class); Exception rethrow = ctor.newInstance(e.getMessage(), e); throw rethrow; } } return retVal; }
From source file:com.solace.logging.AspectJTimingAspect.java
License:Open Source License
/** * Will do the typical invocation of the logging instances via perf4j but * will do them instead of on annotated methods but on all public methods. * Additionally will guarantee that no instrumentation is needed for the * enter and exit in the typical application logs * //ww w . j av a2 s . co m * @param pjp * a ProceedingJoinPoint compiled in via aspectj * @return returns the object if any * @throws Throwable */ @Around(value = "execution(public * *(..))", argNames = "pjp") public Object doPerfLogging(final ProceedingJoinPoint pjp) throws Throwable { Object o = null; Object caller = pjp.getThis(); Logger logger = null; if (pjp.getThis() != null) logger = Logger.getLogger(pjp.getThis().getClass()); else logger = Logger.getLogger("main"); Profiled p = DefaultProfiled.INSTANCE; try { if (logger.isDebugEnabled()) { logger.debug(ENTER, pjp.getSignature().toShortString()); if (pjp.getArgs() != null && pjp.getArgs().length > 0) { StringBuilder sb = new StringBuilder(); for (Object param : pjp.getArgs()) sb.append(param).append("; "); logger.debug(INPUT, sb.toString()); } } o = super.doPerfLogging(pjp, p); } finally { if (logger.isDebugEnabled()) logger.debug(EXIT, pjp.getSignature().toShortString()); } return o; }
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 ww .j av a 2s.co 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 2s .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); } } }