1 2 Previous Next 19 Replies Latest reply on Jan 17, 2013 6:43 PM by xudong4713

    Accessing EJB classes from an OSGi Bundle

    jdoble

      There are lots of examples showing how to access an OSGi bundle from an ESB, but I am wanting to do the reverse. Specifically, I have a EJB jar, deployed within an EAR in the AS7.1 standalone/deployments folder, and I have an OSGi bundle, also deployed in the standalone/deployments folder, and I want the OSGi bundle to be able to access classes defined in the EJB jar.

       

      I am thinking that my problem is that I don't know how to indicate to the OSGi world what package(s) the EJB jar should export. Can anyone provide an explanation or point me to an example that would work for AS 7.1?

        • 1. Re: Accessing EJB classes from an OSGi Bundle
          thomas.diesler

          Deployments are registered with the OSGi Layer by default. Have a look at the server DEBUG log. It should tell you the identity of the EJB deployment in the OSGi layer and its exported (package) capabilities. From the OSGi perspective it should be sufficient to define the Package-Import

           

          Here is a general BundleAccessesModuleServiceTestCase

          • 2. Re: Accessing EJB classes from an OSGi Bundle
            xudong4713

            i have the same issue. and Thomas's answer is vague to me. plus the link to BundleAccessesModuleServiceTestCase does not work. could someone provide an example? thanks in advance.

            • 3. Re: Accessing EJB classes from an OSGi Bundle
              thomas.diesler

              The OSGi testsuite has moved to https://github.com/jbossas/jboss-as/tree/master/testsuite/integration/osgi

               

              Have a look at

               

              StatelessBeanTestCase


              BundleAccessesModuleServiceTestCase

               

              I'd like to discuss this in the context of the upcomming 7.2.0.Alpha1 (i.e. current master)

               


              • 4. Re: Accessing EJB classes from an OSGi Bundle
                xudong4713

                Whatever I do I get this error when JBoss AS is trying to start bundle2ejb:

                 

                Caused by: org.jboss.osgi.resolver.XResolverException: Unable to resolve Module[bundle2ejb:1.0.0]: missing requirement [Module[bundle2ejb:1.0.0]] package; (package=com.xxx.ejb)

                 

                where bundle2ejb is an OSGi bundle invoking an ejb, which is in package com.xxx.ejb.

                 

                Import is specified in the pom.xml:

                <Import-Package>com.xxx.ejb,… </Import-Package>

                 

                And the ejb is deployed in a regular war/jar, not a WAB. The JBoss AS version I use is jboss-as-7.1.1.Final.

                 

                Any hint? WAB is the way to go? Or use AS 7.2 instead?

                 

                Thanks

                • 5. Re: Accessing EJB classes from an OSGi Bundle
                  thomas.diesler

                  I can support you using the latest from master (i.e. 7.2.0.Alpha1-SNAPSHOT)

                  • 6. Re: Accessing EJB classes from an OSGi Bundle
                    xudong4713

                    I built the jboss-as 7.2.0.Alpha1-SNAPSHOT from the latest code and the previous problem went away. Thank you Thomas.

                     

                    However I got another problem, I cannot deploy a package that invokes an osgi bundle. The same code works on AS 7.1. Here is the error:

                     

                    INFO  [org.jboss.as.server] (management-handler-thread - 5) JBAS015870: Deploy of deployment "osgi-servlet.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" =>

                    ["jboss.deployment.unit.\"osgi-servlet.war\".FIRST_MODULE_USE Missing[JBAS014861: <one or more transitive dependencies>]","jboss.module.service.\"deployment.osgi-servlet.war\".main Missing[jboss.module.spec.service.\"deployment.osgi-bundle2ejb\".\"1.0.0.SNAPSHOT\"]"]}

                     

                    Here is my manifest line:

                     

                    Dependencies: org.osgi.core,org.jboss.modules,deployment.osgi-bundle2e

                    jb:1.0.0.SNAPSHOT

                     

                    osgi-bundle2ejb:1.0.0.SNAPSHOT is deployed and started as shown in the jboss console. And I didn’t change the standalone.xml file as I did for AS 7.1.

                     

                    Thanks.

                    • 7. Re: Accessing EJB classes from an OSGi Bundle
                      thomas.diesler

                      The current master also supports OSGi metadata in webapps. You should  be able to simply import your package to the war (as you normally would with a bundle).

                       

                      The compatibility issue that you are seeing is https://issues.jboss.org/browse/AS7-5593

                      I'm still pondering whether/how I should actually do that as it would introduce an additional unique constraint.

                      • 8. Re: Accessing EJB classes from an OSGi Bundle
                        xudong4713

                        I thought setting the dependencies in the manifest file was the normal way of importing a bundle. I’m not aware of another “normal” way. Kindly please advise.

                         

                        This is how I do it in maven pom file but it does not work with AS 7.2:

                         

                        <plugin>

                            <groupId>org.apache.maven.plugins</groupId>

                            <artifactId>maven-war-plugin</artifactId>

                            <configuration>

                                <archive>

                                    <manifestEntries>

                                        <Dependencies>

                                            org.osgi.core,org.jboss.modules,deployment.osgi-bundle2ejb:1.0.0.SNAPSHOT

                                        </Dependencies>

                                    </manifestEntries>

                                </archive>

                            </configuration>

                        </plugin>

                        • 9. Re: Accessing EJB classes from an OSGi Bundle
                          thomas.diesler

                          The normal/standard way is to use OSGi. What you are doing above is

                           

                          #1 Proprietary to JBossAS and hance not portable

                          #2 Not good modular practise

                           

                          If you change osgi-bundle2ejb you'll also break your WAR.

                           

                          I'm suggesting to make your webapp an OSGi bundle and use the standard Package-Import header.

                          • 10. Re: Accessing EJB classes from an OSGi Bundle
                            xudong4713

                            I transformed both of my EJB module and servlet module to WABs but cannot get them work together. I wished I could take advantage of JBoss OSGi for my web application but it appears that it’s not ready for prime time yet. It might be just lack of documentation. I’m gonna try Apache Felix/Aries.

                             

                            Thank you Thomas for your help.

                            • 11. Re: Accessing EJB classes from an OSGi Bundle
                              thomas.diesler

                              In our samples and test cases we show that it works. If there are holes I'd like to understand what they are.

                              • 12. Re: Accessing EJB classes from an OSGi Bundle
                                xudong4713

                                Is there a way to send my code over? I didn't see any way to attach a file here.

                                 

                                Due to large number of EJBs in my current web application I want to make sure OSGi bundles work seamlessly with EJBs. I have created an OSGi bundle to call an EJB, which is in a separate WAB, and another WAB with a servlet to invoke the bundle. With AS 7.2 I can deploy the EJB WAB and the bundle successfully, but failed to deploy the servlet WAB, which complains about a missing class. What’s interesting is that the missing class is in the EJB class and isn’t referenced by the servlet at all.

                                 

                                Regarding documentation, I have only seen the test cases and one quick start example on bundle. The test cases are inspiring but the real (non-test) code seems to be different from the test code. I wish there were more real (non-test) examples in different scenarios, such as bundle, ejb, web service, regular code, servlet invoking each other. Another thing I would like to point out is that I struggled a lot with maven pom setup, so I would like to see the examples with pom files.

                                 

                                Thanks much Thomas.

                                • 13. Re: Accessing EJB classes from an OSGi Bundle
                                  thomas.diesler

                                  You can have a look at https://github.com/jbossas/jboss-as/tree/master/testsuite/integration/osgi

                                   

                                  There you get a pom and and a large number of javaee/osgi integration tests

                                   

                                  Running org.jboss.as.test.integration.osgi.deployment.ServerDeploymentTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 24.022 sec

                                  Running org.jboss.as.test.integration.osgi.deployment.BundleDeploymentCaseTwoTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.527 sec

                                  Running org.jboss.as.test.integration.osgi.deployment.LegacyBundleTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.57 sec

                                  Running org.jboss.as.test.integration.osgi.deployment.DeploymentMarkerTestCase

                                  Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.937 sec

                                  Running org.jboss.as.test.integration.osgi.deployment.BundleDeploymentCaseOneTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.198 sec

                                  Running org.jboss.as.test.integration.osgi.deployment.ArquillianDeployerTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.955 sec

                                  Running org.jboss.as.test.integration.osgi.deployment.DeferredResolveTestCase

                                  Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 9.943 sec

                                  Running org.jboss.as.test.integration.osgi.deployment.BundleReplaceTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.832 sec

                                  Running org.jboss.as.test.integration.osgi.http.HttpServiceTestCase

                                  Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.615 sec

                                  Running org.jboss.as.test.integration.osgi.resource.ResourceInjectionTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.818 sec

                                  Running org.jboss.as.test.integration.osgi.resource.BundleContextInjectionTestCase

                                  Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.208 sec

                                  Running org.jboss.as.test.integration.osgi.ear.EnterpriseArchiveTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.499 sec

                                  Running org.jboss.as.test.integration.osgi.ear.CollectionsEnterpriseArchiveTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.48 sec

                                  Running org.jboss.as.test.integration.osgi.stilts.StompletTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.665 sec

                                  Running org.jboss.as.test.integration.osgi.jaxb.XMLBindingTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.846 sec

                                  Running org.jboss.as.test.integration.osgi.jaxws.WebServiceEndpointTestCase

                                  Tests run: 6, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 8.57 sec

                                  Running org.jboss.as.test.integration.osgi.jaxws.WebServiceClientTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.402 sec

                                  Running org.jboss.as.test.integration.osgi.jaxp.SAXParserTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.494 sec

                                  Running org.jboss.as.test.integration.osgi.jaxp.DocumentBuilderTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.474 sec

                                  Running org.jboss.as.test.integration.osgi.jaxp.XPathFactoryTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.58 sec

                                  Running org.jboss.as.test.integration.osgi.jndi.JNDITestCase

                                  Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.523 sec

                                  Running org.jboss.as.test.integration.osgi.classloading.OptionalImportTestCase

                                  Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.684 sec

                                  Running org.jboss.as.test.integration.osgi.classloading.LogServiceDynamicImportTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.846 sec

                                  Running org.jboss.as.test.integration.osgi.classloading.ModuleRegistrationTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.458 sec

                                  Running org.jboss.as.test.integration.osgi.classloading.BundleNestedInWarTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.521 sec

                                  Running org.jboss.as.test.integration.osgi.classloading.LogServiceStaticImportTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.844 sec

                                  Running org.jboss.as.test.integration.osgi.classloading.BundleNestedInEarTestCase

                                  Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.196 sec

                                  Running org.jboss.as.test.integration.osgi.classloading.SystemPackagesTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.497 sec

                                  Running org.jboss.as.test.integration.osgi.classloading.VersionRangeImportTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.072 sec

                                  Running org.jboss.as.test.integration.osgi.configadmin.ConfigAdminTestCase

                                  Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.721 sec

                                  Running org.jboss.as.test.integration.osgi.configadmin.ConfigAdminIntegrationTestCase

                                  Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.2 sec

                                  Running org.jboss.as.test.integration.osgi.configadmin.ConfigurationAdminTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.651 sec

                                  Running org.jboss.as.test.integration.osgi.repository.RepositoryTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.99 sec

                                  Running org.jboss.as.test.integration.osgi.jaxrs.RestEndpointTestCase

                                  Tests run: 6, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 6.736 sec

                                  Running org.jboss.as.test.integration.osgi.cdi.ManagedBeansTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.871 sec

                                  Running org.jboss.as.test.integration.osgi.jta.TransactionTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.479 sec

                                  Running org.jboss.as.test.integration.osgi.core.PackageAdminTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.43 sec

                                  Running org.jboss.as.test.integration.osgi.core.StartLevelTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.879 sec

                                  Running org.jboss.as.test.integration.osgi.core.BundleLifecycleTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.427 sec

                                  Running org.jboss.as.test.integration.osgi.jpa.PersistenceTestCase

                                  Tests run: 3, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 3.849 sec

                                  Running org.jboss.as.test.integration.osgi.ejb3.client.EJBClientDescriptorTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.323 sec

                                  Running org.jboss.as.test.integration.osgi.ejb3.EjbBindingsTestCase

                                  Tests run: 3, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 1.788 sec

                                  Running org.jboss.as.test.integration.osgi.ejb3.StatelessBeanTestCase

                                  Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.926 sec

                                  Running org.jboss.as.test.integration.osgi.management.FrameworkManagementTestCase

                                  Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.064 sec

                                  Running org.jboss.as.test.integration.osgi.webapp.WebAppTestCase

                                  Tests run: 8, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 7.831 sec

                                  Running org.jboss.as.test.integration.osgi.webapp.WebAppSpecTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.425 sec

                                  Running org.jboss.as.test.integration.osgi.xservice.ModuleAccessesBundleServiceTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.464 sec

                                  Running org.jboss.as.test.integration.osgi.xservice.BundleAccessesModuleServiceTestCase

                                  Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.229 sec

                                   

                                  Results :

                                   

                                  Tests run: 114, Failures: 0, Errors: 0, Skipped: 5

                                  • 14. Re: Accessing EJB classes from an OSGi Bundle
                                    jrantav

                                    X Chen wrote:

                                     

                                    Regarding documentation, I have only seen the test cases and one quick start example on bundle. The test cases are inspiring but the real (non-test) code seems to be different from the test code. I wish there were more real (non-test) examples in different scenarios, such as bundle, ejb, web service, regular code, servlet invoking each other. Another thing I would like to point out is that I struggled a lot with maven pom setup, so I would like to see the examples with pom files.

                                     

                                    Fully agreeing with this. Test cases don't create for example the manifests for investigation, or any deployment artifacts you can actually test yourself (experimenting the deployment etc). This is the reason I started to make my own repo of examples, because equivalent just doesn't seem to exist.

                                     

                                    A pom made just for unit tests is something fundamentally different from a pom made for build artifacts. There is a lot of stuff that you need to add, and good examples of it would help a lot.

                                     

                                    Of course, I appreciate the test cases as well, but they're just not the same thing.

                                    1 2 Previous Next