5 Replies Latest reply on Oct 14, 2005 5:30 AM by kabirkhan

    Multiples Interceptor with the same class

    fredmaster

      hi,

      The problem

      I declared two interceptors with a same class and different pointcuts

      <bind pointcut="Class1">
       <interceptor name="Inter1" scope="PER_INSTANCE">
       <attribute name="attributeA">A</attribute>
       </interceptor>
      </bind>
      
      <bind pointcut="Class2">
       <interceptor name="Inter2" scope="PER_INSTANCE">
       <attribute name="attributeA">B</attribute>
       </interceptor>
      </bind>
      

      The problem is that the last interceptor created overrides the attributes of the first, because the key of the Interceptor in the JbossAop is the class name and not the interceptor name.

      Somebody can I help me ? Why the key of the interceptor not is the name

        • 1. Re: Multiples Interceptor with the same class
          kabirkhan

          What you have pasted in should not work at all :-) I think you are looking for:

          <bind pointcut="all(package.Class1)">
           <interceptor name="Inter1" class="package.MyInterceptor" scope="PER_INSTANCE">
           <attribute name="attributeA">A</attribute>
           </interceptor>
          </bind>
          
          <bind pointcut="all(package.Class2)">
           <interceptor name="Inter1" class="package.MyInterceptor" scope="PER_INSTANCE">
           <attribute name="attributeA">B</attribute>
           </interceptor>
          </bind>
          


          OR

           <interceptor name="Inter1" class="package.MyInterceptor" scope="PER_INSTANCE">
           <attribute name="attributeA">A</attribute>
           </interceptor>
           <interceptor name="Inter2" class="package.MyInterceptor" scope="PER_INSTANCE">
           <attribute name="attributeA">B</attribute>
           </interceptor>
          
          <bind pointcut="all(package.Class1)">
           <interceptor-ref name="Inter1"/>
          </bind>
          
          <bind pointcut="all(package.Class2)">
           <interceptor-ref name="Inter2"/>
          </bind>
          


          If you do not explicitly use a name attribute in your intertceptor declaration it will use the fully qualified name of the class as the name

          • 2. Re: Multiples Interceptor with the same class
            fredmaster

            The problem not is a sintax.

            See

            I have two projects ".aop" with a file "jboss-aop.xml"

            The frist "jboss-aop.xml" have

             <bind pointcut="execution(private void br.com.singu.pessoa.facade.PessoaSessionFacadeBean->setPessoaFromPessoaDto(..))">
             <interceptor name="interceptor1" class="br.com.singu.aop.FieldChangedInterceptor" scope="PER_INSTANCE">
             <attribute name="fieldName">getIdSituacaoPessoa</attribute>
             <attribute name="observerId">br.com.singu.pessoa.facade.PessoaSessionFacadeBean.setPessoaFromPessoaDto</attribute>
             </interceptor>
             </bind>
            


            The second "jboss-aop.xml" have

             <bind pointcut="execution(private void br.com.singu.academico.aluno.facade.AlunoCursoSessionFacadeBean->setAlunoCursoFromAlunoCursoDto(..))">
             <interceptor name="interceptor2" class="br.com.singu.aop.FieldChangedInterceptor" scope="PER_INSTANCE">
             <attribute name="fieldName">getIdSituacaoAlunoCurso</attribute>
             <attribute name="observerId">br.com.singu.academico.observer.SituacaoAlunoCursoObserver</attribute>
             </interceptor>
             </bind>
            


            Execution

            1 - method "setAlunoCursoFromAlunoCursoDto" the value of the fieldName is "getIdSituacaoAlunoCurso"
            2 - method "setPessoaFromPessoaDto" the value of the fieldName is "getIdSituacaoPessoa"
            3 - method "setAlunoCursoFromAlunoCursoDto" the value of the fieldName is "getIdSituacaoPessoa"

            The execution of the method "setPessoaFromPessoaDto" interceptor1 overrrides the value of the interceptor2.

            • 3. Re: Multiples Interceptor with the same class
              kabirkhan

              Can you try to change the scope of the interceptor and let me know if that behaves any differently? I'm wondering if there could be an error in how per instance interceptors are handled for this.

              Thanks

              • 4. Re: Multiples Interceptor with the same class
                fredmaster

                I tried changes the scope for PER_CLASS and PER_JOINPOINT but the error persists.

                • 5. Re: Multiples Interceptor with the same class
                  kabirkhan

                  A simple standalone example works for me. Can you provide some more details about your packaging and if you're running within JBoss or not?

                  Or even better create a jira issue with a test case showing the behaviour: http://jira.jboss.com/jira/browse/JBAOP