Search in sources :

Example 26 with InterceptorContext

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);
    }
}
Also used : HashMap(java.util.HashMap) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) SessionBeanComponent(org.jboss.as.ejb3.component.session.SessionBeanComponent) InterceptorContext(org.jboss.invocation.InterceptorContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 27 with InterceptorContext

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;
}
Also used : ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ComponentFactory(org.jboss.as.ee.component.ComponentFactory) InterceptorContext(org.jboss.invocation.InterceptorContext) ManagedReference(org.jboss.as.naming.ManagedReference)

Example 28 with InterceptorContext

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);
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) InterceptorContext(org.jboss.invocation.InterceptorContext) WSComponent(org.jboss.as.webservices.injection.WSComponent) ManagedReference(org.jboss.as.naming.ManagedReference) Method(java.lang.reflect.Method) WSComponent(org.jboss.as.webservices.injection.WSComponent) Component(org.jboss.as.ee.component.Component)

Example 29 with InterceptorContext

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());
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext)

Aggregations

InterceptorContext (org.jboss.invocation.InterceptorContext)29 Interceptor (org.jboss.invocation.Interceptor)8 Method (java.lang.reflect.Method)4 Component (org.jboss.as.ee.component.Component)4 ComponentView (org.jboss.as.ee.component.ComponentView)4 ManagedReference (org.jboss.as.naming.ManagedReference)4 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)3 SessionBeanComponent (org.jboss.as.ejb3.component.session.SessionBeanComponent)3 SecurityContext (org.jboss.security.SecurityContext)3 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)3 PrivilegedAction (java.security.PrivilegedAction)2 HashMap (java.util.HashMap)2 ComponentFactory (org.jboss.as.ee.component.ComponentFactory)2 StartupCountdown (org.jboss.as.ee.component.deployers.StartupCountdown)2 InvocationType (org.jboss.as.ee.component.interceptors.InvocationType)2 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)2 CancellationFlag (org.jboss.as.ejb3.component.interceptors.CancellationFlag)2 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)2 SkeletonStrategy (org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy)2 ObjectStreamException (java.io.ObjectStreamException)1