Java 类org.aspectj.lang.annotation.Before 实例源码

项目:iBase4J-Common    文件:DataSourceAspect.java   
/**
 * 配置前置通知,使用在方法aspect()上注册的切入点
 */
@Before("aspect()")
public void before(JoinPoint point) {
    Parameter parameter = (Parameter) point.getArgs()[0];
    String method = parameter.getMethod();
    try {
        L: for (String key : ChooseDataSource.METHODTYPE.keySet()) {
            for (String type : ChooseDataSource.METHODTYPE.get(key)) {
                if (method.startsWith(type)) {
                    logger.info(key);
                    HandleDataSource.putDataSource(key);
                    break L;
                }
            }
        }
    } catch (Exception e) {
        logger.error("", e);
        HandleDataSource.putDataSource("write");
    }
}
项目:pinkyLam-Blog-Server    文件:WebLogAspect.java   
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    startTime.set(System.currentTimeMillis());

    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    // 记录下请求内容
    logger.info("请求地址 : " + request.getRequestURL().toString());
    logger.info("请求方法类型 : " + request.getMethod());
    logger.info("IP : " + request.getRemoteAddr());
    logger.info("请求方法 : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    logger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));

}
项目:devops-cstack    文件:ServerAspect.java   
@Before("execution(* cn.org.once.cstack.ServerService.updateType(..))")
public void beforeServer(JoinPoint joinPoint) throws MonitorException, ServiceException {

    Server server = (Server) joinPoint.getArgs()[0];
    User user = getAuthentificatedUser();
    Message message = null;
    // String applicationName = server.getApplication().getName();
    String applicationDisplayName = server.getApplication().getDisplayName();

    switch (joinPoint.getSignature().getName().toUpperCase()) {
    case updateType:
        message = MessageUtils.writeBeforeApplicationMessage(user, applicationDisplayName, updateType);
        break;
    }
    logger.info(message.toString());
    messageService.create(message);

}
项目:devops-cstack    文件:DeploymentAspect.java   
@Before("execution(* cn.org.once.cstack.service.DeploymentService.create(..))")
public void beforeDeployment(JoinPoint joinPoint)
    throws MonitorException {
    try {
        User user = this.getAuthentificatedUser();
        Application application = (Application) joinPoint.getArgs()[0];
        Message message = null;
        switch (joinPoint.getSignature().getName().toUpperCase()) {
            case createType:
                message = MessageUtils.writeBeforeDeploymentMessage(user,
                    application, createType);
                break;
        }
        if (message != null) {
            logger.info(message.toString());
            messageService.create(message);
        }

    } catch (ServiceException e) {
        throw new MonitorException("Error afterReturningApplication", e);

    }
}
项目:SSM-REQUEST-CHECK    文件:ReqNoDrcAspect.java   
@Before("checkRepeat()")
public void before(JoinPoint joinPoint) throws Exception {
    BaseRequest request = getBaseRequest(joinPoint);
    if(request != null){
        final String reqNo = request.getReqNo();
        if(StringUtil.isEmpty(reqNo)){
            throw new RuntimeException("reqNo不能为空");
        }else{
            try {
                String tempReqNo = redisTemplate.opsForValue().get(prefixReq +reqNo);
                logger.debug("tempReqNo="+tempReqNo);

                if((StringUtil.isEmpty(tempReqNo))){
                    redisTemplate.opsForValue().set(prefixReq + reqNo, reqNo, day, TimeUnit.DAYS);
                }else{
                    throw new RuntimeException("请求号重复,reqNo="+reqNo);
                }

            } catch (RedisConnectionFailureException e){
                logger.error("redis操作异常",e);
                throw new RuntimeException("need redisService") ;
            }
        }
    }

}
项目:springboot-cloud    文件:ReqNoDrcAspect.java   
@Before("checkRepeat()")
public void before(JoinPoint joinPoint) throws Exception {
    BaseRequest request = getBaseRequest(joinPoint);
    if(request != null){
        final String reqNo = request.getReqNo();
        if(StringUtil.isEmpty(reqNo)){
            throw new SBCException(StatusEnum.REPEAT_REQUEST);
        }else{
            try {
                String tempReqNo = redisTemplate.opsForValue().get(prefixReq +reqNo);
                logger.debug("tempReqNo=" + tempReqNo);

                if((StringUtil.isEmpty(tempReqNo))){
                    redisTemplate.opsForValue().set(prefixReq + reqNo, reqNo, day, TimeUnit.DAYS);
                }else{
                    throw new SBCException("请求号重复,"+ prefixReq +"=" + reqNo);
                }

            } catch (RedisConnectionFailureException e){
                logger.error("redis操作异常",e);
                throw new SBCException("need redisService") ;
            }
        }
    }

}
项目:SpringBoot_Wechat_Sell    文件:SellerAuthorizeAspect.java   
@Before("verify()")
public void doVerify() {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    //查询cookie
    Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN);
    if (cookie == null) {
        log.warn("【登录校验】Cookie中查不到token");
        throw new SellerAuthorizeException();
    }

    //去redis里查询
    String tokenValue = redisTemplate.opsForValue().get(String.format(RedisConstant.TOKEN_PREFIX, cookie.getValue()));
    if (StringUtils.isEmpty(tokenValue)) {
        log.warn("【登录校验】Redis中查不到token");
        throw new SellerAuthorizeException();
    }
}
项目:iBase4J    文件:DataSourceAspect.java   
/**
 * 配置前置通知,使用在方法aspect()上注册的切入点
 */
