[ 
https://issues.apache.org/jira/browse/DELTASPIKE-1060?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15085358#comment-15085358
 ] 

Harald Wellmann commented on DELTASPIKE-1060:
---------------------------------------------

I'm not ready to give up yet ;-)

The following code snippet exhibits the issue _independent of DeltaSpike_:

{code}
        AnnotationLiteral<NoOp> noOpLit = new AnnotationLiteral<NoOp>(){};
        Interceptor<NoOpInterceptor> interceptorBean = 
(Interceptor<NoOpInterceptor>)
            beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, 
noOpLit).get(0);


        CreationalContext<NoOpInterceptor> context = 
beanManager.createCreationalContext(interceptorBean);
        NoOpInterceptor interceptor = interceptorBean.create(context);

        Method method = Simple.class.getMethod("getMessage");
        InvocationContext invocationContext = new InvocationContextImpl(new 
Simple(), method);
        
System.out.println(interceptorBean.intercept(InterceptionType.AROUND_INVOKE, 
interceptor, invocationContext));
{code}

Running this with Weld, I get the same exception on 
{{interceptorBean.create(context)}}. With OpenWebBeans, the call succeeds, but 
the {{@Intercepted}} bean injected into the interceptor instance is the 
interceptor bean, not the intercepted one (i.e. {{Bean<Simple>}}).

The following works on Weld, using an implementation specific API:

{code}
        Bean<Simple> simpleBean = (Bean<Simple>) 
beanManager.resolve(beanManager.getBeans(Simple.class));
        AnnotationLiteral<NoOp> noOpLit = new AnnotationLiteral<NoOp>(){};
        Interceptor<NoOpInterceptor> interceptorBean = 
(Interceptor<NoOpInterceptor>)
            beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, 
noOpLit).get(0);


        CreationalContextImpl<Simple> parentContext = 
(CreationalContextImpl<Simple>) beanManager.createCreationalContext(simpleBean);
        CreationalContext<NoOpInterceptor> context = 
parentContext.getCreationalContext(interceptorBean);
        NoOpInterceptor interceptor = interceptorBean.create(context);

        Method method = Simple.class.getMethod("getMessage");
        InvocationContext invocationContext = new InvocationContextImpl(new 
Simple(), method);
        
System.out.println(interceptorBean.intercept(InterceptionType.AROUND_INVOKE, 
interceptor, invocationContext));
{code}

Note the use of {{CreationalContextImpl}} to set the parent context.

So the bottom line is:

* Is this usage of {{javax.enterprise.inject.spi.Interceptor<T>}} and of 
obtaining an interceptor instance via {{interceptorBean.create(cc}} correct? If 
not, what's the correct usage? Or if you're not supposed to create an 
interceptor instance via {{BeanManager}} at all, then what's the whole point of 
the {{javax.enterprise.inject.spi.Interceptor<T>}} API?
* Should there be an official API for creating a {{CreationalContext}} linked 
to a given parent context?
* As long as there is no such official API, can we write an adapter in 
DeltaSpike that works both for Weld and OpenWebBeans and use that in our proxy 
classes to make interceptors work on partial beans?

> @Intercepted does not work with partial bean proxy
> --------------------------------------------------
>
>                 Key: DELTASPIKE-1060
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1060
>             Project: DeltaSpike
>          Issue Type: Bug
>          Components: Proxy-Module
>    Affects Versions: 1.5.2
>            Reporter: Harald Wellmann
>            Assignee: Harald Wellmann
>            Priority: Minor
>         Attachments: deltaspike1060.tgz
>
>
> For a partial bean with an interceptor binding and an interceptor which 
> injects the intercepted bean, e.g.
> {code}
>     @Inject
>     @Intercepted
>     private Bean<?> intercepted;
> {code}
> Weld 2.2+ throws the following exception when an intercepted method of the 
> partial bean is invoked:
> {noformat}
> Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001549: 
> Unable to determine parent creational context of 
> org.jboss.weld.context.CreationalContextImpl@4841524b
>       at 
> org.jboss.weld.bean.builtin.AbstractBuiltInMetadataBean.getParentCreationalContext(AbstractBuiltInMetadataBean.java:65)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.bean.builtin.InterceptedBeanMetadataBean.newInstance(InterceptedBeanMetadataBean.java:62)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.bean.builtin.InterceptedBeanMetadataBean.newInstance(InterceptedBeanMetadataBean.java:47)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.bean.builtin.AbstractBuiltInMetadataBean.create(AbstractBuiltInMetadataBean.java:53)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50) 
> [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:761) 
> [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:861)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:375) 
> [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:386) 
> [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:70)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:72)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
>  [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:159) 
> [weld-core-impl-2.2.14.Final.jar:2015-06-24 15:18]
>       at 
> org.apache.deltaspike.proxy.impl.invocation.ManualInvocationContext.proceed(ManualInvocationContext.java:84)
>       at 
> org.apache.deltaspike.proxy.impl.invocation.AbstractManualInvocationHandler.invoke(AbstractManualInvocationHandler.java:48)
>       at 
> org.apache.deltaspike.proxy.impl.invocation.DelegateManualInvocationHandler.staticInvoke(DelegateManualInvocationHandler.java:39)
>       at demo.CustomerDao$$DSPartialBeanProxy.findBy(Unknown Source)
> {noformat}
> The problem was discovered trying to port an application from WildFly 
> 9.0.1.Final to 10.0.0.CR5. In WildFly 10, the Narayana transactional 
> interceptor implementation does inject the intercepted bean, which was not 
> the case in WildFly 9.
> The problem can be reproduced also on WildFly 9 with a simple demo 
> interceptor. I'll attach a sample project.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to