1 2 3 Previous Next 32 Replies Latest reply on Jun 18, 2013 4:07 PM by lukasw44

    Anyone do osgi web application within jboss as 7?

    yuanqixun

      Hi, anyone do osgi web application within jboss as 7 or give me any resources about it.

      We can see many topic about osgi but not about web applicaion.

        • 1. Re: Anyone do osgi web application within jboss as 7?
          bosschaert

          Hi Yuan,

           

          In you can deploy OSGi Web Application Bundles (WABs) as defined by the OSGi 4.2 Enterprise Specification (chapter 128) in JBoss AS7.

          OSGi-WAB support is not enabled by default, to enable it you need to increase the startlevel of the framework to 3 (for more details see the AS7 OSGi Subsystem Configuration guide).

          To do this, edit the standalone.xml file before you start as7:

          {code:xml}<property name="org.osgi.framework.startlevel.beginning">3</property>{code}

           

          Now you can deploy the attached osgi-demo-wab.jar file to try it out.

           

          In short, a WAB is simply a .war file turned into an OSGi bundle. A WAB has additional metadata in the MANIFEST.MF file, the attached WAB has:

          {code}Bundle-ClassPath: .,WEB-INF/classes/

          Bundle-ManifestVersion: 2

          Bundle-SymbolicName: TestWab

          Export-Package: org.coderthoughts.demo.web.osgi

          Import-Package: org.osgi.framework,javax.servlet,javax.servlet.http

          Web-ContextPath: /TestWab{code}

          Addtionally, you'll notice that the WAB simply has a .jar extension. The OSGi-WAB specifications don't mandate a particular file extension.

           

          The WAB can do whatever a normal .war file can do (e.g. it has a web.xml file like you would find in a .war file), but additionally it can interact with the OSGi Framework through the BundleContext which is available through the ServletContext. The attached DemoServlet.java has the full code, but here's the important bit:

          {code:java}public class DemoServlet extends HttpServlet {

              private BundleContext bundleContext;

           

              @Override

              public void init(ServletConfig config) throws ServletException {

                  super.init(config);

                  bundleContext = (BundleContext) config.getServletContext().getAttribute("osgi-bundlecontext");

              }

           

              @Override

              protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

                  PrintWriter writer = resp.getWriter();

                  writer.print("Using BundleContext looked up in Servlet Context to list available OSGi Bundles:");

                  for (Bundle bundle : bundleContext.getBundles()) {

                      writer.print(bundle.getSymbolicName());

                  }

                  writer.close();

              }

          }

          {code}

          The OSGi BundleContext is obtained from the ServletContext through the standard osgi-bundlecontext attribute.

           

          In your servlet you can use this BundleContext to look up OSGi Services, or, as is done in this example to look to the other bundles in the framework.

           

          When you invoke the servlet on http://localhost:8090/TestWab/DemoServlet the output will look something like this:

          Screen Shot 2011-07-21 at 11.46.54.png

          • 2. Re: Anyone do osgi web application within jboss as 7?
            thomas.diesler

            The current WAB support is limited by whatever pax-web supports. The recommended approach in AS7 is that you develop your webapp as you normally would without OSGi and hence take advantage of scalability, end-to-end security, integration with EJB3, etc.

             

            In AS7 you can then also call into OSGi from the webapp. I demoed this yesterday during our AS7/OSGi webinar.

             

            The code for the demo is here.

             

            I recommend not to go with WAB - instead use WAR + OSGi in AS7

            1 of 1 people found this helpful
            • 3. Re: Anyone do osgi web application within jboss as 7?
              yuanqixun

              Hei,Thomas, thanks for your webinar,but it's not release right now?

              • 4. Re: Anyone do osgi web application within jboss as 7?
                yuanqixun

                And, do you agree with that use war + osgi as the base structure for modular application development, many people think osgi is not fit today's web development. Is it sure?

                • 5. Re: Anyone do osgi web application within jboss as 7?
                  yuanqixun

                  Another question, if I want to architect our web application modular. How to set the web osgi bundle structure? if more than one webapp bundle, there must not be the same web root name!!! And any module should be a web app structure(contain class,jsp,css,js etc.)

                  I just want to many people join into a webapp project's development.

                  • 6. Re: Anyone do osgi web application within jboss as 7?
                    thomas.diesler

                    many people think osgi is not fit today's web development. Is it sure?

                     

                    This is an opinion and as such might not be generally true for everybody.

                     

                    Traditionally the appserver is the provider of middleware services. Persistence, transactionality, security, scalability, fail-over, etc. is the job of AS7.  I recommend, in the spirit of Open Choice, to mix the two worlds and apply the OSGi technology only to the functional areas where you need OSGi functionality. IMHO, it is not feasible to expect high quality middleware services to show up as OSGi bundles somehow, such that they can run in a vendor independent fashion on a pure OSGi runtime. For example, the question of end-to-end security from the web to the persistence layer is simply not addressed at Enterprise OSGi spec level. Even if it gets addressed at some point in the future, functionality will always lack behind what is available today in the appserver.  Going "pure OSGi" is only a good idea if you can be certain that pure OSGi runtimes provide the functionality that you need.

                     

                    if I want to architect our web application modular. How to set the web osgi bundle structure?

                     

                    I believe it's good to make a consious desicion where OSGi is applicable and where not. Don't use OSGi for the sake of using OSGi. If you need to design a webapp - design a webapp. If your webapp has the notion of plugins, it would be possible to model these as OSGi services. In that way 3rd party can contribute plugins in a non-conflicting way - class space consistency is maintained at the OSGi level. 

                     

                    You may want to think like this:

                     

                    #1 Disconnected teams provide functionality in a more or less uncoordinated fashion. They can however define their (package) capabilities and requirements. I need a seperate piece that finds a consistent solution for the dependency graph.

                     

                    #2 My app supports the notion of dynamic services. The set of services is not fixed or services may come and go. I need a seperate piece that maintains the services and notifies clients of changes in the set.

                     

                    #3 My app supports the notion of hot fixes. I want to update functionality without taking the app down.

                     

                    In any of these cases OSGi is well applied. The last point may be a false promise however. As you know Java does not have the notion class unload, so if there is a reference to an old class it will continue to get used until all packages are refreshed. With AS7 bootstrap time in the order of seconds it might be easier to restart the server instead of dealing with the additional update complexities.

                     

                    Things should be as simple as possible, but not simpler - A. Einstein

                    • 7. Re: Anyone do osgi web application within jboss as 7?
                      bmsantos

                      David,

                       

                      Sorry to revive this thread, but I have the following question... in JBoss AS 7, how can I make the DemoServlet work with Servlet 3.0 annotations? I've tried this, but it does not work. The JBoss OSGi deployment interceptor is expecting a web.xml, which is not required with WebServlet 3.0 specs.

                       

                      Caused by: org.jboss.osgi.deployment.interceptor.LifecycleInterceptorException: Cannot obtain web.xml from: vfs:

                       

                      Am I missing something here or WebServlet 3.0 is not yet supported in JBoss AS 7 WABs?

                       

                      Thanks,

                      • 8. Re: Anyone do osgi web application within jboss as 7?
                        thomas.diesler

                        Please monitor https://issues.jboss.org/browse/JBOSGI-491

                         

                        WAB support is currently provided by Pax-Web. We are however moving towards a JBossWeb based implementation. By that time (at the latest) servlet 3.x support should become available.

                         

                        If you don't like the interceptor approach, you can remove jbosgi-webapp and install the pax bundles directly.

                        • 9. Re: Anyone do osgi web application within jboss as 7?
                          bmsantos

                          Thomas,

                           

                          Thanks! That explains it.

                           

                          I was not aware that OSGi Http Service was being provided by Pax-Web/Jetty. Will be much nicer when we get the feature rich JBossWeb based implemetation.

                           

                          Thanks,

                          B.

                          • 10. Re: Anyone do osgi web application within jboss as 7?
                            m.wuestemann

                            Hi,

                             

                            i watched you webinar demo.

                             

                            Now i tryed to get your code in my eclipse by following your README in the /eclipse folder.

                             

                            After importing i got following Error:

                             

                            DescriptionResourcePathLocationType
                            Project build error: Non-resolvable parent POM for org.jboss.osgi:jboss-osgi:1.0.1-SNAPSHOT: Failure to transfer org.jboss.osgi:jboss-osgi-parent:pom:1.0.10 from http://repository.jboss.org/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of jboss-public-repository-group has elapsed or updates are forced. Original error: Could not transfer artifact org.jboss.osgi:jboss-osgi-parent:pom:1.0.10 from/to jboss-public-repository-group (http://repository.jboss.org/nexus/content/groups/public/): Network is unreachable: no further information to http://repository.jboss.org/nexus/content/groups/public/org/jboss/osgi/jboss-osgi-parent/1.0.10/jboss-osgi-parent-1.0.10.pom and 'parent.relativePath' points at wrong local POMpom.xml/jboss-osgi-distributionline 1Maven pom Loading Problem

                             

                            Can someone help me ?

                             

                            Thanks

                            • 12. Re: Anyone do osgi web application within jboss as 7?
                              white_sox

                              Hello and thank you for your post,

                               

                               

                               

                              I deployed your bundle osgi-demo-wab.jar to jboss-as-7.1.1.Final but I cannot access the servlet (404).

                              These are the lines from the logs:

                               

                              17:51:30,699 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "osgi-demo-wab.jar"

                              .....

                              17:51:31,137 INFO  [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-3) Bundle started: TestWab:0.0.0

                               

                               

                              Do you have any idea about he configuration that I'm missing ?

                               

                              Thank you.

                              • 13. Re: Anyone do osgi web application within jboss as 7?
                                eran_kazula

                                Hello Thomas,

                                 

                                It seems that the link that was previously provided to the demo code is broken.

                                 

                                So referring to your recommendation to "use WAR + OSGi in AS7", can you please provide another link to the WebApp demo code or explain how to "call into OSGi from the webapp"?

                                 

                                Thank you!

                                 

                                Eran.

                                • 14. Re: Anyone do osgi web application within jboss as 7?
                                  bmsantos

                                  Eran,

                                   

                                  Try the following link:

                                   

                                  I haven't check it since JBoss 7.0 but I'm assuming that there aren't that many differences and that JBoss 7.1 is still using Pax-Web for WABs.

                                   

                                  http://riaconnection.wordpress.com/2011/08/06/deploying-a-war-as-a-jboss-as-7-osgi-wab/

                                   

                                  Later,

                                  Bruno

                                  1 2 3 Previous Next