当前位置: 首页>>代码示例>>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;未经允许,请勿转载。