@Before("aspect()")
public void before(JoinPoint point) {
    String className = point.getTarget().getClass().getName();
    String method = point.getSignature().getName();
    logger.info(className + "." + method + "(" + StringUtils.join(point.getArgs(), ",") + ")");
    try {
        L: for (String key : ChooseDataSource.METHODTYPE.keySet()) {
            for (String type : ChooseDataSource.METHODTYPE.get(key)) {
                if (method.startsWith(type)) {
                    logger.info(key);
                    HandleDataSource.putDataSource(key);
                    break L;
                }
            }
        }
    } catch (Exception e) {
        logger.error(e);
        HandleDataSource.putDataSource("write");
    }
}
项目:pre-dem-android    文件:WebViewProbe.java   
@Before("call(* android.webkit.WebView+.loadUrl(..))")
public void onWebViewLoadUrl(JoinPoint joinPoint) {
    if (!Configuration.httpMonitorEnable || !Configuration.webviewEnable) {
        return;
    }
    try {
        if (joinPoint.getTarget() instanceof WebView) {
            WebView web = (WebView) joinPoint.getTarget();
            synchronized (webviews) {
                for (int i = webviews.size() - 1; i >= 0; i--) {
                    WebView item = webviews.get(i).get();
                    if (item == null) {
                        webviews.remove(i);
                    } else if (item.equals(web)) {
                        return;
                    }
                }
                webviews.add(new WeakReference<>(web));
            }

            web.setWebViewClient(ProbeWebClient.instance);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
项目:spring-boot-aop    文件:RestrictAspect.java   
@Before("@annotation(com.nibado.example.springaop.aspects.Restrict) && execution(public * *(..))")
public void restrict(final JoinPoint joinPoint) throws Throwable {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Restrict annotation = signature.getMethod().getAnnotation(Restrict.class);

    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes())
            .getRequest();

    if (annotation.admin() && !isAdmin(request)) {
        throw new ForbiddenException("Need admin access");
    }

    if (annotation.localOnly()
            && !request.getRemoteAddr().equals("127.0.0.1")
            && !request.getRemoteAddr().equals("0:0:0:0:0:0:0:1")) {
        throw new ForbiddenException("Only possible from localhost");
    }
}
项目:spring-boot-starter-dynamic-datasource    文件:DataSourceAspect.java   
/**
 * 在进入Service方法之前执行
 * 
 * @param point
 *            切面对象
 */
@Before("dataSourcePointcut()")
public void before(JoinPoint point) {
    // 获取到当前执行的方法名
    String methodName = point.getSignature().getName();
    boolean isSlave = false;
    if (slaveMethodPattern.isEmpty()) {
        // 当前Spring容器中没有配置事务策略,采用方法名匹配方式
        isSlave = isSlave(methodName);
    } else {
        // 使用策略规则匹配
        for (String mappedName : slaveMethodPattern) {
            if (isMatch(methodName, mappedName)) {
                isSlave = true;
                break;
            }
        }
    }
    if (isSlave) {
        // 标记为读库
        DynamicDataSourceHolder.markSlave();
    } else {
        // 标记为写库
        DynamicDataSourceHolder.markMaster();
    }
}
项目:mall    文件:WebLogAspect.java   
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    startTime.set(System.currentTimeMillis());

    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    // 记录下请求内容
    LOGGER.info("**************Start API Request**************");
    LOGGER.info("URL : " + request.getRequestURI().toString());
    LOGGER.info("HTTP_METHOD : " + request.getMethod());
    LOGGER.info("IP : " + request.getRemoteAddr());
    LOGGER.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    LOGGER.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
}
项目:springDemos    文件:ControllerAspect.java   
@Before("@annotation(challengeSecurity) && args(challegeObject)")
public void checkController(final JoinPoint joinPoint, final IChallenge challegeObject,
        final ChallengeSecurity challengeSecurity) {

    final List<ChallengeModel> challenges = challegeObject.getChallenges();
    if (challenges != null) {
        LOG.info("Analizando array de challenges");
        challenges.forEach(challenge -> {
            if (ChallengeTypeEnum.OTP.equals(challenge.getType())) {
                analyzeOtp(challenge);
            } else {
                analyzeOtc(challenge);
            }
        });
    } else {
        LOG.info("El método no tiene ningún challenge");
    }

}
项目:ProxyPool    文件:WebLogAspect.java   
@Before("log()")
public void doBeforeController(JoinPoint joinPoint) {

    // 接收到请求,记录请求内容
    log.info("WebLogAspect.doBefore()");
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    // 记录下请求内容
    log.info("URL : " + request.getRequestURL().toString());
    log.info("HTTP_METHOD : " + request.getMethod());
    log.info("IP : " + request.getRemoteAddr());
    log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    log.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
    //获取所有参数方法一:
    Enumeration<String> enu = request.getParameterNames();
    while (enu.hasMoreElements()) {
        String paraName = (String) enu.nextElement();
        System.out.println(paraName + ": " + request.getParameter(paraName));
    }
}
项目:tac-ms-starter-parent    文件:WebLogAop.java   
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws ParamException, JsonProcessingException {
    startTime.set(System.currentTimeMillis());

    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    // 记录下请求内容
    logger.info("URL : " + request.getRequestURL().toString());
    logger.info("HTTP_METHOD : " + request.getMethod());
    logger.info("IP : " + request.getRemoteAddr());
    logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    if (joinPoint.getArgs().length == 2 ) {
        logger.info("ARGS : " + JsonUtil.toJson(joinPoint.getArgs()[0]));
    }

}
项目:Burst    文件:WebLogAspect.java   
@Before("webLog()")
public void doBefore(JoinPoint joinPoint){
    log.info("------------日志开始:"+LocalDateTime.now()+"------------");
    startTime.set(System.currentTimeMillis());
    // 接收到请求,记录请求内容
    log.info("WebLogAspect.doBefore()");
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    log.info("URL : " + request.getRequestURL().toString());
    log.info("HTTP_METHOD : " + request.getMethod());
    log.info("IP : " + request.getRemoteAddr());
    log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    log.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
    //获取所有参数方法一:
    Enumeration enu=request.getParameterNames();
    while(enu.hasMoreElements()){
        String paraName=(String)enu.nextElement();
        log.info("PARAM :"+"("+paraName+" : "+request.getParameter(paraName)+")");
    }
}
项目:OperatieBRP    文件:AspectForMDC.java   
/**
 * Het advies uit te voeren op de pointcut.
 * @param message parameter van de methode
 * @throws JMSException als iets in de pointcut fout gaat
 */
@Before("nl.bzk.algemeenbrp.util.common.logging.AspectForMDC.jmsBerichtLezer() && args(message)")
public void voegMDCInformatieToe(Message message) throws JMSException {
    if (message.getStringProperty(MDC.JMS_VERWERKING_CODE) != null) {
        org.slf4j.MDC.put(VERWERKING_CODE, message.getStringProperty(MDC.JMS_VERWERKING_CODE));
    } else {
        org.slf4j.MDC.put(VERWERKING_CODE, UUID.randomUUID().toString());
    }
    org.slf4j.MDC.put(JMS_MESSAGE_ID, message.getJMSMessageID());
    if (message.getStringProperty(BERICHT_REFERENTIE) != null) {
        org.slf4j.MDC.put(SYNC_BERICHT_REFERENTIE, message.getStringProperty(BERICHT_REFERENTIE));
    } else {
        org.slf4j.MDC.remove(SYNC_BERICHT_REFERENTIE);
    }
    if (message.getStringProperty(CORRELATIE_REFERENTIE) != null) {
        org.slf4j.MDC.put(SYNC_CORRELATIE_REFERENTIE, message.getStringProperty(CORRELATIE_REFERENTIE));
    } else {
        org.slf4j.MDC.remove(SYNC_CORRELATIE_REFERENTIE);
    }
}
项目:JAVA-    文件:DataSourceAspect.java   
/**
 * 配置前置通知,使用在方法aspect()上注册的切入点
 */
@Before("aspect()")
public void before(JoinPoint point) {
    String className = point.getTarget().getClass().getName();
    String method = point.getSignature().getName();
    logger.info(className + "." + method + "(" + StringUtils.join(point.getArgs(), ",") + ")");
    try {
        L: for (String key : ChooseDataSource.METHODTYPE.keySet()) {
            for (String type : ChooseDataSource.METHODTYPE.get(key)) {
                if (method.startsWith(type)) {
                    logger.info(key);
                    HandleDataSource.putDataSource(key);
                    break L;
                }
            }
        }
    } catch (Exception e) {
        logger.error(e);
        HandleDataSource.putDataSource("write");
    }
}
项目:springboot-start    文件:WebLogAspect.java   
@Before(value = "webLog()")
    public void doBefore(JoinPoint joinPoint) throws Throwable {
        startTime.set(System.currentTimeMillis());
        // 接收到请求,记录请求内容
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        // 记录下请求内容
//        log.info("URL : " + request.getRequestURL().toString());
//        log.info("HTTP_METHOD : " + request.getMethod());
//        log.info("IP : " + request.getRemoteAddr());
//        log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//        log.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
//        BasicDBObject logInfo = ;
        l.set(getBasicDBObject(request, joinPoint));
//        log.info(logInfo);
    }
项目:sso    文件:ThirdPartyLoginAspect.java   
@Before("loginHandle()")
public void doBefore(JoinPoint pjp) throws Throwable {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    Principal principal = request.getUserPrincipal();
    if (principal != null && principal instanceof Pac4jPrincipal) {
        logger.debug("准备判断用户绑定状态");
        Pac4jPrincipal pac4jPrincipal = (Pac4jPrincipal) principal;

        //获取认证客户端
        String clientName = (String) pac4jPrincipal.getProfile().getAttribute("clientName");
        //获取客户端策略
        ClientStrategy clientStrategy = clientStrategyFactory.getClientStrategy().get(clientName);
        if (clientStrategy != null) {

            //判断该客户端是否已经有绑定用户
            if (!clientStrategy.isBind(pac4jPrincipal)) {
                logger.debug("用户[" + pac4jPrincipal.getProfile().getId() + "]通过" + clientStrategy.name() + "登录尚未绑定");
                //未绑定给予处理
                clientStrategy.handle(pjp, pac4jPrincipal);
            }
        }
    }
}
项目:Spring-5.0-Cookbook    文件:LoginProxyAspect.java   
@Before("classPointcut() && loginPointcut() && args(model,req) && @annotation(mapping)")
public String browserCheck(JoinPoint joinPoint, Model model, HttpServletRequest req, RequestMapping mapping) throws ServletException, IOException{

   // IP Address checking -- TO DO LIST
      // String ipAddress = req.getRemoteAddr();
   logger.info("executing " + joinPoint.getSignature().getName());
   logger.warn("MVC application trying to check browser type...");
      String loginRequestMethod = mapping.method()[0].name();
      String username = req.getParameter("username");
   String password = req.getParameter("password");

   req.setAttribute("username", username);
   req.setAttribute("password", password);

   logger.info("executing " + joinPoint.getSignature().getName() + " which is a " + loginRequestMethod + " request");
      if(loginRequestMethod.equalsIgnoreCase("GET")){
        Enumeration<String> headers = req.getHeaderNames();
           while(headers.hasMoreElements()){
            String headerName = headers.nextElement();  
            if(headerName.equalsIgnoreCase("user-agent")){
                 String browserType = req.getHeader(headerName);
                 if(browserType.contains("Chrome")){
                    req.setAttribute("browserNo", 1);   
                    logger.info("MVC application uses Chrome...");
                 }else if (browserType.contains("Firefox")){
                     req.setAttribute("browserNo", 2);
                     logger.info("MVC application uses Firefox...");
                 }else{
                     req.setAttribute("browserNo", 3);
                     logger.info("MVC application stops because browser not supported...");
                 }
               break;
            }
           }
      }
    return "login";
}
项目:lemcloud    文件:SystemLogAspect.java   
/**
 * 前置通知 用于拦截Controller层记录用户的操作的开始时间
 * @param joinPoint 切点
 * @throws InterruptedException 
 */
@Before("controllerAspect()")
public void doBefore(JoinPoint joinPoint) throws InterruptedException{
    beginTimeThreadLocal.set(System.currentTimeMillis());//线程绑定变量(该数据只有当前请求的线程可见)  
    if (logger.isDebugEnabled()){//这里日志级别为debug
        logger.debug("开始计时: {}  URI: {}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
            .format(beginTimeThreadLocal.get()), request.getRequestURI());
    }
}
项目:Spring-5.0-Cookbook    文件:LoginAuthAspect.java   
@Before("classPointcut() && loginSubmitPointcut()  && @annotation(mapping)")
public void registerParams(JoinPoint joinPoint,  RequestMapping mapping) throws ServletException, IOException{
       HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
       logger.info("executing " + joinPoint.getSignature().getName());
       String loginRequestMethod = mapping.method()[0].name();
       logger.info("executing " + joinPoint.getSignature().getName() + " which is a " + loginRequestMethod + " request");
       if(loginRequestMethod.equalsIgnoreCase("POST")){
           String username =  req.getParameter("username");
           String password =  req.getParameter("password");
          logger.warn("MVC application detected access from user: " + username + " with password: " + password );
       }
}
项目:My-Blog    文件:LogAspect.java   
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    LOGGER.info("URL : " + request.getRequestURL().toString() + ",IP : " + request.getRemoteAddr() + ",CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() + ",ARGS : " + Arrays.toString(joinPoint.getArgs()));
}
项目:springboot-smart    文件:DataSourceAop.java   
@Before("execution(* org.zt.ccty.springboot_mybatis_demo.dao..*.insert*(..)) || execution(* org.zt.ccty.springboot_mybatis_demo.dao..*.update*(..))"
        + "|| execution(* org.zt.ccty.springboot_mybatis_demo.dao..*.alter*(..))|| execution(* org.zt.ccty.springboot_mybatis_demo.dao..*.modify*(..))"
        + "|| execution(* org.zt.ccty.springboot_mybatis_demo.dao..*.delete*(..))|| execution(* org.zt.ccty.springboot_mybatis_demo.dao..*.del*(..))"
        )  
public void setWriteDataSourceType() {  
    DataSourceContextHolder.write();  
    log.info("dataSource切换到:write");  
}
项目:renren-fast    文件:SysLogAspect.java   
@Before("logPointCut()")
public void saveSysLog(JoinPoint joinPoint) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();

    SysLogEntity sysLog = new SysLogEntity();
    SysLog syslog = method.getAnnotation(SysLog.class);
    if(syslog != null){
        //注解上的描述 
        sysLog.setOperation(syslog.value());
    }

    //请求的方法名
    String className = joinPoint.getTarget().getClass().getName();
    String methodName = signature.getName();
    sysLog.setMethod(className + "." + methodName + "()");

    //请求的参数
    Object[] args = joinPoint.getArgs();
    String params = new Gson().toJson(args[0]);
    sysLog.setParams(params);

    //获取request
    HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
    //设置IP地址
    sysLog.setIp(IPUtils.getIpAddr(request));

    //用户名
    String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
    sysLog.setUsername(username);

    sysLog.setCreateDate(new Date());
    //保存系统日志
    sysLogService.save(sysLog);
}
项目:allure-java    文件:Allure1StepsAspects.java   
@Before("anyMethod() && withStepAnnotation()")
public void stepStart(final JoinPoint joinPoint) {
    final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    final String uuid = UUID.randomUUID().toString();
    final StepResult result = new StepResult()
            .withName(createTitle(joinPoint))
            .withParameters(getParameters(methodSignature, joinPoint.getArgs()));

    getLifecycle().startStep(uuid, result);
}
项目:apollo-custom    文件:NamespaceAcquireLockAspect.java   
@Before("@annotation(PreAcquireNamespaceLock) && args(itemId, operator, ..)")
public void requireLockAdvice(long itemId, String operator) {
  Item item = itemService.findOne(itemId);
  if (item == null){
    throw new BadRequestException("item not exist.");
  }
  acquireLock(item.getNamespaceId(), operator);
}
项目:fish-admin    文件:WebLogAspectConfig.java   
@Before("weblog()")
public void doBefore(JoinPoint joinpoint) throws Throwable {
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    logger.info("Started " + request.getMethod() + " "
            + request.getRequestURL().toString() + " for "
            + request.getRemoteAddr() + " at " + LocalDateTime.now());
    logger.info("Processing by " + joinpoint.getSignature().getDeclaringTypeName() + "." + joinpoint.getSignature().getName()
            + " " + request.getContentType());
    logger.info("Parameters: " + mapper.writeValueAsString(request.getParameterMap()));
}
项目:MI-S    文件:WebRequestLogAspect.java   
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    startTime.set(System.currentTimeMillis());
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    log.info("URL : " + request.getRequestURL().toString());
    log.info("HTTP_METHOD : " + request.getMethod());
    log.info("IP : " + (request.getRemoteAddr().equals("0:0:0:0:0:0:0:1") ? "127.0.0.1":request.getRemoteAddr()));
    log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    log.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
}
项目:spring-tg    文件:TgSecurityAspect.java   
@Before("execution(* io.enoy.tg.bot.TgBotMessageHandler.handleMessage(..))")
public void setupSecurityContext(JoinPoint joinPoint) {
    TgContext tgContext = (TgContext) joinPoint.getArgs()[1];

    Collection<GrantedAuthority> tgGrantedAuthorities = getGrantedAuthorities(tgContext);
    TgAuthentication tgAuthentication = new TgAuthentication(tgContext, tgGrantedAuthorities);
    SecurityContextHolder.getContext().setAuthentication(tgAuthentication);
}
项目:docs-manage    文件:WebLogAspect.java   
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) {
    startTime.set(System.currentTimeMillis());

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    logger.info("HTTP_METHOD: {}, URL: {}, IP: {}, CLASS_METHOD: {}, ARGS: {}", request.getMethod(),
            request.getRequestURL().toString(), request.getRemoteAddr(),
            joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName(),
            Arrays.toString(joinPoint.getArgs()));
}
项目:docs-manage    文件:WebLogAspect.java   
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) {
    startTime.set(System.currentTimeMillis());

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    logger.info("HTTP_METHOD: {}, URL: {}, IP: {}, CLASS_METHOD: {}, ARGS: {}", request.getMethod(),
            request.getRequestURL().toString(), request.getRemoteAddr(),
            joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName(),
            Arrays.toString(joinPoint.getArgs()));
}
项目:lams    文件:AbstractAspectJAdvisorFactory.java   
/**
 * Find and return the first AspectJ annotation on the given method
 * (there <i>should</i> only be one anyway...)
 */
