4 Replies Latest reply: Apr 2, 2012 7:17 AM by Mathieu Lachance RSS

infinispan-cdi + weld

Mathieu Lachance Newbie

Hello,

I'm trying to make a really simple infinispan project using cdi annotations (backed by jboss weld project) using this maven dependency configuration :

 

    <dependency>
      <groupId>org.jboss.weld.se</groupId>
      <artifactId>weld-se</artifactId>
      <version>2.0.0.Alpha1</version>
    </dependency>
    
    <dependency>
      <groupId>org.infinispan</groupId>
      <artifactId>infinispan-core</artifactId>
      <version>5.1.3.CR1</version>
    </dependency>
    
    <dependency>
      <groupId>org.infinispan</groupId>
      <artifactId>infinispan-cdi</artifactId>
      <version>5.1.3.CR1</version>
    </dependency>

 

with the empty beans.xml :

 

<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">
      

</beans>

 

using this maven command in eclipse :

 

Goals : exec:java -e
Parameter Name, Value :
exec.mainClass, org.jboss.weld.environment.se.StartMain

 

but, even if the project is empty, i get the following exception :

 

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1.jbossorg-3:java (default-cli) on project cdi: An exception occurred while executing the Java class. null: InvocationTargetException: WELD-000409 Observer method for container lifecycle event [[method] org.infinispan.cdi.InfinispanExtension.registerCacheConfigurations(AfterDeploymentValidation, CacheManagerEventBridge, Instance<EmbeddedCacheManager>, BeanManager)] can only inject BeanManager. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1.jbossorg-3:java (default-cli) on project cdi: An exception occurred while executing the Java class. null
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
          at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
          at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
          at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
          at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
          at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
          at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
          at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occurred while executing the Java class. null
          at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:352)
          at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
          ... 19 more
Caused by: java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
          at java.lang.Thread.run(Thread.java:680)
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000409 Observer method for container lifecycle event [[method] org.infinispan.cdi.InfinispanExtension.registerCacheConfigurations(AfterDeploymentValidation, CacheManagerEventBridge, Instance<EmbeddedCacheManager>, BeanManager)] can only inject BeanManager.
          at org.jboss.weld.event.ObserverMethodImpl.checkObserverMethod(ObserverMethodImpl.java:164)
          at org.jboss.weld.event.ObserverMethodImpl.initialize(ObserverMethodImpl.java:210)
          at org.jboss.weld.bootstrap.ExtensionBeanDeployer.deployBeans(ExtensionBeanDeployer.java:75)
          at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:318)
          at org.jboss.weld.environment.se.Weld.initialize(Weld.java:85)
          at org.jboss.weld.environment.se.StartMain.go(StartMain.java:41)
          at org.jboss.weld.environment.se.StartMain.main(StartMain.java:52)
          ... 6 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

 

I also have try to downgrade the weld version to : 1.1.6.Final, but I still get the following exception :

 

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1.jbossorg-3:java (default-cli) on project cdi: An exception occurred while executing the Java class. null: InvocationTargetException: WELD-001450 Interceptor method public java.lang.Object org.jboss.solder.exception.control.ExceptionHandledInterceptor.passExceptionsToSolderCatch(javax.interceptor.InvocationContext) throws java.lang.Throwable does not declare that it throws Exception. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1.jbossorg-3:java (default-cli) on project cdi: An exception occurred while executing the Java class. null
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
          at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
          at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
          at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
          at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
          at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
          at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
          at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occurred while executing the Java class. null
          at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:352)
          at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
          ... 19 more
Caused by: java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
          at java.lang.Thread.run(Thread.java:680)
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-001450 Interceptor method public java.lang.Object org.jboss.solder.exception.control.ExceptionHandledInterceptor.passExceptionsToSolderCatch(javax.interceptor.InvocationContext) throws java.lang.Throwable does not declare that it throws Exception.
          at org.jboss.weld.interceptor.reader.InterceptorMetadataUtils.isValidBusinessMethodInterceptorMethod(InterceptorMetadataUtils.java:98)
          at org.jboss.weld.interceptor.reader.InterceptorMetadataUtils.isInterceptorMethod(InterceptorMetadataUtils.java:53)
          at org.jboss.weld.interceptor.reader.InterceptorMetadataUtils.buildMethodMap(InterceptorMetadataUtils.java:130)
          at org.jboss.weld.interceptor.reader.InterceptorMetadataUtils.readMetadataForInterceptorClass(InterceptorMetadataUtils.java:38)
          at org.jboss.weld.interceptor.reader.cache.DefaultMetadataCachingReader$1.apply(DefaultMetadataCachingReader.java:30)
          at org.jboss.weld.interceptor.reader.cache.DefaultMetadataCachingReader$1.apply(DefaultMetadataCachingReader.java:28)
          at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:355)
          at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:184)
          at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:153)
          at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:69)
          at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:393)
          at org.jboss.weld.interceptor.reader.cache.DefaultMetadataCachingReader.getInterceptorMetadata(DefaultMetadataCachingReader.java:54)
          at org.jboss.weld.bean.InterceptorImpl.<init>(InterceptorImpl.java:64)
          at org.jboss.weld.bean.InterceptorImpl.of(InterceptorImpl.java:59)
          at org.jboss.weld.bootstrap.AbstractBeanDeployer.createInterceptor(AbstractBeanDeployer.java:228)
          at org.jboss.weld.bootstrap.BeanDeployer.createBeans(BeanDeployer.java:137)
          at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:204)
          at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:349)
          at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.deployBeans(ForwardingBootstrap.java:70)
          at org.jboss.weld.environment.se.Weld.initialize(Weld.java:133)
          at org.jboss.weld.environment.se.StartMain.go(StartMain.java:41)
          at org.jboss.weld.environment.se.StartMain.main(StartMain.java:52)
          ... 6 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException



 

