下面列出了org.aspectj.lang.annotation.AfterReturning#org.aspectj.lang.JoinPoint 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Profiled(
logFailuresSeparately = true,
tag = "0.ExecutorIntegrationModule#markAsArchived"
)
public void markAsArchived(String rid) throws IntegrationModuleException {
JoinPoint var6 = Factory.makeJP(ajc$tjp_1, this, this, (Object)rid);
TimingAspect var10000 = TimingAspect.aspectOf();
Object[] var7 = new Object[]{this, rid, var6};
ProceedingJoinPoint var10001 = (new ExecutorIntegrationModuleV3Impl$AjcClosure3(var7)).linkClosureAndJoinPoint(69648);
Annotation var10002 = ajc$anno$1;
if (ajc$anno$1 == null) {
var10002 = ajc$anno$1 = ExecutorIntegrationModuleV3Impl.class.getDeclaredMethod("markAsArchived", String.class).getAnnotation(Profiled.class);
}
var10000.doPerfLogging(var10001, (Profiled)var10002);
}
protected void handleDataScope(final JoinPoint joinPoint)
{
// 获得注解
DataScope controllerDataScope = getAnnotationLog(joinPoint);
if (controllerDataScope == null)
{
return;
}
// 获取当前的用户
SysUser currentUser = ShiroUtils.getSysUser();
if (currentUser != null)
{
// 如果是超级管理员,则不过滤数据
if (!currentUser.isAdmin())
{
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
controllerDataScope.userAlias());
}
}
}
/**
* 前置通知:
* 1. 在执行目标方法之前执行,比如请求接口之前的登录验证;
* 2. 在前置通知中设置请求日志信息,如开始时间,请求参数,注解内容等
*
* @param joinPoint
* @throws Throwable
*/
@Before("webLogPointcut()")
public void doBefore(JoinPoint joinPoint) {
// 接收到请求,记录请求内容
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//获取请求头中的User-Agent
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
//打印请求的内容
startTime = System.currentTimeMillis();
log.info("请求开始时间:{}" , LocalDateTime.now());
log.info("请求Url : {}" , request.getRequestURL().toString());
log.info("请求方式 : {}" , request.getMethod());
log.info("请求ip : {}" , request.getRemoteAddr());
log.info("请求参数 : {}" , Arrays.toString(joinPoint.getArgs()));
// 系统信息
log.info("浏览器:{}", userAgent.getBrowser().toString());
log.info("浏览器版本:{}", userAgent.getBrowserVersion());
log.info("操作系统: {}", userAgent.getOperatingSystem().toString());
}
static final String getInsurability_aroundBody0(MyCareNetIntegrationModuleImpl ajc$this, String userName, String password, String pharmacyHolder, String pharmacySSIN, String pharmcayNihii, String date, String type, String careReceiverSSIN, String careReceiverMutuality, String careReceiverRegNrWithMut, String packageName, String reference, String userReference, JoinPoint var14) {
ApplicationConfig.getInstance().assertValidSession();
try {
MyCareNetRequest myCareNet = new MyCareNetRequest();
LOG.debug("******************** Call MyCarenet for insurability ******************** ");
GetInsurabilityForPharmacistResponse ins = InsurabilityConsultationServiceImpl.getInstance().getInsurabilityForPharmacist(myCareNet.createRequest(userName, password, pharmacyHolder, pharmacySSIN, pharmcayNihii, date, type, careReceiverSSIN, careReceiverMutuality, careReceiverRegNrWithMut, packageName, reference, userReference));
String insXml = null;
if (ins != null) {
insXml = JaxContextCentralizer.getInstance().toXml(GetInsurabilityForPharmacistResponse.class, ins);
LOG.debug("******************** Call MyCarenet for insurability response: " + insXml + " ******************** ");
}
return insXml;
} catch (Throwable var20) {
Exceptionutils.errorHandler(var20);
return null;
}
}
public void setArgumentNamesFromStringArray(String... args) {
this.argumentNames = new String[args.length];
for (int i = 0; i < args.length; i++) {
this.argumentNames[i] = StringUtils.trimWhitespace(args[i]);
if (!isVariableName(this.argumentNames[i])) {
throw new IllegalArgumentException(
"'argumentNames' property of AbstractAspectJAdvice contains an argument name '" +
this.argumentNames[i] + "' that is not a valid Java identifier");
}
}
if (this.argumentNames != null) {
if (this.aspectJAdviceMethod.getParameterCount() == this.argumentNames.length + 1) {
// May need to add implicit join point arg name...
Class<?> firstArgType = this.aspectJAdviceMethod.getParameterTypes()[0];
if (firstArgType == JoinPoint.class ||
firstArgType == ProceedingJoinPoint.class ||
firstArgType == JoinPoint.StaticPart.class) {
String[] oldNames = this.argumentNames;
this.argumentNames = new String[oldNames.length + 1];
this.argumentNames[0] = "THIS_JOIN_POINT";
System.arraycopy(oldNames, 0, this.argumentNames, 1, oldNames.length);
}
}
}
}
@Profiled(
logFailuresSeparately = true,
tag = "0.ExecutorIntegrationModule#listNotifications"
)
public List<ListNotificationsItem> listNotifications(boolean readFlag) throws IntegrationModuleException {
JoinPoint var7 = Factory.makeJP(ajc$tjp_5, this, this, (Object)Conversions.booleanObject(readFlag));
TimingAspect var10000 = TimingAspect.aspectOf();
Object[] var8 = new Object[]{this, Conversions.booleanObject(readFlag), var7};
ProceedingJoinPoint var10001 = (new ExecutorIntegrationModuleV3Impl$AjcClosure11(var8)).linkClosureAndJoinPoint(69648);
Annotation var10002 = ajc$anno$5;
if (ajc$anno$5 == null) {
var10002 = ajc$anno$5 = ExecutorIntegrationModuleV3Impl.class.getDeclaredMethod("listNotifications", Boolean.TYPE).getAnnotation(Profiled.class);
}
return (List)var10000.doPerfLogging(var10001, (Profiled)var10002);
}
@Profiled(
logFailuresSeparately = true,
tag = "IntegrationModule#XMLNotificationValidation"
)
public void assertValidNotification(byte[] xmlDocument) throws IntegrationModuleException {
JoinPoint var3 = Factory.makeJP(ajc$tjp_0, this, this, (Object)xmlDocument);
TimingAspect var10000 = TimingAspect.aspectOf();
Object[] var4 = new Object[]{this, xmlDocument, var3};
ProceedingJoinPoint var10001 = (new KmehrHelper$AjcClosure1(var4)).linkClosureAndJoinPoint(69648);
Annotation var10002 = ajc$anno$0;
if (ajc$anno$0 == null) {
var10002 = ajc$anno$0 = KmehrHelper.class.getDeclaredMethod("assertValidNotification", byte[].class).getAnnotation(Profiled.class);
}
var10000.doPerfLogging(var10001, (Profiled)var10002);
}
/**
* 定义前置通知(需要在切点方法的前面需要执行的动作处理)
*/
@Before("apiRequestLog()")
public void doBefore(JoinPoint joinPoint) {
logger.info("前置通知日志输出");
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
// 获取url
logger.info("url={}", request.getRequestURL());
//获取请求method
logger.info("method={}", request.getMethod());
//获取请求ip
logger.info("ip={}", request.getRemoteAddr());
// 获取处理请求的类方法
logger.info("class_method={}", joinPoint.getSignature().getDeclaringType() + "." + joinPoint.getSignature().getName());
// 获取请求方法传入的参数
logger.info("args={}", joinPoint.getArgs());
}
/**
* Do after.
*
* @param joinPoint the join point
*/
@AfterReturning(pointcut = "validateAnnotation()")
public void doAfter(final JoinPoint joinPoint) {
String methodName = joinPoint.getSignature().getName();
Object target = joinPoint.getTarget();
//得到拦截的方法
Method method = getMethodByClassAndName(target.getClass(), methodName);
Object[] objects = joinPoint.getArgs();
//方法的参数
assert method != null;
ValidateAnnotation annotation = (ValidateAnnotation) getAnnotationByMethod(method, ValidateAnnotation.class);
if (annotation != null) {
BindingResult bindingResult = null;
for (Object arg : objects) {
if (arg instanceof BindingResult) {
bindingResult = (BindingResult) arg;
}
}
if (bindingResult != null && bindingResult.hasErrors()) {
String errorInfo = bindingResult.getFieldError().getDefaultMessage();
throw new IllegalArgumentException(errorInfo);
}
}
}
@Profiled(
logFailuresSeparately = true,
tag = "TipConfigModuleImpl#getLatestProductFilter",
logger = "org.perf4j.TimingLogger_Executor"
)
public void getLatestProductFilter() throws IntegrationModuleException {
JoinPoint var16 = Factory.makeJP(ajc$tjp_0, this, this);
TimingAspect var10000 = TimingAspect.aspectOf();
Object[] var17 = new Object[]{this, var16};
ProceedingJoinPoint var10001 = (new TipConfigModuleImpl$AjcClosure1(var17)).linkClosureAndJoinPoint(69648);
Annotation var10002 = ajc$anno$0;
if (ajc$anno$0 == null) {
var10002 = ajc$anno$0 = TipConfigModuleImpl.class.getDeclaredMethod("getLatestProductFilter").getAnnotation(Profiled.class);
}
var10000.doPerfLogging(var10001, (Profiled)var10002);
}
public String createTitle(final JoinPoint joinPoint) {
final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
final Step step = methodSignature.getMethod().getAnnotation(Step.class);
return step.value().isEmpty()
? getName(methodSignature.getName(), joinPoint.getArgs())
: getTitle(step.value(), methodSignature.getName(), joinPoint.getThis(), joinPoint.getArgs());
}
@After(EXECUTION_WINDOW_SET_POSITION)
public void afterWindowIsMoved(JoinPoint joinPoint) throws Throwable {
try {
listener.afterWindowIsMoved(driver, castTarget(joinPoint),
castArgument(joinPoint, 0));
} catch (Throwable t) {
throw getRootCause(t);
}
}
@AfterReturning(pointcut = "restEndPoints()", returning = "result")
public void logAfterReturn(JoinPoint joinPoint, Object result) {
log.info("Exiting Method: " + joinPoint.getSignature().getName());
if (log.isDebugEnabled()) {
try {
log.debug("Response: " + mapper.writeValueAsString(result));
}
catch (JsonProcessingException e) {
log.warn("An error occurred while attempting to write value as JSON: " + result.toString());
log.warn(e.getMessage(), e);
}
}
}
static final List listOpenPrescription_aroundBody10(PrescriberIntegrationModuleImpl ajc$this, String patientId, JoinPoint var2) {
ApplicationConfig.getInstance().assertValidSession();
try {
MarshallerHelper helper = new MarshallerHelper(GetListOpenPrescriptionResult.class, GetListOpenPrescriptionParam.class);
List etkRecipes = ajc$this.getEtkHelper().getRecipe_ETK();
GetListOpenPrescriptionParam param = new GetListOpenPrescriptionParam();
param.setSymmKey(ajc$this.getSymmKey().getEncoded());
param.setPrescriberId(StandaloneRequestorProvider.getRequestorIdInformation());
param.setPatientId(patientId);
ListOpenPrescriptionsRequest request = new ListOpenPrescriptionsRequest();
request.setSecuredListOpenPrescriptionsRequest(ajc$this.createSecuredContentType(ajc$this.sealRequest((EncryptionToken)etkRecipes.get(0), helper.toXMLByteArray(param))));
ListOpenPrescriptionsResponse response = null;
try {
response = RecipePrescriberServiceImpl.getInstance().listOpenPrescriptions(request);
} catch (ClientTransportException var14) {
throw new IntegrationModuleException(I18nHelper.getLabel("error.connection.prescriber"), var14);
}
ajc$this.checkStatus(response);
GetListOpenPrescriptionResult result = (GetListOpenPrescriptionResult)helper.unsealWithSymmKey(response.getSecuredListOpenPrescriptionsResponse().getSecuredContent(), ajc$this.getSymmKey());
return (List)(result.getPrescriptions() == null ? new ArrayList() : result.getPrescriptions());
} catch (Throwable var15) {
Exceptionutils.errorHandler(var15);
return null;
}
}
/**
* Advice that logs methods throwing exceptions.
*
* @param joinPoint join point for advice
* @param e exception
*/
@AfterThrowing(pointcut = "applicationPackagePointcut() && springBeanPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
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");
}
}
@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());
}
private boolean maybeBindJoinPoint(Class<?> candidateParameterType) {
if (JoinPoint.class == candidateParameterType) {
this.joinPointArgumentIndex = 0;
return true;
}
else {
return false;
}
}
@AfterReturning(pointcut = "templateMidTableInputMetaAspect()", returning = "object")
public void templateMidTableInputMetaAspectAfter(JoinPoint joinPoint, Object object) throws InvocationTargetException, IllegalAccessException {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String localeStr = request.getHeader("Content-Language");
if (object != null) {
replaceMessage(object, localeStr);
}
}
@Before(EXECUTION_NAVIGATION_FORWARD)
public void beforeNavigateForward(JoinPoint joinPoint) throws Throwable {
try {
listener.beforeNavigateForward(driver);
} catch (Throwable t) {
throw getRootCause(t);
}
}
@Test
public void verifyResolverCredential() {
final TicketOrCredentialPrincipalResolver res =
new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
final JoinPoint jp = mock(JoinPoint.class);
final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
when(jp.getArgs()).thenReturn(new Object[] {c});
final String result = res.resolveFrom(jp, null);
assertNotNull(result);
assertEquals(result, c.toString());
}
@After(EXECUTION_WINDOW_MAXIMIZE)
public void afterMaximization(JoinPoint joinPoint) throws Throwable {
try {
listener.afterWindowIsMaximized(driver, castTarget(joinPoint));
} catch (Throwable t) {
throw getRootCause(t);
}
}
@Before(EXECUTION_CHANGE_VALUE)
public void beforeChangeValueOf(JoinPoint joinPoint) throws Throwable {
try {
listener.beforeChangeValueOf(castTarget(joinPoint), driver);
} catch (Throwable t) {
throw getRootCause(t);
}
}
@Before(EXECUTION_TAKE_SCREENSHOT_AS)
public void beforeTakeScreenShot(JoinPoint joinPoint) throws Throwable {
try {
listener.beforeGetScreenshotAs(castArgument(joinPoint, 0));
} catch (Throwable t) {
throw getRootCause(t);
}
}
@Test
public void testMonitorPerformance() throws Throwable {
HelloWorld monitorMe = context.getBean("monitorMe", HelloWorld.class);
Object START_CONTEXT = new Object();
when(openMon.start(any(JoinPoint.StaticPart.class))).thenReturn(START_CONTEXT);
monitorMe.getString();
verify(openMon).start(any(JoinPoint.StaticPart.class));
verify(openMon).stop(START_CONTEXT);
}
@Before(EXECUTION_CONTEXT)
public void beforeSwitchingToContext(JoinPoint joinPoint) throws Throwable {
try {
listener.beforeSwitchingToContext(driver, String.valueOf(joinPoint.getArgs()[0]));
} catch (Throwable t) {
throw getRootCause(t);
}
}
private OperateLog getAnnotationLog(JoinPoint joinPoint) throws Exception {
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
OperateLog classAnnotation = AnnotationUtils.findAnnotation(method.getDeclaringClass(), OperateLog.class);
if (method != null) {
return classAnnotation;
}
return null;
}
@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()));
}
@Before("com.sequenceiq.cloudbreak.cloud.logger.LogContextAspects.interceptCloudPlatformEventHandlersAcceptMethod()")
public void buildLogContextForCloudPlatformEventHandler(JoinPoint joinPoint) {
Event<CloudPlatformRequest<?>> event = (Event<CloudPlatformRequest<?>>) joinPoint.getArgs()[0];
CloudPlatformRequest<?> cloudPlatformRequest = event.getData();
CloudContext cloudContext = cloudPlatformRequest.getCloudContext();
buildMdcContext(cloudContext, event);
LOGGER.debug("A CloudPlatformEventHandler's 'accept' method has been intercepted: {}, MDC logger context is built.", joinPoint.toShortString());
}
@Override
public void processSwitchInfo(JoinPoint pjp){
final MethodSignature ms = (MethodSignature) pjp.getSignature();
SwitcherInfo info = null;
info = contextHolder.getContextAttribute(SwitcherInfo.CURRENT_SWITCHER_INFO);
if(info!=null)
return ;
try {
info = this.switcherCaches.get(ms.getMethod(), new Callable<SwitcherInfo>() {
@Override
public SwitcherInfo call() throws Exception {
SwitcherInfo switcherInfo = null;
Switcher dsw = AnnotationUtils.findAnnotationWithStopClass(ms.getDeclaringType(), ms.getMethod(), Switcher.class, Object.class);
if(dsw==null){
Transactional tnl = AnnotationUtils.findAnnotationWithStopClass(ms.getDeclaringType(), ms.getMethod(), Transactional.class, Object.class);
if(tnl!=null){
switcherInfo = new SwitcherInfo(tnl.value(), Type.TransactionManager);
}else{
switcherInfo = SwitcherInfo.DEFAULT_INFO;
}
}else{
switcherInfo = new SwitcherInfo(dsw.value());
}
return switcherInfo;
}
});
} catch (ExecutionException e) {
throw new BaseException("get switcher error: " + ms.getMethod());
}
contextHolder.setContextAttribute(SwitcherInfo.CURRENT_SWITCHER_INFO, info);
}
@Test
public void testAnnotated_Constructor() throws Exception {
AutomonAnnotatedMethod obj = new AutomonAnnotatedMethod(); // not monitored
obj = new AutomonAnnotatedMethod("monitor me!"); // monitored
verify(openMon).start(any(JoinPoint.StaticPart.class));
verify(openMon).stop(any());
}