7 Replies Latest reply: Mar 30, 2012 4:50 AM by Dejan Stefanovic RSS

Injecting MessageBus into Servlets and EJBs

Dejan Stefanovic Newbie

After managing to run HelloWorld example on JBoss 6.1.0 Final, I am preparing to start integrating Errai into my existing GWT/JEE application.

However, I don't see how i can send messages from some of my application Servlets or EJBs (for example, I want to send certain message from Servlet to GWT application).

I tried message reception in my Servlet and it works fine (annotated as service for certain subject and implemented callback).

However, I want to send message from servlet by trying to inject MessageBuss into it (eclipse says "No bean is eligible for injection to the injection point [JSR-299 §5.2.1]") and then using MessageBuilder to create and send message -  as I see that this is the way

However, obviously there is no injection, since bus instance is null, so I am stucked.

Maybe you can point me to some examples of use of the MessageBuss (I see only use from GWT application or from Service components).

Maybe I missed some Errai concepts, so if I did, please point me to place where I can get better overview of the whole idea behind Errai.

Thanks in advance!

  • 1. Re: Injecting MessageBus into Servlets and EJBs
    Christian Sadilek Master

    Hi Dejan,

     

    In your Servlet, you can get a reference to the ErraiService from the ServletContext. The ErraiService holds a reference to the ServerMessageBus.

     

    ErraiService service = (ErraiService) context.getAttribute("errai");
    MessageBus bus = service.getBus();
    

     

     

    You can then send messages using the server bus as described in the docs.

     

    We do support server side injection of the MessageBus and RequestDispatcher based on Guice. However, this doesn't integrate well if you aim to inject into Servlets or EJBs.

     

    I have created a JIRA to add better support for this in a future release: https://issues.jboss.org/browse/ERRAI-237

  • 2. Re: Injecting MessageBus into Servlets and EJBs
    Christian Sadilek Master

    An update to this: If you have the errai-weld-integration.jar on your classpath and you're using EE6 you should be able to @Inject MessageBus directly, as errai-weld-integration registers the MessageBus.

  • 3. Re: Injecting MessageBus into Servlets and EJBs
    Dejan Stefanovic Newbie

    Christian, thanks for useful response! I managed to post messages from servlet using reference from ServletContext.

    However, I did not manage to get MessageBus injected using weld. What I did for this is that I added dependency in the maven build in jboss6 profile:

     

    <dependency>

        <groupId>org.jboss.errai</groupId>

        <artifactId>errai-weld-integration</artifactId>

        <version>2.0.Beta2</version>

    </dependency>

     

    However, after checking member variable that should be injected:

     

    @Inject

    MessageBus injBuss;

     

    it was still null. Also, during server boot (only when it had my .war in deploy folder) I got bunch of exceptions like this:

     

    23:43:52,578 WARN  [ClassLoaderManager] Unexpected error during load of:com.google.common.base.Equivalences$Impl: java.lang.IncompatibleClassChangeError: Implementing class

        at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_19]

        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) [:1.6.0_19]

        at java.lang.ClassLoader.defineClass(ClassLoader.java:616) [:1.6.0_19]

        at org.jboss.classloader.spi.base.BaseClassLoader.access$200(BaseClassLoader.java:52) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:650) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:609) [jboss-classloader.jar:2.2.1.GA]

        at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_19]

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:608) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:585) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:156) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.filter.FilteredDelegateLoader.doLoadClass(FilteredDelegateLoader.java:141) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:132) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:461) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:262) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:161) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:280) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1172) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:886) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader.doLoadClass(BaseClassLoader.java:505) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:450) [jboss-classloader.jar:2.2.1.GA]

        at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_19]

        at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_19]

        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) [:1.6.0_19]

        at java.lang.ClassLoader.defineClass(ClassLoader.java:616) [:1.6.0_19]

        at org.jboss.classloader.spi.base.BaseClassLoader.access$200(BaseClassLoader.java:52) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:650) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:609) [jboss-classloader.jar:2.2.1.GA]

        at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_19]

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:608) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:585) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:156) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.filter.FilteredDelegateLoader.doLoadClass(FilteredDelegateLoader.java:141) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:132) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:461) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:262) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:161) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:280) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1172) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:886) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader.doLoadClass(BaseClassLoader.java:505) [jboss-classloader.jar:2.2.1.GA]

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:450) [jboss-classloader.jar:2.2.1.GA]

        at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_19]

        at java.lang.Class.forName0(Native Method) [:1.6.0_19]

        at java.lang.Class.forName(Class.java:247) [:1.6.0_19]

        at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl.resolveComplexTypeInfo(IntrospectionTypeInfoFactoryImpl.java:434) [jboss-reflect.jar:2.2.1.SP1]

        at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl.getTypeInfo(IntrospectionTypeInfoFactoryImpl.java:390) [jboss-reflect.jar:2.2.1.SP1]

        at org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory.getTypeInfo(IntrospectionTypeInfoFactory.java:54) [jboss-reflect.jar:2.2.1.SP1]

        at org.jboss.config.plugins.AbstractConfiguration.getTypeInfo(AbstractConfiguration.java:121) [jboss-reflect.jar:2.2.1.SP1]

        at org.jboss.kernel.plugins.config.AbstractKernelConfig.getTypeInfo(AbstractKernelConfig.java:95) [jboss-kernel.jar:2.2.0.SP2]

        at org.jboss.kernel.plugins.config.AbstractKernelConfigurator.getTypeInfo(AbstractKernelConfigurator.java:102) [jboss-kernel.jar:2.2.0.SP2]

        at org.jboss.scanning.plugins.visitor.ConfiguratorReflectProvider.getTypeInfo(ConfiguratorReflectProvider.java:47) [:1.0.0.GA]

        at org.jboss.scanning.plugins.visitor.CachingReflectProvider.getTypeInfo(CachingReflectProvider.java:52) [:1.0.0.GA]

        at org.jboss.scanning.plugins.visitor.ReflectResourceVisitor.getTypeInfo(ReflectResourceVisitor.java:60) [:1.0.0.GA]

        at org.jboss.scanning.plugins.visitor.ReflectResourceVisitor.getClassInfo(ReflectResourceVisitor.java:72) [:1.0.0.GA]

        at org.jboss.scanning.plugins.visitor.ReflectResourceVisitor.doVisit(ReflectResourceVisitor.java:107) [:1.0.0.GA]

        at org.jboss.scanning.plugins.visitor.ReflectResourceVisitor.visit(ReflectResourceVisitor.java:86) [:1.0.0.GA]

        at org.jboss.scanning.hierarchy.plugins.HierarchyIndexScanningPlugin.visit(HierarchyIndexScanningPlugin.java:91) [:1.0.0.GA]

        at org.jboss.scanning.spi.helpers.ScanningPluginWrapper.visit(ScanningPluginWrapper.java:112) [:1.0.0.GA]

        at org.jboss.classloading.plugins.visitor.FederatedResourceVisitor.visit(FederatedResourceVisitor.java:101) [jboss-classloading.jar:2.2.1.GA]

        at org.jboss.classloading.plugins.vfs.VFSResourceVisitor.visit(VFSResourceVisitor.java:264) [jboss-classloading-vfs.jar:2.2.1.GA]

        at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:409) [jboss-vfs.jar:3.0.1.GA]

        at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:411) [jboss-vfs.jar:3.0.1.GA]

        at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:411) [jboss-vfs.jar:3.0.1.GA]

        at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:411) [jboss-vfs.jar:3.0.1.GA]

        at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:411) [jboss-vfs.jar:3.0.1.GA]

        at org.jboss.vfs.VirtualFile.visit(VirtualFile.java:397) [jboss-vfs.jar:3.0.1.GA]

        at org.jboss.classloading.plugins.vfs.VFSResourceVisitor.visit(VFSResourceVisitor.java:102) [jboss-classloading-vfs.jar:2.2.1.GA]

        at org.jboss.deployers.vfs.plugins.classloader.VFSDeploymentClassLoaderPolicyModule.visit(VFSDeploymentClassLoaderPolicyModule.java:181) [:2.2.2.GA]

        at org.jboss.scanning.plugins.DeploymentUnitScanner.scan(DeploymentUnitScanner.java:111) [:1.0.0.GA]

        at org.jboss.scanning.spi.helpers.UrlScanner.scan(UrlScanner.java:96) [:1.0.0.GA]

        at org.jboss.scanning.deployers.ScanningDeployer.deploy(ScanningDeployer.java:95) [:1.0.0.GA]

        at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) [:2.2.2.GA]

        at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1832) [:2.2.2.GA]

        at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1550) [:2.2.2.GA]

        at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1491) [:2.2.2.GA]

        at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.deployers.plugins.deployers.DeployersImpl.change(DeployersImpl.java:1983) [:2.2.2.GA]

        at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:1076) [:2.2.2.GA]

        at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:679) [:2.2.2.GA]

        at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.process(MainDeployerPlugin.java:106) [:6.1.0.Final]

        at org.jboss.profileservice.dependency.ProfileControllerContext$DelegateDeployer.process(ProfileControllerContext.java:143) [:0.2.2]

        at org.jboss.profileservice.dependency.ProfileDeployAction.deploy(ProfileDeployAction.java:151) [:0.2.2]

        at org.jboss.profileservice.dependency.ProfileDeployAction.installActionInternal(ProfileDeployAction.java:94) [:0.2.2]

        at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54) [jboss-kernel.jar:2.2.0.SP2]

        at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42) [jboss-kernel.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654) [jboss-dependency.jar:2.2.0.SP2]

        at org.jboss.profileservice.dependency.ProfileActivationWrapper$BasicProfileActivation.start(ProfileActivationWrapper.java:190) [:0.2.2]

        at org.jboss.profileservice.dependency.ProfileActivationWrapper.start(ProfileActivationWrapper.java:87) [:0.2.2]

        at org.jboss.profileservice.dependency.ProfileActivationService.activateProfile(ProfileActivationService.java:215) [:0.2.2]

        at org.jboss.profileservice.dependency.ProfileActivationService.activate(ProfileActivationService.java:159) [:0.2.2]

        at org.jboss.profileservice.bootstrap.AbstractProfileServiceBootstrap.activate(AbstractProfileServiceBootstrap.java:112) [:0.2.2]

        at org.jboss.profileservice.resolver.BasicResolverFactory$ProfileResolverFacade.deploy(BasicResolverFactory.java:87) [:0.2.2]

        at org.jboss.profileservice.bootstrap.AbstractProfileServiceBootstrap.start(AbstractProfileServiceBootstrap.java:91) [:0.2.2]

        at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:132) [:6.1.0.Final]

        at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56) [:6.1.0.Final]

        at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-6]

        at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-6]

        at java.lang.Thread.run(Thread.java:619) [:1.6.0_19]

     

     

    Any ideas?

  • 4. Re: Injecting MessageBus into Servlets and EJBs
    Christian Sadilek Master

    Are you using javax.inject.Inject there (which you should ) or com.google.inject.Inject?

  • 5. Re: Injecting MessageBus into Servlets and EJBs
    Dejan Stefanovic Newbie

    I use javax.inject.Inject

  • 6. Re: Injecting MessageBus into Servlets and EJBs
    Christian Sadilek Master

    Did you build your project using the bus-quickstart archetype? The cdi-quickstart has a slightly different jboss6 profile. It excludes the google collections from the bus dependency for instance. That would explain the exception you are seeing. Here's a link to the pom.xml of cdi-quickstart: https://github.com/errai/archetypes/blob/master/cdi-quickstart/src/main/resources/archetype-resources/pom.xml

  • 7. Re: Injecting MessageBus into Servlets and EJBs
    Dejan Stefanovic Newbie

    After creating project using bus-quickstart archetype as explained here, it worked perfectly. Thanks!