I am missing something ?

 

Any help will be greatly appreciated,

 

Big thanks,

  • 1. Re: infinispan-cdi + weld
    Galder Zamarreño Master

    No idea. Can you build a test case and add it to https://github.com/infinispan/infinispan/tree/master/cdi/extension project and we can then look into it?

  • 2. Re: infinispan-cdi + weld
    Mathieu Lachance Newbie

    I am not really familiar with git but I've made a very simple maven project including the test.

     

    See attachment

  • 3. Re: infinispan-cdi + weld
    Mathieu Lachance Newbie

    I've looked up at the weld source code and here's the method that make it crash :

     

    org.jboss.weld.event.ObserverMethodImpl :

     

        /**
         * Performs validation of the observer method for compliance with the
         * specifications.
         */
        private void checkObserverMethod() {
            // Make sure exactly one and only one parameter is annotated with Observes
            List<?> eventObjects = this.observerMethod.getAnnotated().getWeldParameters(Observes.class);
            if (this.reception.equals(Reception.IF_EXISTS) && declaringBean.getScope().equals(Dependent.class)) {
                throw new DefinitionException(INVALID_SCOPED_CONDITIONAL_OBSERVER, this);
            }
            if (eventObjects.size() > 1) {
                throw new DefinitionException(MULTIPLE_EVENT_PARAMETERS, this);
            }
            // Check for parameters annotated with @Disposes
            List<?> disposeParams = this.observerMethod.getAnnotated().getWeldParameters(Disposes.class);
            if (disposeParams.size() > 0) {
                throw new DefinitionException(INVALID_DISPOSES_PARAMETER, this);
            }
            // Check annotations on the method to make sure this is not a producer
            // method, initializer method, or destructor method.
            if (this.observerMethod.getAnnotated().isAnnotationPresent(Produces.class)) {
                throw new DefinitionException(INVALID_PRODUCER, this);
            }
            if (this.observerMethod.getAnnotated().isAnnotationPresent(Inject.class)) {
                throw new DefinitionException(INVALID_INITIALIZER, this);
            }
            boolean containerLifecycleObserverMethod = Observers.isContainerLifecycleObserverMethod(this);
            for (WeldParameter<?, ?> parameter : getMethod().getAnnotated().getWeldParameters()) {
                if (parameter.isAnnotationPresent(Named.class) && parameter.getAnnotation(Named.class).value().equals("")) {
                    throw new DefinitionException(NON_FIELD_INJECTION_POINT_CANNOT_USE_NAMED, getMethod());
                }
                // if this is an observer method for container lifecycle event, it must not inject anything besides BeanManager
                if (containerLifecycleObserverMethod && !parameter.isAnnotationPresent(Observes.class) && !BeanManager.class.equals(parameter.getBaseType())) {
                    throw new DefinitionException(INVALID_INJECTION_POINT, this);
                }
            }
    
        }
    
    

     

    more likely this validation :

     

                // if this is an observer method for container lifecycle event, it must not inject anything besides BeanManager
                if (containerLifecycleObserverMethod && !parameter.isAnnotationPresent(Observes.class) && !BeanManager.class.equals(parameter.getBaseType())) {
                    throw new DefinitionException(INVALID_INJECTION_POINT, this);
                }
    
    

     

    after when I look after the org.infinispan.cdi.InfinispanExtension :

     

    void registerCacheConfigurations(@Observes AfterDeploymentValidation event, CacheManagerEventBridge eventBridge, @Any Instance<EmbeddedCacheManager> cacheManagers, BeanManager beanManager) {
    

     

    definitly, this method is not conform to the cdi observer method compliance.

     

    So, is Infinispan cdi implementation wrong ? or it's the weld implementation that is too strict, or maybe not implemented correctly ?

     

    Thanks for the updates !