use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class AssociationImpl method invokeMethod.
static Object invokeMethod(final ComponentView componentView, final Method method, final InvocationRequest incomingInvocation, final InvocationRequest.Resolved content, final CancellationFlag cancellationFlag) throws Exception {
final InterceptorContext interceptorContext = new InterceptorContext();
interceptorContext.setParameters(content.getParameters());
interceptorContext.setMethod(method);
interceptorContext.putPrivateData(Component.class, componentView.getComponent());
interceptorContext.putPrivateData(ComponentView.class, componentView);
interceptorContext.putPrivateData(InvocationType.class, InvocationType.REMOTE);
interceptorContext.setBlockingCaller(false);
// setup the contextData on the (spec specified) InvocationContext
final Map<String, Object> invocationContextData = new HashMap<String, Object>();
interceptorContext.setContextData(invocationContextData);
if (content.getAttachments() != null) {
// attach the attachments which were passed from the remote client
for (final Map.Entry<String, Object> attachment : content.getAttachments().entrySet()) {
if (attachment == null) {
continue;
}
final String key = attachment.getKey();
final Object value = attachment.getValue();
// application, so add these attachments to the privateData of the InterceptorContext
if (EJBClientInvocationContext.PRIVATE_ATTACHMENTS_KEY.equals(key)) {
final Map<?, ?> privateAttachments = (Map<?, ?>) value;
for (final Map.Entry<?, ?> privateAttachment : privateAttachments.entrySet()) {
interceptorContext.putPrivateData(privateAttachment.getKey(), privateAttachment.getValue());
}
} else {
// add it to the InvocationContext which will be visible to the target bean and the
// application specific interceptors
invocationContextData.put(key, value);
}
}
}
// add the session id to the interceptor context, if it's a stateful ejb locator
final EJBLocator<?> ejbLocator = content.getEJBLocator();
if (ejbLocator.isStateful()) {
interceptorContext.putPrivateData(SessionID.class, ejbLocator.asStateful().getSessionId());
}
// add transaction
if (content.hasTransaction()) {
interceptorContext.setTransactionSupplier(content::getTransaction);
}
// add security identity
final SecurityIdentity securityIdentity = incomingInvocation.getSecurityIdentity();
final boolean isAsync = componentView.isAsynchronous(method);
final boolean oneWay = isAsync && method.getReturnType() == void.class;
final boolean isSessionBean = componentView.getComponent() instanceof SessionBeanComponent;
if (isAsync && isSessionBean) {
if (!oneWay) {
interceptorContext.putPrivateData(CancellationFlag.class, cancellationFlag);
}
final Object result = invokeWithIdentity(componentView, interceptorContext, securityIdentity);
return result == null ? null : ((Future<?>) result).get();
} else {
return invokeWithIdentity(componentView, interceptorContext, securityIdentity);
}
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class ServiceComponentDescription method createConfiguration.
@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
final ComponentConfiguration configuration = super.createConfiguration(classIndex, moduleClassLoader, moduleLoader);
// will not be used, but if instance factory is not set then components must have default constructor, which is not a
// requirement for MBeans
configuration.setInstanceFactory(new ComponentFactory() {
@Override
public ManagedReference create(final InterceptorContext context) {
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
return null;
}
};
}
});
return configuration;
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class AbstractInvocationHandler method invokeInternal.
public void invokeInternal(final Endpoint endpoint, final Invocation wsInvocation) throws Exception {
// prepare for invocation
onBeforeInvocation(wsInvocation);
// prepare invocation data
final ComponentView componentView = getComponentView();
Component component = componentView.getComponent();
// in case of @FactoryType annotation we don't need to go into EE interceptors
final boolean forceTargetBean = (wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null);
if (forceTargetBean) {
this.reference = new ManagedReference() {
public void release() {
}
public Object getInstance() {
return wsInvocation.getInvocationContext().getTargetBean();
}
};
if (component instanceof WSComponent) {
((WSComponent) component).setReference(reference);
}
}
final Method method = getComponentViewMethod(wsInvocation.getJavaMethod(), componentView.getViewMethods());
final InterceptorContext context = new InterceptorContext();
prepareForInvocation(context, wsInvocation);
context.setMethod(method);
context.setParameters(wsInvocation.getArgs());
context.putPrivateData(Component.class, component);
context.putPrivateData(ComponentView.class, componentView);
// pull in any XTS transaction
LocalTransactionContext.getCurrent().importProviderTransaction();
context.setTransaction(ContextTransactionManager.getInstance().getTransaction());
if (forceTargetBean) {
context.putPrivateData(ManagedReference.class, reference);
}
// invoke method
final Object retObj = componentView.invoke(context);
// set return value
wsInvocation.setReturnValue(retObj);
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class EJBComponent method getCurrentTransactionAttribute.
protected TransactionAttributeType getCurrentTransactionAttribute() {
final InterceptorContext invocation = CurrentInvocationContext.get();
final MethodIntf methodIntf = MethodIntfHelper.of(invocation);
return getTransactionAttributeType(methodIntf, invocation.getMethod());
}
Aggregations