use of javax.interceptor.InvocationContext in project wildfly by wildfly.
the class PassivationAnnotationParsingProcessor method processPassivation.
private void processPassivation(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
if (!(target instanceof MethodInfo)) {
throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType);
}
final MethodInfo methodInfo = MethodInfo.class.cast(target);
final ClassInfo classInfo = methodInfo.declaringClass();
final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
final Type[] args = methodInfo.args();
if (args.length > 1) {
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name()));
return;
} else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) {
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)"));
return;
}
final MethodIdentifier methodIdentifier;
if (args.length == 0) {
methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name());
} else {
methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name(), InvocationContext.class);
}
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
if (annotationType == POST_ACTIVATE) {
builder.setPostActivate(methodIdentifier);
} else {
builder.setPrePassivate(methodIdentifier);
}
classDescription.setInterceptorClassDescription(builder.build());
}
use of javax.interceptor.InvocationContext in project indy by Commonjava.
the class MetricsInterceptor method operation.
@AroundInvoke
public Object operation(InvocationContext context) throws Exception {
if (!config.isMetricsEnabled())
return context.proceed();
IndyMetrics metrics = context.getMethod().getAnnotation(IndyMetrics.class);
if (metrics == null) {
return context.proceed();
}
logger.debug("Gathering metrics for: {}", context.getContextData());
Measure measures = metrics.measure();
List<Timer.Context> timers = Stream.of(measures.timers()).map(named -> util.getTimer(named).time()).collect(Collectors.toList());
try {
return context.proceed();
} catch (Exception e) {
Measure me = metrics.exceptions();
Stream.of(me.meters()).forEach((named) -> {
Meter requests = util.getMeter(named);
requests.mark();
});
throw e;
} finally {
if (timers != null) {
timers.forEach(Timer.Context::stop);
}
Stream.of(measures.meters()).forEach((named) -> {
Meter requests = util.getMeter(named);
requests.mark();
});
}
}
use of javax.interceptor.InvocationContext in project tomee by apache.
the class InterceptorStack method invoke.
public Object invoke(final javax.xml.rpc.handler.MessageContext messageContext, final Object... parameters) throws Exception {
try {
final InvocationContext invocationContext = new JaxRpcInvocationContext(operation, interceptors, beanInstance, targetMethod, messageContext, parameters);
ThreadContext.getThreadContext().set(InvocationContext.class, invocationContext);
return invocationContext.proceed();
} finally {
ThreadContext.getThreadContext().remove(InvocationContext.class);
}
}
use of javax.interceptor.InvocationContext in project tomee by apache.
the class InterceptorBindingBuilder method toMethods.
/**
* Used for getting the java.lang.reflect.Method objects for the following callbacks:
* <p/>
* - @PostConstruct <any-scope> void <method-name>(InvocationContext)
* - @PreDestroy <any-scope> void <method-name>(InvocationContext)
* - @PrePassivate <any-scope> void <method-name>(InvocationContext)
* - @PostActivate <any-scope> void <method-name>(InvocationContext)
* - @AroundInvoke <any-scope> Object <method-name>(InvocationContext) throws Exception
* - @AroundTimeout <any-scope> Object <method-name>(InvocationContext) throws Exception
*
* @param clazz
* @param callbackInfos the raw CallbackInfo objects
* @param callbacks the collection where the created methods will be placed
*/
private void toMethods(final Class<?> clazz, final List<CallbackInfo> callbackInfos, final Set<Method> callbacks) {
final List<Method> methods = new ArrayList<Method>();
for (final CallbackInfo callbackInfo : callbackInfos) {
try {
Method method = getMethod(clazz, callbackInfo.method, InvocationContext.class);
if (callbackInfo.className == null && method.getDeclaringClass().equals(clazz) && !methods.contains(method)) {
methods.add(method);
}
if (method.getDeclaringClass().getName().equals(callbackInfo.className) && !methods.contains(method)) {
methods.add(method);
} else {
// check for a private method on the declared class
// find declared class
Class<?> c = clazz;
while (c != null && !c.getName().equals(callbackInfo.className)) {
c = c.getSuperclass();
}
// get callback method
if (c != null) {
try {
method = getMethod(c, callbackInfo.method, InvocationContext.class);
// make sure it is private
if (Modifier.isPrivate(method.getModifiers()) && !methods.contains(method)) {
SetAccessible.on(method);
methods.add(method);
}
} catch (final NoSuchMethodException e) {
// no-op
}
}
}
} catch (final NoSuchMethodException e) {
logger.warning("Interceptor method not found (skipping): public Object " + callbackInfo.method + "(InvocationContext); in class " + clazz.getName());
}
}
Collections.sort(methods, new MethodCallbackComparator());
callbacks.addAll(methods);
}
use of javax.interceptor.InvocationContext in project tomee by apache.
the class EjbMethodInvoker method performInvocation.
@Override
protected Object performInvocation(final Exchange exchange, final Object serviceObject, final Method m, final Object[] paramArray) throws Exception {
InvocationContext invContext = exchange.get(InvocationContext.class);
invContext.setParameters(paramArray);
Object res = invContext.proceed();
EjbMessageContext ctx = (EjbMessageContext) invContext.getContextData();
Map<String, Object> handlerProperties = (Map<String, Object>) exchange.get(HANDLER_PROPERTIES);
addHandlerProperties(ctx, handlerProperties);
updateWebServiceContext(exchange, ctx);
return res;
}
Aggregations