Search in sources :

Example 1 with InterceptorBindings

use of org.jboss.weld.ejb.spi.InterceptorBindings in project wildfly by wildfly.

the class WeldComponentIntegrationProcessor method addWeldInterceptorBindingService.

private static ServiceName addWeldInterceptorBindingService(final ServiceTarget target, final ComponentConfiguration configuration, final Class<?> componentClass, final String beanName, final ServiceName weldServiceName, final ServiceName weldStartService, final String beanDeploymentArchiveId, final ComponentInterceptorSupport componentInterceptorSupport) {
    ServiceName bindingServiceName = configuration.getComponentDescription().getServiceName().append(WeldInterceptorBindingsService.SERVICE_NAME);
    final ServiceBuilder<?> sb = target.addService(bindingServiceName);
    final Consumer<InterceptorBindings> interceptorBindingsConsumer = sb.provides(bindingServiceName);
    final Supplier<WeldBootstrapService> weldContainerSupplier = sb.requires(weldServiceName);
    sb.requires(weldStartService);
    sb.setInstance(new WeldInterceptorBindingsService(interceptorBindingsConsumer, weldContainerSupplier, beanDeploymentArchiveId, beanName, componentClass, componentInterceptorSupport));
    sb.install();
    return bindingServiceName;
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) WeldInterceptorBindingsService(org.jboss.as.weld.ejb.WeldInterceptorBindingsService) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService)

Example 2 with InterceptorBindings

use of org.jboss.weld.ejb.spi.InterceptorBindings in project wildfly by wildfly.

the class Jsr299BindingsCreateInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    BeanManagerImpl beanManager = this.beanManager;
    if (beanManager == null) {
        // cache the BM lookup, as it is quite slow
        beanManager = this.beanManager = weldContainerSupplier.get().getBeanManager(beanArchiveId);
    }
    // this is not always called with the deployments TCCL set
    // which causes weld to blow up
    SessionBean<Object> bean = null;
    if (ejbName != null) {
        EjbDescriptor<Object> descriptor = beanManager.getEjbDescriptor(this.ejbName);
        if (descriptor != null) {
            bean = beanManager.getBean(descriptor);
        }
    }
    InterceptorBindings interceptorBindings = interceptorBindingsSupplier.get();
    final ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    InterceptorInstances existing = interceptorSupport.getInterceptorInstances(componentInstance);
    if (existing == null) {
        CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean);
        HashMap<String, SerializableContextualInstance<Interceptor<Object>, Object>> interceptorInstances = new HashMap<String, SerializableContextualInstance<Interceptor<Object>, Object>>();
        if (interceptorBindings != null) {
            for (Interceptor<?> interceptor : interceptorBindings.getAllInterceptors()) {
                addInterceptorInstance((Interceptor<Object>) interceptor, beanManager, interceptorInstances, creationalContext);
            }
        }
        interceptorSupport.setInterceptorInstances(componentInstance, new WeldInterceptorInstances(creationalContext, interceptorInstances));
    }
    return interceptorContext.proceed();
}
Also used : HashMap(java.util.HashMap) InterceptorInstances(org.jboss.as.weld.spi.InterceptorInstances) SerializableContextualInstance(org.jboss.weld.serialization.spi.helpers.SerializableContextualInstance) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) Interceptor(javax.enterprise.inject.spi.Interceptor)

Example 3 with InterceptorBindings

use of org.jboss.weld.ejb.spi.InterceptorBindings in project wildfly by wildfly.

the class Jsr299BindingsInterceptor method processInvocation.

@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
    final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
    final InterceptorInstances interceptorInstances = interceptorSupport.getInterceptorInstances(componentInstance);
    final InterceptorBindings interceptorBindings = interceptorBindingsSupplier.get();
    switch(interceptionType) {
        case AROUND_INVOKE:
            return doMethodInterception(context.getInvocationContext(), InterceptionType.AROUND_INVOKE, interceptorInstances, interceptorBindings);
        case AROUND_TIMEOUT:
            return doMethodInterception(context.getInvocationContext(), InterceptionType.AROUND_TIMEOUT, interceptorInstances, interceptorBindings);
        case PRE_DESTROY:
            try {
                return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
            } finally {
                interceptorInstances.getCreationalContext().release();
            }
        case POST_CONSTRUCT:
            return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
        case AROUND_CONSTRUCT:
            return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
        default:
            // should never happen
            return context.proceed();
    }
}
Also used : InterceptorInstances(org.jboss.as.weld.spi.InterceptorInstances) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) ComponentInstance(org.jboss.as.ee.component.ComponentInstance)

Example 4 with InterceptorBindings

use of org.jboss.weld.ejb.spi.InterceptorBindings in project core by weld.

