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

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

I haven't looked at OWB yet in detail, but I'm planning to do so.

Another question, coming back to DeltaSpike Partial Beans:

Assuming I had to manually write a class similar to the generated proxy, I 
understand it would look more or less like this:

{code}
@ApplicationScoped
public class DelegatingCalculator extends AbstractCalculator
{
    private InvocationHandler handler;
    
    @Inject 
    public DelegatingCalculator(@Named("calculator") InvocationHandler handler)
    {
        this.handler = handler;
    }

    @Override
    public int add(int left, int right)
    {
        Method method;
        try
        {
            method = AbstractCalculator.class.getDeclaredMethod("add", 
int.class, int.class);
            return (int) handler.invoke(this, method, new Object[]{left, 
right});
        }
        catch (Throwable e)
        {
            throw new RuntimeException(e);
        }
    }
}
{code}

where {{AbstractCalculator}} is a partial bean with an interceptor binding

{code}
// add partial bean binding annotation
@ApplicationScoped
@NoOp // this is an interceptor binding
public abstract class AbstractCalculator
{

    public abstract int add(int left, int right);
    
    public int subtract(int left, int right)
    {
        return add(left, -right);
    }
}
{code}

Running this sample on Weld and invoking {{DelegatingCalculator.add()}}, the 
method gets intercepted by the {{NoOpInterceptor}} without further trickery.

So I wonder why this wouldn't work if {{DelegatingCalculator}} were generated 
by ASM and added to the {{BeanManager}} by a CDI extension? What's the reason 
for the interceptor machinery implemented in the Proxy module?

> @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