@SuppressWarnings("unchecked")
protected static AspectJAnnotation<?> findAspectJAnnotationOnMethod(Method method) {
    Class<?>[] classesToLookFor = new Class<?>[] {
            Before.class, Around.class, After.class, AfterReturning.class, AfterThrowing.class, Pointcut.class};
    for (Class<?> c : classesToLookFor) {
        AspectJAnnotation<?> foundAnnotation = findAnnotation(method, (Class<Annotation>) c);
        if (foundAnnotation != null) {
            return foundAnnotation;
        }
    }
    return null;
}
项目:outcomes    文件:LogAspect.java   
@Before("weblog()")
public void doBefore(JoinPoint joinpoint) throws Throwable {
    ServletRequestAttributes attributes =
            (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    log.info("URL : " + request.getRequestURL().toString());
    log.info("TYPE : " + request.getMethod());
    log.info("REMOTE IP : " + request.getRemoteAddr());
    log.info("METHOD : " + joinpoint.getSignature().getDeclaringTypeName() + "." + joinpoint.getSignature().getName());
    log.info("PARAMETERS : " + Arrays.toString(joinpoint.getArgs()));
}
项目:spring-boot-seed    文件:ControllerLogAspectJ.java   
@Before("execution(public * com.numsg.system1.biz1.controller..*.*(..))")
public void logBefore(JoinPoint joinPoint) {
    String args = "";
    for (int i = 0; i < joinPoint.getArgs().length; i++) {
        args += joinPoint.getArgs()[i] + ",";
    }
    logger.info("The method " + joinPoint.getSignature().getName() + " begin, Args:" + args);
}
项目:Sound.je    文件:RateLimiterAspect.java   
/**
 * Binds to RateLimit annotation
 *
 * @param joinPoint the join point
 * @param limit     the limit annotation data
 * @throws RequestLimitExceeded hard error if limit is exceeded
 */
@Before("@annotation(limit)")
public void rateLimt(final JoinPoint joinPoint, final RateLimit limit) throws RequestLimitExceeded {
    final String key = getOrCreate(joinPoint, limit);

    handleHardRateLimiting(key, limit);
    handleSoftRateLimiting(key, joinPoint, limit);
}
项目:iceberg    文件:StepsAspect.java   
@Before("anyStep()")
public void before(JoinPoint joinPoint) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    String methodName = signature.getName();
    String[] methodNameWords = methodName.split("(?=[A-Z])");
    String humanReadableStep = StringUtils.capitalize(StringUtils.join(methodNameWords, " "));
    String message = humanReadableStep + " " + getParameters(signature, joinPoint.getArgs());
    LOGGER.warn(message);
}
项目:spring4.x-project    文件:LogAspect.java   
@Before("execution(* org.light4j.sping4.base.aop.DemoMethodService.*(..))") //⑥
public void before(JoinPoint joinPoint){
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();
    System.out.println("方法规则式拦截,"+method.getName());

}
项目:mark-framework    文件:RequestLimitContract.java   
@Before("@annotation(limit)")
public void requestLimit(JoinPoint joinPoint, RequestLimit limit) throws Exception {
    DefaultRequestLimitKey key = new DefaultRequestLimitKey(joinPoint);
    if (isForbidden(key, limit.period())) {
        return;
    }
    // 时间
    Long now = System.currentTimeMillis();
    Long before = now - limit.time();

    ConcurrentLinkedQueue<Long> queue = limitAccessTime.get(key);
    int count = 1;
    if (queue != null) {
        Iterator<Long> itr = queue.iterator();
        while (itr.hasNext()) {
            long accessTime = itr.next();
            if (accessTime < before) {
                itr.remove();
            } else {
                count++;
            }
        }
    } else {
        queue = new ConcurrentLinkedQueue<>();
    }
    if (count > limit.count()) {
        logger.info(key+ " 超过了次数限制" + limit.count());
        throw new RequestLimitException(key+ " 超过了次数限制" + limit.count());
    }
    queue.add(now);
    limitAccessTime.put(key, queue);
}