the class EnterpriseBeanInterceptionTest method testInterceptors.

@Test
public void testInterceptors() throws Exception {
    SessionBean<Ball> ballSessionBean = (SessionBean<Ball>) beanManager.getBeans(Ball.class).iterator().next();
    InterceptorBindings interceptorBindings = new InterceptorBindingsAdapter(beanManager.getInterceptorModelRegistry().get(ballSessionBean.getAnnotated()));
    List<javax.enterprise.inject.spi.Interceptor> interceptors = new ArrayList<javax.enterprise.inject.spi.Interceptor>(interceptorBindings.getAllInterceptors());
    Assert.assertEquals(3, interceptors.size());
    List<Class<?>> expectedInterceptors = Arrays.<Class<?>>asList(Goalkeeper.class, Defender.class, Referee.class);
    Assert.assertTrue(expectedInterceptors.contains(interceptors.get(0).getBeanClass()));
    Assert.assertTrue(expectedInterceptors.contains(interceptors.get(1).getBeanClass()));
    Assert.assertTrue(expectedInterceptors.contains(interceptors.get(2).getBeanClass()));
    Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getBeanClass().getMethod("shoot")).size());
    Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getBeanClass().getMethod("shoot")).size());
    Assert.assertEquals(Goalkeeper.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getBeanClass().getMethod("shoot")).get(0).getBeanClass());
    Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, ballSessionBean.getBeanClass().getMethod("pass")).size());
    Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getBeanClass().getMethod("pass")).size());
    Assert.assertEquals(Defender.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, ballSessionBean.getBeanClass().getMethod("pass")).get(0).getBeanClass());
    Method finishGameMethod = ballSessionBean.getBeanClass().getMethod("finishGame", Timer.class);
    Assert.assertEquals(0, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, finishGameMethod).size());
    Assert.assertEquals(1, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, finishGameMethod).size());
    Assert.assertEquals(Referee.class, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, finishGameMethod).get(0).getBeanClass());
}
Also used : InterceptorBindingsAdapter(org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) SessionBean(org.jboss.weld.bean.SessionBean) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) Test(org.junit.Test)

Example 5 with InterceptorBindings

use of org.jboss.weld.ejb.spi.InterceptorBindings in project wildfly by wildfly.

the class WeldComponentIntegrationProcessor method addJsr299BindingsCreateInterceptor.

private static void addJsr299BindingsCreateInterceptor(final ComponentConfiguration configuration, final ComponentDescription description, final String beanName, final ServiceName weldServiceName, ServiceBuilder<?> builder, final ServiceName bindingServiceName, final ComponentInterceptorSupport componentInterceptorSupport) {
    // add the create interceptor that creates the Jakarta Contexts and Dependency Injection Interceptors
    final Supplier<WeldBootstrapService> weldContainerSupplier = builder.requires(weldServiceName);
    final Supplier<InterceptorBindings> interceptorBindingsSupplier = builder.requires(bindingServiceName);
    final Jsr299BindingsCreateInterceptor createInterceptor = new Jsr299BindingsCreateInterceptor(weldContainerSupplier, interceptorBindingsSupplier, description.getBeanDeploymentArchiveId(), beanName, componentInterceptorSupport);
    configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(createInterceptor), InterceptorOrder.ComponentPostConstruct.CREATE_CDI_INTERCEPTORS);
}
Also used : InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) Jsr299BindingsCreateInterceptor(org.jboss.as.weld.interceptors.Jsr299BindingsCreateInterceptor) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService)

Aggregations

InterceptorBindings (org.jboss.weld.ejb.spi.InterceptorBindings)6 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)2 WeldBootstrapService (org.jboss.as.weld.WeldBootstrapService)2 InterceptorInstances (org.jboss.as.weld.spi.InterceptorInstances)2 InterceptorBindingsAdapter (org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Interceptor (javax.enterprise.inject.spi.Interceptor)1 WeldInterceptorBindingsService (org.jboss.as.weld.ejb.WeldInterceptorBindingsService)1 Jsr299BindingsCreateInterceptor (org.jboss.as.weld.interceptors.Jsr299BindingsCreateInterceptor)1 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)1 ServiceName (org.jboss.msc.service.ServiceName)1 SlimAnnotatedType (org.jboss.weld.annotated.slim.SlimAnnotatedType)1 SessionBean (org.jboss.weld.bean.SessionBean)1 InterceptionModel (org.jboss.weld.interceptor.spi.model.InterceptionModel)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1 ClassTransformer (org.jboss.weld.resources.ClassTransformer)1 SerializableContextualInstance (org.jboss.weld.serialization.spi.helpers.SerializableContextualInstance)1 Test (org.junit.Test)1