You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Harald Wellmann <hw...@gmail.com> on 2012/12/09 20:11:15 UTC

Interceptor enablement per bean archive

Scenario:

There are two bean archives sample.jar and test.jar.
sample.jar contains an interceptor, an interceptor binding annotation 
and some beans with methods annotated by this annotation.

test.jar has some test classes verifying that the annotated methods do 
get intercepted.

The tests pass when the interceptor is enabled in 
sample/META-INF/beans.xml and fail as expected when not enabled.

Problem:

The tests also pass when the interceptor is enabled in 
tests/META-INF/beans.xml but not in sample/META-INF/beans.xml.

According to section 9.4. of the CDI 1.0 spec, I would have expected an 
interceptors definition in tests.jar to have no effect at all on beans 
in some other bean archive (sample.jar).

I'm testing in a plain old Java SE environment. Same problem with OWB 
1.1.6 and Weld 1.1.9.

I read the discussion in https://issues.jboss.org/browse/CDI-18 which 
seems to be related, but it sounds rather open-ended to me.

My questions:

1) Is it true that my tests SHOULD fail by CDI 1.0 if the interceptor is 
enabled in the wrong archive?

2) What is the implemented (or intended) behaviour in OWB, for Java SE 
and Java EE applications?

Best regards,
Harald



Re: Interceptor enablement per bean archive

Posted by Mark Struberg <st...@yahoo.de>.
org.apache.webbeans.useBDABeansXMLScanner=true

in openwebeans.properties.

just define one in your project with a higher ordinal > 100.

LieGrue,
strub





----- Original Message -----
> From: Harald Wellmann <hw...@gmail.com>
> To: user@openwebbeans.apache.org
> Cc: 
> Sent: Sunday, December 9, 2012 10:00 PM
> Subject: Re: Interceptor enablement per bean archive
> 
> 2012/12/9 Mark Struberg <st...@yahoo.de>:
>>  OWB ignores BDA for interceptors, alternatives and decorators by default. 
> You can enable the BDA behaviour via a flag.
>>  But I suggest to not use this flag ;)
>> 
> 
> Thanks for clarifying! I do agree global enablement is a more sensible default.
> 
> Just for reference: what exactly is this flag for enabling BDA behaviour?
> 
> Thanks,
> Harald
> 

Re: Interceptor enablement per bean archive

Posted by Harald Wellmann <hw...@gmail.com>.
2012/12/9 Mark Struberg <st...@yahoo.de>:
> OWB ignores BDA for interceptors, alternatives and decorators by default. You can enable the BDA behaviour via a flag.
> But I suggest to not use this flag ;)
>

Thanks for clarifying! I do agree global enablement is a more sensible default.

Just for reference: what exactly is this flag for enabling BDA behaviour?

Thanks,
Harald

Re: Interceptor enablement per bean archive

Posted by Mark Struberg <st...@yahoo.de>.
Hi Harald!

OWB ignores BDA for interceptors, alternatives and decorators by default. You can enable the BDA behaviour via a flag.
But I suggest to not use this flag ;)

Please think about _real_ applications. The world is already full with oversimplified and too abstract samples ;)

In a REAL application you do not have this problem! Enabling an interceptor or alternative will just have not effect on other libraries, because they simply do not use those interceptors.
Otoh think about a MailService from some backend library, a jar you take from another department in your company. This jar has tons of other functionality which uses the @Inject MailService ms; Now imagine you like to use an @Alternative SecureMailService. For using this you would need to change all the jars you get in from somewhere.

In current Glassfish and other EE server installations many big projects I know ended up unpacking all their dependencies to WEB-INF/classes and merge all beans.xml into WEB-INF/beans.xml manually :/

BDA enablement is really counter-productive in real world apps.



Btw, funnily @Specializes does NOT have this restriction!

LieGrue,
strub



----- Original Message -----
> From: Harald Wellmann <hw...@gmail.com>
> To: "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org>
> Cc: 
> Sent: Sunday, December 9, 2012 8:11 PM
> Subject: Interceptor enablement per bean archive
> 
> Scenario:
> 
> There are two bean archives sample.jar and test.jar.
> sample.jar contains an interceptor, an interceptor binding annotation and some 
> beans with methods annotated by this annotation.
> 
> test.jar has some test classes verifying that the annotated methods do get 
> intercepted.
> 
> The tests pass when the interceptor is enabled in sample/META-INF/beans.xml and 
> fail as expected when not enabled.
> 
> Problem:
> 
> The tests also pass when the interceptor is enabled in tests/META-INF/beans.xml 
> but not in sample/META-INF/beans.xml.
> 
> According to section 9.4. of the CDI 1.0 spec, I would have expected an 
> interceptors definition in tests.jar to have no effect at all on beans in some 
> other bean archive (sample.jar).
> 
> I'm testing in a plain old Java SE environment. Same problem with OWB 1.1.6 
> and Weld 1.1.9.
> 
> I read the discussion in https://issues.jboss.org/browse/CDI-18 which seems to 
> be related, but it sounds rather open-ended to me.
> 
> My questions:
> 
> 1) Is it true that my tests SHOULD fail by CDI 1.0 if the interceptor is enabled 
> in the wrong archive?
> 
> 2) What is the implemented (or intended) behaviour in OWB, for Java SE and Java 
> EE applications?
> 
> Best regards,
> Harald
>