當前位置: 首頁>>代碼示例>>Java>>正文


Java Before類代碼示例

本文整理匯總了Java中org.aspectj.lang.annotation.Before的典型用法代碼示例。如果您正苦於以下問題:Java Before類的具體用法?Java Before怎麽用?Java Before使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Before類屬於org.aspectj.lang.annotation包,在下文中一共展示了Before類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doBefore

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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);
            }
        }
    }
}
 
開發者ID:kawhii,項目名稱:sso,代碼行數:24,代碼來源:ThirdPartyLoginAspect.java

示例2: before

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
/**
 * 配置前置通知,使用在方法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");
	}
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:23,代碼來源:DataSourceAspect.java

示例3: doBefore

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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()));

}
 
開發者ID:handexing,項目名稱:pinkyLam-Blog-Server,代碼行數:17,代碼來源:WebLogAspect.java

示例4: beforeServer

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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);

}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:19,代碼來源:ServerAspect.java

示例5: beforeDeployment

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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);

    }
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:24,代碼來源:DeploymentAspect.java

示例6: before

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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") ;
			}
		}
	}
		
}
 
開發者ID:crossoverJie,項目名稱:SSM-REQUEST-CHECK,代碼行數:27,代碼來源:ReqNoDrcAspect.java

示例7: before

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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") ;
            }
        }
    }

}
 
開發者ID:crossoverJie,項目名稱:springboot-cloud,代碼行數:27,代碼來源:ReqNoDrcAspect.java

示例8: doVerify

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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();
    }
}
 
開發者ID:ldlood,項目名稱:SpringBoot_Wechat_Sell,代碼行數:20,代碼來源:SellerAuthorizeAspect.java

示例9: before

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
/**
 * 配置前置通知,使用在方法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");
	}
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:24,代碼來源:DataSourceAspect.java

示例10: onWebViewLoadUrl

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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();
    }
}
 
開發者ID:pre-dem,項目名稱:pre-dem-android,代碼行數:27,代碼來源:WebViewProbe.java

示例11: execution

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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");
    }
}
 
開發者ID:nielsutrecht,項目名稱:spring-boot-aop,代碼行數:20,代碼來源:RestrictAspect.java

示例12: before

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
/**
 * 在進入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();
    }
}
 
開發者ID:6089555,項目名稱:spring-boot-starter-dynamic-datasource,代碼行數:32,代碼來源:DataSourceAspect.java

示例13: doBefore

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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()));
}
 
開發者ID:JesseHu1520,項目名稱:mall,代碼行數:17,代碼來源:WebLogAspect.java

示例14: args

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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");
    }

}
 
開發者ID:srhojo,項目名稱:springDemos,代碼行數:20,代碼來源:ControllerAspect.java

示例15: doBeforeController

import org.aspectj.lang.annotation.Before; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:fengzhizi715,項目名稱:ProxyPool,代碼行數:22,代碼來源:WebLogAspect.java


注:本文中的org.aspectj.lang.annotation.Before類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。