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


Java JoinPoint類代碼示例

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


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

示例1: doBefore

import org.aspectj.lang.JoinPoint; //導入依賴的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("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());
    logger.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));

}
 
開發者ID:ju5t1nhhh,項目名稱:personspringclouddemo,代碼行數:17,代碼來源:WebLogAspect.java

示例2: renderParams

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
private static String renderParams(JoinPoint joinPoint, String[] params, String[] includeParamNames,
                                   String[] excludeParamNames, boolean inputCollectionAware) {

    Set<String> includeSet = prepareNameSet(includeParamNames);
    Set<String> excludeSet = prepareNameSet(excludeParamNames);
    List<String> requestList = new ArrayList<>();

    Map<String, Object> paramMap = joinPointToParamMap(joinPoint, params);

    if (!includeSet.isEmpty()) {
        includeSet
            .stream().filter(paramMap::containsKey)
            .forEach(key -> requestList.add(buildParam(key, paramMap.get(key), inputCollectionAware)));
    } else if (!excludeSet.isEmpty()) {
        paramMap.forEach((key, value) -> {
            if (!excludeSet.contains(key)) {
                requestList.add(buildParam(key, value, inputCollectionAware));
            }
        });
    } else {
        paramMap.forEach((key, value) -> requestList.add(buildParam(key, value, inputCollectionAware)));
    }

    return StringUtils.join(requestList, ',');
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:26,代碼來源:LogObjectPrinter.java

示例3: afterReturn

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
/**
 * @param joinPoint
 */
@AfterReturning("logAnnoAspect()")

public void afterReturn(JoinPoint joinPoint) {
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    Method method = methodSignature.getMethod();
    LogDelete logDelete = method.getAnnotation(LogDelete.class);
    if (null != logDelete) {
        BaseEntity entity = (BaseEntity) joinPoint.getArgs()[0];
        Log log = new Log();
        log.setUserId(((User) SecurityUtils.getSubject().getSession().getAttribute("curUser")).getId());
        log.setAction(Constants.LOG_ACTION_DELETE + logDelete.resource());
        log.setResource(entity.getLogResource());
        log.setResourceId(entity.getId());
        logService.insert(log);
    }
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:20,代碼來源:LogDeleteAdvice.java

示例4: createKey

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
private String createKey(JoinPoint jp) {
    Object[] args = jp.getArgs();

    if (args.length <= 0) {
        throw new IllegalArgumentException(RATE_LIMIT_PRECONDITION_FAIL);
    }

    for (Object arg : args) {
        if (arg instanceof HttpServletRequest) {
            HttpServletRequest request = (HttpServletRequest) arg;

            String ipAddress = request.getHeader("X-Forwarded-For");
            if (ipAddress == null) {
                ipAddress = request.getRemoteAddr();
            }
            return ipAddress;
        }
    }

    throw new IllegalArgumentException(RATE_LIMIT_PRECONDITION_FAIL);
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:22,代碼來源:RateLimiterAspect.java

示例5: after

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
/**
 * @param data
 * @throws ClassNotFoundException
 * @throws HttpMessageNotWritableException
 * @throws IOException
 */
@AfterReturning(pointcut = "point()", returning = "data")
public void after(JoinPoint jp, Object data) throws Exception {
    MethodInvocationProceedingJoinPoint joinPoint = (MethodInvocationProceedingJoinPoint) jp;
    Class<?> clazz = joinPoint.getSignature().getDeclaringType();
    if (AnnotationUtils.findAnnotation(clazz, FeignClient.class) == null) {
        log.debug("未找到feign 客戶端");
        return;
    }
    CustomSecurityContext securityContext = SecurityContextHystrixRequestVariable.getInstance().get();
    ErrorResult errorResult = null;
    if (securityContext != null && (errorResult = securityContext.getErrorResult()) != null) {
        if (errorResult.getHttpStatus() != HttpStatus.OK.value()) {
            Class<?> exceptionClass = Class.forName(errorResult.getException());
            Constructor<?> constructor = exceptionClass.getConstructor(new Class[]{String.class, String.class});
            throw (CustomException) constructor
                    .newInstance(new Object[]{errorResult.getMessage(), errorResult.getCode()});
        }
    }
    SecurityContextHystrixRequestVariable.getInstance().remove();
}
 
開發者ID:zhaoqilong3031,項目名稱:spring-cloud-samples,代碼行數:27,代碼來源:DefaultFeignExceptionHandlerInterceptor.java

示例6: doBefore

import org.aspectj.lang.JoinPoint; //導入依賴的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

示例7: logAfterThrowing

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
/**
 * Advice that logs methods throwing exceptions.
 */
@AfterThrowing(pointcut = "loggingPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
    if (env.acceptsProfiles("dev")) {
        log.error("Exception in {}.{}() with cause = \'{}\' and exception = \'{}\'",
            joinPoint.getSignature().getDeclaringTypeName(),
            joinPoint.getSignature().getName(),
            e.getCause() != null ? e.getCause() : "NULL", e.getMessage(),
            e
        );

    } else {
        log.error("Exception in {}.{}() with cause = {}",
            joinPoint.getSignature().getDeclaringTypeName(),
            joinPoint.getSignature().getName(),
            e.getCause() != null ? e.getCause() : "NULL"
        );
    }
}
 
開發者ID:Cinderpup,項目名稱:RoboInsta,代碼行數:22,代碼來源:LoggingAspect.java

示例8: before

import org.aspectj.lang.JoinPoint; //導入依賴的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

示例9: doBefore

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

}
 
開發者ID:ThinkingAndCoding,項目名稱:tac-ms-starter-parent,代碼行數:19,代碼來源:WebLogAop.java

示例10: verifyResolverSecurityContext

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
@Test
public void verifyResolverSecurityContext() throws Exception {
    final UserDetails ud = mock(UserDetails.class);
    when(ud.getUsername()).thenReturn("pid");
    final Authentication authn = mock(Authentication.class);
    when(authn.getPrincipal()).thenReturn(ud);
    final SecurityContext securityContext = mock(SecurityContext.class);
    when(securityContext.getAuthentication()).thenReturn(authn);
    SecurityContextHolder.setContext(securityContext);

    final TicketOrCredentialPrincipalResolver res =
            new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
    final JoinPoint jp = mock(JoinPoint.class);
    when(jp.getArgs()).thenReturn(new Object[]{ud});

    final String result = res.resolveFrom(jp, null);
    assertNotNull(result);
    assertEquals(result, ud.getUsername());
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:20,代碼來源:TicketOrCredentialPrincipalResolverTests.java

示例11: beforeServer

import org.aspectj.lang.JoinPoint; //導入依賴的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

示例12: printRestResult

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
public static RestResp printRestResult(final JoinPoint joinPoint, final Object res, final boolean printBody) {

        if (res == null) {
            return new RestResp("OK", "null", printBody);
        }

        Class<?> respClass = res.getClass();
        String status;
        Object bodyToPrint;

        if (ResponseEntity.class.isAssignableFrom(respClass)) {
            ResponseEntity<?> respEn = ResponseEntity.class.cast(res);

            status = String.valueOf(respEn.getStatusCode());

            Object body = respEn.getBody();
            bodyToPrint = LogObjectPrinter.printResult(joinPoint, body, printBody);

        } else {
            status = "OK";
            bodyToPrint = LogObjectPrinter.printResult(joinPoint, res, printBody);
        }
        return new RestResp(status, bodyToPrint, printBody);

    }
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:26,代碼來源:WebLogObjectPrinter.java

示例13: verifyResolverServiceTicket

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
@Test
public void verifyResolverServiceTicket() throws Exception {
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), c);

    final TicketGrantingTicket ticketId = getCentralAuthenticationService()
            .createTicketGrantingTicket(ctx);
    final ServiceTicket st = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(),
            CoreAuthenticationTestUtils.getService(), ctx);

    final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
    final JoinPoint jp = mock(JoinPoint.class);

    when(jp.getArgs()).thenReturn(new Object[] {st.getId()});

    final String result = res.resolveFrom(jp, null);
    assertNotNull(result);
    assertEquals(result, c.getId());
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:20,代碼來源:TicketOrCredentialPrincipalResolverTests.java

示例14: before

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
@Before("apiPointcut()")
public void before(JoinPoint joinPoint) {
    Object obj[] = joinPoint.getArgs();
    if (obj.length > 0) {
        APIRequest request = (APIRequest) obj[0];
        Set set = request.getParams().entrySet();
        Map.Entry[] entries = (Map.Entry[]) set.toArray(new Map.Entry[set.size()]);
        for (Map.Entry entry : entries) {
            logger.info("[Params] " + entry.getKey() + ":" + entry.getValue());
        }
    } else {
        logger.info("[Params] null");
    }
}
 
開發者ID:bingozb,項目名稱:DKJavaWebApiDemo,代碼行數:15,代碼來源:APILogger.java

示例15: anyMethod

import org.aspectj.lang.JoinPoint; //導入依賴的package包/類
@AfterReturning(pointcut = "empController() && anyMethod() && args(empId, request)", returning = "result", argNames = "joinPoint,result,empId,request")
public void handleAfterMethodWithEmpIdRequestParams(JoinPoint joinPoint, Object result, Integer empId, HttpServletRequest request) {
    int action = Integer.parseInt((((MethodSignature)joinPoint.getSignature())
            .getMethod()).getAnnotation(RequestMapping.class).name());
    AuditInfo auditRecord = new AuditInfo(null, empId, request.getRemoteAddr(), "Id: "+empId, action);
    auditService.createRecord(auditRecord);
}
 
開發者ID:Witerium,項目名稱:stuffEngine,代碼行數:8,代碼來源:AuditHandler.java


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