use of javax.interceptor.AroundInvoke in project iobserve-analysis by research-iobserve.
the class TraceObjectInterceptor method interceptMethodCall.
/**
* Around advice configuration.
*
* @param context
* the invocation context of a bean call.
* @return the return value of the next method in the chain
* @throws Throwable
*/
@AroundInvoke
public Object interceptMethodCall(final InvocationContext context) throws Throwable {
// (IllegalThrowsCheck)
if (this.monitoringCtrl.isMonitoringEnabled()) {
final String signature = context.getMethod().toString();
if (this.monitoringCtrl.isProbeActivated(signature)) {
// common fields
TraceMetadata trace = TraceObjectInterceptor.TRACEREGISTRY.getTrace();
final boolean newTrace = trace == null;
if (newTrace) {
trace = TraceObjectInterceptor.TRACEREGISTRY.registerTrace();
this.monitoringCtrl.newMonitoringRecord(trace);
}
final long traceId = trace.getTraceId();
final String clazz = context.getTarget().getClass().getCanonicalName();
final int objectId = System.identityHashCode(context);
// measure before execution
this.monitoringCtrl.newMonitoringRecord(new BeforeOperationObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, objectId));
// execution of the called method
try {
final Object retval = context.proceed();
// measure after successful execution
this.monitoringCtrl.newMonitoringRecord(new AfterOperationObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, objectId));
return retval;
} catch (final Throwable th) {
// NOPMD NOCS (catch throw might
// ok here)
// measure after failed execution
this.monitoringCtrl.newMonitoringRecord(new AfterOperationFailedObjectEvent(this.timeSource.getTime(), traceId, trace.getNextOrderId(), signature, clazz, th.toString(), objectId));
throw th;
} finally {
if (newTrace) {
// close the trace
TraceObjectInterceptor.TRACEREGISTRY.unregisterTrace();
}
}
} else {
return context.proceed();
}
} else {
return context.proceed();
}
}
use of javax.interceptor.AroundInvoke in project UVMS-ActivityModule-APP by UnionVMS.
the class UserRoleInterceptor method interceptRequest.
@AroundInvoke
public Object interceptRequest(final InvocationContext ic) throws Exception {
IUserRoleInterceptor iUserRoleInterceptor = ic.getMethod().getAnnotation(IUserRoleInterceptor.class);
// Get User role defined in the Rest service
ActivityFeaturesEnum[] features = iUserRoleInterceptor.requiredUserRole();
// Request parameters
Object[] parameters = ic.getParameters();
HttpServletRequest req = getHttpServletRequest(parameters);
boolean isUserAuthorized = false;
for (ActivityFeaturesEnum activityFeaturesEnum : features) {
isUserAuthorized = req.isUserInRole(activityFeaturesEnum.value());
}
if (!isUserAuthorized) {
throw new ServiceException(ErrorCodes.NOT_AUTHORIZED);
}
return ic.proceed();
}
Aggregations