11 Replies Latest reply on Dec 21, 2010 6:43 PM by janario

    Is It Possible To Create New Interceptor In Weld SE

    xsalefter.xsalefter.yahoo.com

      Hi weld user and developer..


      Recently I'm play with Weld-SE, and try to define and create an Interceptor like this:



      @Target({ElementType.TYPE, ElementType.METHOD})
      @Retention(RetentionPolicy.RUNTIME)
      @Documented
      @InterceptorBinding
      public @interface View {
          String value() default "";
      }
      
      @Interceptor @View 
      public class ViewControllerInterceptor {
      
          @AroundInvoke
          public Object aroundInvoke(InvocationContext ic) throws Exception {
              System.out.println("Did it." + ic.getTarget());
              return ic.proceed();
          }
      }



      And this is my beans.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="
            http://java.sun.com/xml/ns/javaee
            http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
      
                <interceptors>
                    <class>org.xsalefter.swingmvc.ViewControllerInterceptor</class>
                </interceptors>
      </beans>



      But I get DeploymentException like this:



      08:29:53,906 INFO  [weld.Version] WELD-000900 1.0.1 (Final)
      08:29:53,953 INFO  [weld.Bootstrap] WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
      08:29:54,828 WARN  [model.InterceptionTypeRegistry] Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
      08:29:54,828 WARN  [model.InterceptionTypeRegistry] Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
      Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: WELD-001416 Enabled interceptor class class org.xsalefter.swingmvc.ViewControllerInterceptor specified twice specified twice
              at org.jboss.weld.bootstrap.Validator.validateEnabledInterceptorClasses(Validator.java:445)
              at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:319)
              at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:399)
              at org.jboss.weld.environment.se.Weld.initialize(Weld.java:81)
              at org.jboss.weld.environment.se.StartMain.go(StartMain.java:45)
              at org.jboss.weld.environment.se.StartMain.main(StartMain.java:57)
      Java Result: 1



      As far as I know from the stack trace seems that I can't create new Interceptor. My question is that, is it possible to define interceptor in weld like this? If yes, can someone help me to do it correctly?


      Thanks.

        • 1. Re: Is It Possible To Create New Interceptor In Weld SE
          pmuir

          Bug in Weld 1.0.1 that is fixed in 1.1.0.Beta1 :-)

          • 2. Re: Is It Possible To Create New Interceptor In Weld SE
            xsalefter.xsalefter.yahoo.com

            Hi, pete. Thanks for your response. I just update to Weld 1.1 beta, but unfortunately It's still doesn't work. Futhermore, if I disable the interceptor, I get strange exception where I never found it in Weld 1.0:


            Exception in thread "main" org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
            Exception 0 :
            com.google.common.collect.ComputationException: java.lang.VerifyError: (class: org/jboss/weld/environment/se/org$jboss$weld$bean-classpath-Built-in-Extension-org$jboss$weld$environment$se$WeldSEBeanRegistrant_$$_WeldProxy, method: writeReplace signature: ()Ljava/lang/Object;) Illegal type in constant pool
                    at com.google.common.collect.ComputingConcurrentHashMap.compute(ComputingConcurrentHashMap.java:218)
                    at com.google.common.collect.ComputingConcurrentHashMap.apply(ComputingConcurrentHashMap.java:100)
                    at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:515)
                    at org.jboss.weld.bean.proxy.ClientProxyProvider.getClientProxy(ClientProxyProvider.java:104)
                    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:651)
                    at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:252)
                    at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:222)
                    at org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:88)
                    at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:52)
                    at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:43)
                    at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:393)
                    at org.jboss.weld.environment.se.Weld.initialize(Weld.java:90)
                    at org.jboss.weld.environment.se.StartMain.go(StartMain.java:45)
                    at org.jboss.weld.environment.se.StartMain.main(StartMain.java:57)
            Caused by: java.lang.VerifyError: (class: org/jboss/weld/environment/se/org$jboss$weld$bean-classpath-Built-in-Extension-org$jboss$weld$environment$se$WeldSEBeanRegistrant_$$_WeldProxy, method: writeReplace signature: ()Ljava/lang/Object;) Illegal type in constant pool
                    at java.lang.Class.getDeclaredConstructors0(Native Method)
                    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
                    at java.lang.Class.getConstructor0(Class.java:2699)
                    at java.lang.Class.newInstance0(Class.java:326)
                    at java.lang.Class.newInstance(Class.java:308)
                    at org.jboss.weld.util.reflection.SecureReflections$16.work(SecureReflections.java:396)
                    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
                    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInstantiation(SecureReflectionAccess.java:216)
                    at org.jboss.weld.util.reflection.SecureReflections.newInstance(SecureReflections.java:391)
                    at org.jboss.weld.bean.proxy.ProxyFactory.create(ProxyFactory.java:218)
                    at org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:89)
                    at org.jboss.weld.bean.proxy.ClientProxyProvider.access$000(ClientProxyProvider.java:40)
                    at org.jboss.weld.bean.proxy.ClientProxyProvider$1.apply(ClientProxyProvider.java:53)
                    at org.jboss.weld.bean.proxy.ClientProxyProvider$1.apply(ClientProxyProvider.java:44)
                    at com.google.common.collect.ComputingConcurrentHashMap.compute(ComputingConcurrentHashMap.java:206)
                    ... 13 more
            
                    at org.jboss.weld.bootstrap.events.AbstractDefinitionContainerEvent.fire(AbstractDefinitionContainerEvent.java:55)
                    at org.jboss.weld.bootstrap.events.BeforeBeanDiscoveryImpl.fire(BeforeBeanDiscoveryImpl.java:43)
                    at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:393)
                    at org.jboss.weld.environment.se.Weld.initialize(Weld.java:90)
                    at org.jboss.weld.environment.se.StartMain.go(StartMain.java:45)
                    at org.jboss.weld.environment.se.StartMain.main(StartMain.java:57)
            Java Result: 1




            However, I try google it and found Adam Warski blog, and refers to his blog post he's successfully to do it, even in weld 1.0.

            • 3. Re: Is It Possible To Create New Interceptor In Weld SE
              swd847

              hmm, this looks like a bug in the new proxy implementation.


              Which JVM are you using?


              • 4. Re: Is It Possible To Create New Interceptor In Weld SE
                swd847

                Also, if you are not already using it can you try the latest sun/oracle java 6 JVM and see if you still get this exception?

                • 5. Re: Is It Possible To Create New Interceptor In Weld SE
                  xsalefter.xsalefter.yahoo.com

                  Hi, Stuart. Sorry for take a long time for reply this. I've had been in my client place for 2 days and isolated there.


                  I'm using Sun/Oracle JDK 1.6.0 update 14. Should I update it to the latest release (1.6.0 update 21)?

                  • 6. Re: Is It Possible To Create New Interceptor In Weld SE
                    swd847

                    If you could try with update 21 that would be great.


                    I think this is related to WELD-661, which is fixed in the latest master.


                    • 7. Re: Is It Possible To Create New Interceptor In Weld SE
                      xsalefter.xsalefter.yahoo.com

                      I try update 21 and get no luck. The exception thrown the same message. By the way, there is no downloadable jars for beta 2 release?

                      • 8. Re: Is It Possible To Create New Interceptor In Weld SE
                        swd847

                        No there are no downloadable jars, you will have to download it from github and build it yourself.


                        It is available at http://github.com/weld/core, you can just hit the download source button on the top right, you do not actually need git.

                        • 9. Re: Is It Possible To Create New Interceptor In Weld SE
                          swd847

                          I have not been able to reproduce the VerifyError using Sun/Oracle Java update 21 under Linux or OSX.


                          When you say the same exception is thrown do you mean the VerifyError or this one:


                          Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: WELD-001416 Enabled interceptor class class org.xsalefter.swingmvc.ViewControllerInterceptor specified twice specified twice
                          



                          • 10. Re: Is It Possible To Create New Interceptor In Weld SE
                            xsalefter.xsalefter.yahoo.com

                            Ok.. My bad. Exception:



                            08:29:53,953 INFO  [weld.Bootstrap] WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
                            08:29:54,828 WARN  [model.InterceptionTypeRegistry] Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
                            08:29:54,828 WARN  [model.InterceptionTypeRegistry] Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
                            Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: WELD-001416 Enabled interceptor class class org.xsalefter.swingmvc.ViewControllerInterceptor specified twice specified twice
                                    at org.jboss.weld.bootstrap.Validator.validateEnabledInterceptorClasses(Validator.java:445)
                                    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:319)
                                    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:399)
                                    at org.jboss.weld.environment.se.Weld.initialize(Weld.java:81)
                                    at org.jboss.weld.environment.se.StartMain.go(StartMain.java:45)
                                    at org.jboss.weld.environment.se.StartMain.main(StartMain.java:57)
                            Java Result: 1



                            Only happened if:



                            1. I'm using netbeans to run Weld SE.

                            2. Interceptor are enabled.



                            So when I run the application using commandline, the interceptor is run well, and works as expected both in Weld 1.0, 1.1 Beta1, or Beta 2. This is strange.

                            • 11. Re: Is It Possible To Create New Interceptor In Weld SE
                              janario

                              Hello, sorry my English I don't speak very well.
                              I did have this problem too.


                              try this:
                              When you run in the NetBeans IDE code:




                              Enumeration<URL> resources = ClassLoader.getSystemClassLoader().getResources("META-INF/beans.xml");
                              while (resources.hasMoreElements()) {
                                 String urlPath = resources.nextElement().getFile();
                              //...process file beans.xml
                              }





                              the code return two files, the files of the src and bin then the Weld process two beans.xml and two Inteceptors in each file then when have two interceptors equals the Weld throw exception.


                              This is because the classpath.
                              The solution for this problem is:
                              1-Properties of the project
                              2-Compiling and uncheck Compile on Save
                              3-Make a Clean-Build an try again