4 Replies Latest reply on Nov 30, 2007 11:31 AM by xinhua

    @Startup and Seam interceptor

    xinhua

      Hi everybody,

      it seems that Seam interceptor doesnot work with @Startup.
      I have an app scope Seam Component loaded by deployment, in this Seam Component i use my own annotaion (which used seam interceptor) to inject jndi resource, but it does not work.

      please help

      many thanks in advance

        • 1. Re: @Startup and Seam interceptor

          Does your interceptor work with other Seam components that are not annotated with @Startup? Please post your annotation and interceptor code.

          • 2. Re: @Startup and Seam interceptor
            xinhua

            hi,
            yes, interceptor works fine with other component without @Startup

            At first, i have two annotations

            @Target(TYPE)
            @Documented
            @Retention(RUNTIME)
            @Interceptors(KleberInterceptor.class)
            public @interface Kleber
            {
            
            }
            




            interceptor is supposed to check filed with @Jndi annotation and take the string from @jndi for jndi lookup
            public class KleberInterceptor {
            
             @PostConstruct
             public Object jndiLookup(InvocationContext invocation )throws Exception{
             Object target = invocation.getTarget();
             Field[] fields = target.getClass().getDeclaredFields();
            
             try{
             InitialContext ctx = new InitialContext();
             for(Field field: fields){
             Jndi jndi = field.getAnnotation(Jndi.class);
             if(jndi!=null){
             Object obj = ctx.lookup(jndi.value());
             field.setAccessible(true);
             field.set(target, obj);
             }
             }
            
             }catch(Exception ex){
             ex.printStackTrace();
             }
            
             return invocation.proceed();
             }
            
             @AroundInvoke
             otherMethods............
            
            
            }
            


            I can not use @Kleber on a component which already has a @Startup, what i can do now ,is to write jndi lookup codes directly in @Startup component, and it works.....

            is there any better way to inject jndi resouce in @Startup Seam component?




            • 3. Re: @Startup and Seam interceptor
              pmuir

              So how does it not work? Does the interceptor run? Does it run and not set the values?

              • 4. Re: @Startup and Seam interceptor
                xinhua

                 

                "pete.muir@jboss.org" wrote:
                So how does it not work? Does the interceptor run? Does it run and not set the values?


                nothing happened. @Startup is ignored also. Interceptor does not run.

                i put a @Create in this @Startup seam component, if my annotation @Kleber is there, @Create function doesnt run, the compoent wont be created by deployment.

                I donot know how to debug a @Startup Seam component :(