2 Replies Latest reply on Apr 11, 2007 1:59 AM by haensel

    Implementing an EJB3 Interceptor without touching the projec

    haensel

      Hello,

      my name is Hans-Martin and I am a student at the university of Regensburg, Germany.
      I have to hold a lab about EJB3 on JBoss with interceptors. Now I read for about 2 days just to check out how to implement an ejb3 interceptor without touching the project with the business objects (stateless session beans) itself.
      By that annotations are no options...or deployment descriptors (ejb-jar.xml), because I have to add them to the project I want to check with my interceptor.

      I already worked with ejb2 interceptors, but implementing them was just a piece of cake.
      Add you interceptor in the standardjboss.xml file and everything is fine. You don´t have to touch other projects.

      But HOW is this possible with EJB3 interceptors ? I added my interceptor to the ejb3-interceptors-aop.xml.
      Then I got a ClassDefNotFound Exception at the jboss startup. So I added the jar file with my interceptor to the jboss lib (which can´t be the right way anyway). After that I got a ClassCastException on jboss startup.
      But I don´t get the classdefnotfound/classcastexception if I change the scope entry of my interceptor from ?PER_CLASS?/?PER_VM? to ?PER_INSTANCE? within the xml file.

      But then the interceptor does not trigger.

      I have absolutely no more ideas how to implement ejb3 interceptors without touching the projects which shall be wrapped by the interceptors.

      Do you have any ideas ? Or perhaps know a good tutorial or something like this ? I would be more than happy !!!!


      Greetings from Germany,


      Hans

      P.s. I am using Jboss 4.0.5 with JbossIde 2.0.0b. , jre:1.5.0_11, JDK: 1.5.0_09

        • 1. Re: Implementing an EJB3 Interceptor without touching the pr
          bdecoste

          If you add the interceptor as a default for all beans of a certain type by modifying ejb3-interceptors-aop.xml, then you need the interceptor class to be globally loadable by all ejb3s (in server/XXX/lib as you did or in the deployers/ejb3.deployer directory).

          Can you paste the changes you have made to ejb3-interceptors-aop.xml?

          • 2. Re: Implementing an EJB3 Interceptor without touching the pr
            haensel

            Heya,

            thank you so much for your reply.

            The changes I made for my ejb3 Inteceptor looks like this:

            <interceptor class="haensl.ejb3interceptors.MyDefaultInterceptor" scope="PER_CLASS"/>
            
            <domain name="Stateless Bean">
             <bind pointcut="execution(public * *->*(..))">
             <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
             <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
             <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
             </bind>
             <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
             <interceptor-ref name="Basic Authorization"/>
             </bind>
             <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
             <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
             </bind>
             <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
             <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
             </bind>
             <bind pointcut="execution(public * *->*(..))">
             <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
             <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
             <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
             <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
             <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
             <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
             <!--interceptor-ref name="haensl.ejb3interceptors.MyDefaultInterceptor"/ -->
             </bind>


            For loading this interceptor by all ejbs which are deployed on the server I just have to copy my .jar file with the interceptor to the lib folder of the server ?
            It still doesnt work that way.

            And with deployment descriptors I only worked so far that I know that I have to add them to the target projects which needed to be intercepted.
            But by this I have to "touch" those projects. And that is not my intention.

            Or is there some kind of "global deployment descriptor folder" in the server structure ?


            Thank you so much,


            Hans