users@glassfish.java.net

Re: ejb-jar.xml assembly-descriptor question: interceptor recognized, but not loaded?

From: Cheng Fang <cheng.fang_at_oracle.com>
Date: Sun, 27 May 2012 22:28:33 -0400

If your bean class is declared:
@Stateless
public class PersonBean extends AbstractDAO implements PersonManager...

then PersonManager is deemed its remote (if it's annotated with
@Remote), or local (if it's annotated with @Local, or nothing to that
effect). So business methods can only come from PersonManager. If
PersonBean indirectly implements DAO, where your persist method is
declared, DAO is not considered its business interface. Interceptors
only apply to business methods.

-cheng

On 5/27/12 9:52 PM, Laird Nelson wrote:
> On Sun, May 27, 2012 at 8:19 PM, Laird Nelson <ljnelson_at_gmail.com
> <mailto:ljnelson_at_gmail.com>> wrote:
>
> The problem is either with my understanding of the <ejb-name>
> element or Glassfish's resolution of it.
>
>
> Must have been my understanding (not surprised); an <ejb-name> of
> PersonBean works just fine.
>
> It's when I add the <method> stanza. I am using style #3 on page 563
> of the EJB 3.1 specification. Here is the specification's example of
> the style:
>
> <interceptor-binding>
> <ejb-name>EJBNAME</ejb-name>
> <interceptor-class>INTERCEPTOR</interceptor-class>
> <method>
> <method-name>METHOD</method-name>
> </method>
> </interceptor-binding>
>
> Note the <method> stanza.
>
> Mine works if I use style #2--that is, if I omit the <method> stanza
> altogether. My interceptor is fired on all methods of PersonBean,
> including the one I want:
>
> <interceptor-binding>
> <ejb-name>EJBNAME</ejb-name>
> <interceptor-class>INTERCEPTOR</interceptor-class>
> </interceptor-binding>
>
> ...but my interceptor is not created or fired if I put in the name of
> the method that I would like intercepted. It is as though the method
> is silently ignored.
>
> When I use style #2, I made sure my interceptor outputs the name of
> the method ("persist", in my case). I used that value for the
> <method-name> element in style #3. No luck.
>
> I'm wondering if inheritance is an issue here.
>
> My stateless EJB (PersonBean) inherits from an abstract class
> (non-EJB; AbstractDAO) that implements DAO, an interface.
>
> My EJB also directly implements PersonManager, another interface.
>
> So:
>
> @Stateless
> public class PersonBean extends AbstractDAO implements PersonManager...
>
> The persist method signature is defined in DAO and implemented in
> AbstractDAO.
>
> I figured that the proper way to refer to this was:
>
> <interceptor-binding>
> <ejb-name>PersonBean</ejb-name>
> <interceptor-class>com.foobar.NewPersonInterceptor</interceptor-class>
> <method>
> <method-name>persist</method-name>
> </method>
> </interceptor-binding>
>
> ...although strictly speaking PersonBean does not override or
> otherwise directly declare the "persist" method (that is declared in
> his superclass).
>
> Soldiering onwards!
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>