« Return to Thread: default interceptor

Re: default interceptor

by David Blevins :: Rate this Message:

Reply to Author | View in Thread


On Mar 9, 2009, at 12:20 AM, is_maximum wrote:

>
> Hello
>
> I have defined a default interceptor as follows but there is a  
> warning that
> says :
>
> WARN - InterceptorBinding references non-existent (undeclared)  
> interceptor:
> com.foo.interceptor.RequestDataInterceptor
>
> and this interceptor never being executed.
>
>
> <interceptor-binding>
>        <ejb-name>*</ejb-name>
>        <interceptor-order>
>
> <interceptor-class>com.foo.interceptor.RequestDataInterceptor</
> interceptor-class>
>        </interceptor-order>
> </interceptor-binding>
>
> can anyone help me out this problem?


Sure.  It's a little strange, but per spec interceptors are declared  
independently like ejbs are and then the two are bound together in the  
assembly descriptor.  Here's a small example off an all annotation  
version and the equivalent in xml:

The app:

     @Stateful
     @Interceptors(OrangeInterceptor.class)
     public class OrangeBean implements OrangeLocal {

         public int echo(int i) {
             return i;
         }
     }

     public interface OrangeLocal {
         int echo(int i);
     }

     public class OrangeInterceptor {

         @PostConstruct
         public void construct(InvocationContext context){}

         @AroundInvoke
         public Object invoke(InvocationContext context) throws  
Exception {
             return context.proceed();
         }
     }

The resulting ejb-jar.xml:

   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee">
     <enterprise-beans>
       <session id="OrangeBean">
         <ejb-name>OrangeBean</ejb-name>
         <business-local>org.superbiz.OrangeLocal</business-local>
         <ejb-class>org.superbiz.OrangeBean</ejb-class>
         <session-type>Stateful</session-type>
         <transaction-type>Container</transaction-type>
       </session>
     </enterprise-beans>
     <interceptors>
       <interceptor>
         <interceptor-class>org.superbiz.OrangeInterceptor</
interceptor-class>
         <around-invoke>
           <class>org.superbiz.OrangeInterceptor</class>
           <method-name>invoke</method-name>
         </around-invoke>
         <post-construct>
           <lifecycle-callback-class>org.superbiz.OrangeInterceptor
           </lifecycle-callback-class>
           <lifecycle-callback-method>construct</lifecycle-callback-
method>
         </post-construct>
       </interceptor>
     </interceptors>
     <assembly-descriptor>
       <interceptor-binding>
         <ejb-name>OrangeBean</ejb-name>
         <interceptor-class>org.superbiz.OrangeInterceptor</
interceptor-class>
       </interceptor-binding>
     </assembly-descriptor>
   </ejb-jar>

So your binding is correct, you just need to declare your  
interceptor.  At the very least a minimal declaration like so:

     <interceptors>
       <interceptor>
         <interceptor-class>org.superbiz.OrangeInterceptor</
interceptor-class>
       </interceptor>
     </interceptors>

This would assume that the interceptor class is using the  
@AroundInvoke annotation, if not you would need to add the <around-
invoke> tag as shown above.

Hope this helps!

-David

 « Return to Thread: default interceptor