1 2 Previous Next 23 Replies Latest reply on Sep 17, 2013 7:33 AM by vijaydaniel

    Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7

    thehashcoder

      Hi EveryOne,

       

      I am very new to OSGi.I am doing a POC for my project. I am able to develop normal OSGi bundles,deploy them on JBoss AS 7 platform, consume other bundle's services etc. But when it comes to the web part I'm stuck. I wanted to create a web app bundle for my POC. I created a normal web app with just one servlet ( with url-mapping /test in web.xml). And below is my MANIFEST file.

       

      Manifest-Version: 1.0
      Bundle-ManifestVersion: 2
      Bundle-ClassPath: .,WEB-INF/classes/
      Bundle-SymbolicName: TestWab
      Export-Package: com.ctl.osgi.servlets
      Web-ContextPath: /TestWab
      Import-Package: org.osgi.framework,javax.servlet,javax.servlet.http

       

       

      But when I hit the URL http://localhost:8080/TestWab/test its giving me a 404 error. I followed the below link when creating the app and I had followed it religiously. Most of the links for OSGi WAB follows the same process.

      link : https://community.jboss.org/message/647106

       

      I have made the following configuration change

       

                <property name="org.osgi.framework.startlevel.beginning">3</property>

       

      Even the fully functional sample application war in the above link produces the same result for me (a 404 error!!). So I believe there is something wrong with configuration/setup rather than code. Could some one please throw some light on this?

       

       

      Thanks in Advance!!

        • 1. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
          bosschaert

          Hi Ranis,

           

          WAB support was provided in AS 7.0 through a variant of pax-web. However shipping this out of the box didn't work out well for everyone, so it was removed from the default configuration from AS 7.1. Setting the start level to 3 only worked in 7.0 as for that start level the org.jboss.osgi.webapp module was defined in the 7.0 standalone.xml.

           

          You can still deploy the webapp support in AS 7.1 how this is done is described here: https://docs.jboss.org/author/display/JBOSGI/Provided+Examples#ProvidedExamples-WebApplication

           

          In the mean time we're replacing the PAX-based WebApplication support with our own native AS7 Web support, you can track the progress for that here: https://issues.jboss.org/browse/AS7-5083

           

          Not sure what AS7 version you were trying this with, but you have a couple of options:

          * You can download 7.0.x and then what you're trying should work by changing the start level to 3.

          * You can take 7.1 and then add WAB support manually by adding capabilities in as described in the JBoss OSGi documentation.

          * You could even build the latest 7.2 stream and try out the native WAB support, however that still isn't implemented fully.

           

          Hope this helps,

           

          David

          1 of 1 people found this helpful
          • 2. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
            thehashcoder

            Hi David,

             

            Thanks a lot for having a look into this. Your answer helped to get some insight into JBoss OSGi stuff. I gave some tries and below are my results.

             

            I added below lines to my standalone.xml

             

                 <capability name="org.ops4j.pax.web:pax-web-jetty-bundle:1.1.2"/>

                 <capability name="org.ops4j.pax.web:pax-web-jsp:1.1.2"/>

                 <capability name="org.ops4j.pax.web:pax-web-extender-war:1.1.2"/>

             

            All the above bundles were deployed in the server, but when I attempted to start the the third bundle it threw me the below exception.

             

             

             

            21:44:23,468 ERROR [stderr] (HttpManagementService-threads - 4) 2012-07-23 21:44:23.468:INFO:oejsh.ContextHandler:stopped HttpServiceContext{httpContext=org.ops4j.pax.web.extender.war.internal.WebAppWebContainerContext@f14aae}

            21:44:23,468 INFO  [org.ops4j.pax.web.service.internal.HttpServiceFactoryImpl] (HttpManagementService-threads - 4) Unbinding bundle: [RanisWAB:0.0.0]

            21:44:23,500 INFO  [org.jboss.osgi.framework] (HttpManagementService-threads - 4) JBOSGI011003: Bundle stopped: org.ops4j.pax.web.pax-web-extender-war:1.1.2

            21:44:35,671 INFO  [org.jboss.osgi.framework] (HttpManagementService-threads - 6) JBOSGI011002: Bundle started: org.ops4j.pax.web.pax-web-extender-war:1.1.2

            21:44:35,671 INFO  [org.ops4j.pax.web.extender.war.internal.WebXmlObserver] (Executor: 1) Using [RanisWAB] as web application context name

            21:44:35,671 INFO  [org.ops4j.pax.web.extender.war.internal.WebXmlObserver] (Executor: 1) Using [] as web application root path

            21:44:35,718 INFO  [org.ops4j.pax.web.service.internal.HttpServiceFactoryImpl] (Executor: 1) Binding bundle: [RanisWAB:0.0.0] to http service

            21:44:35,718 ERROR [stderr] (Executor: 1) 2012-07-23 21:44:35.718:INFO:oejsh.ContextHandler:started HttpServiceContext{httpContext=org.ops4j.pax.web.extender.war.internal.WebAppWebContainerContext@1e2bad0}

            21:44:35,765 WARN  [org.ops4j.pax.web.jsp.internal.JasperClassLoader] (Executor: 1) Exception while calculating location of imported bundles: java.net.MalformedURLException: unknown protocol: javax.servlet.api

                    at java.net.URL.<init>(URL.java:574) [rt.jar:1.6.0_23]

                    at java.net.URL.<init>(URL.java:464) [rt.jar:1.6.0_23]

             

            21:44:35,765 WARN  [org.ops4j.pax.web.jsp.internal.JasperClassLoader] (Executor: 1) Exception while calculating location of imported bundles: java.n

                    at java.net.URL.<init>(URL.java:574) [rt.jar:1.6.0_23]

                    at java.net.URL.<init>(URL.java:464) [rt.jar:1.6.0_23]

                    at java.net.URL.<init>(URL.java:413) [rt.jar:1.6.0_23]

                    at org.ops4j.pax.web.jsp.internal.JasperClassLoader.getLocationsOfBundlesInClassSpace(JasperClassLoader.java:177)

                    at org.ops4j.pax.web.jsp.internal.JasperClassLoader.getClassPathJars(JasperClassLoader.java:157)

                    at org.ops4j.pax.web.jsp.internal.JasperClassLoader.<init>(JasperClassLoader.java:73)

                    at org.ops4j.pax.web.jsp.JspServletWrapper.<init>(JspServletWrapper.java:59)

                    at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerJsps(HttpServiceStarted.java:490)

                    at org.ops4j.pax.web.service.internal.HttpServiceProxy.registerJsps(HttpServiceProxy.java:194)

                    at org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC.visit(RegisterWebAppVisitorWC.java:169)

                    at org.ops4j.pax.web.extender.war.internal.model.WebApp.accept(WebApp.java:590)

                    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$HttpServiceListener.register(WebAppPublisher.java:170)

                    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$HttpServiceListener.serviceChanged(WebAppPublisher.java:155)

                    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$HttpServiceListener.serviceChanged(WebAppPublisher.java:119)

                    at org.ops4j.pax.swissbox.tracker.ReplaceableService.setService(ReplaceableService.java:114)

                    at org.ops4j.pax.swissbox.tracker.ReplaceableService.access$100(ReplaceableService.java:28)

                    at org.ops4j.pax.swissbox.tracker.ReplaceableService$CollectionListener.serviceAdded(ReplaceableService.java:183)

                    at org.ops4j.pax.swissbox.tracker.ServiceCollection$Tracker.addingService(ServiceCollection.java:181)

                    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:896)

                    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)

                    at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:184)

                    at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:339)

                    at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:273)

                    at org.ops4j.pax.swissbox.tracker.ServiceCollection.onStart(ServiceCollection.java:139)

                    at org.ops4j.pax.swissbox.lifecycle.AbstractLifecycle$Stopped.start(AbstractLifecycle.java:121)

                    at org.ops4j.pax.swissbox.lifecycle.AbstractLifecycle.start(AbstractLifecycle.java:49)

                    at org.ops4j.pax.swissbox.tracker.ReplaceableService.onStart(ReplaceableService.java:146)

                    at org.ops4j.pax.swissbox.lifecycle.AbstractLifecycle$Stopped.start(AbstractLifecycle.java:121)

                    at org.ops4j.pax.swissbox.lifecycle.AbstractLifecycle.start(AbstractLifecycle.java:49)

                    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher.publish(WebAppPublisher.java:81)

                    at org.ops4j.pax.web.extender.war.internal.WebXmlObserver.deploy(WebXmlObserver.java:200)

                    at org.ops4j.pax.web.extender.war.internal.WebXmlObserver.addingEntries(WebXmlObserver.java:159)

                    at org.ops4j.pax.swissbox.extender.BundleWatcher$3.run(BundleWatcher.java:224)

                    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [rt.jar:1.6.0_23]

                    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [rt.jar:1.6.0_23]

                    at java.util.concurrent.FutureTask.run(FutureTask.java:138) [rt.jar:1.6.0_23]

                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98) [rt.jar:1.6.0_23]

                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206) [rt.jar:1.6.0_23]

                    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_23]

                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_23]

                    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_23]

             

            I am attaching the screenshot of my OSGi console for your reference (I couldn't find a way here to attach my WAB). It would be of great help if you can throw some light on this.

            osgi-console.jpg

             

             

            Thanks

            Ranis MK

            • 3. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
              thomas.diesler
              21:44:35,765 WARN  [org.ops4j.pax.web.jsp.internal.JasperClassLoader] (Executor: 1) Exception while calculating location of imported bundles: java.n        at java.net.URL.<init>(URL.java:574) [rt.jar:1.6.0_23]
                      at java.net.URL.<init>(URL.java:464) [rt.jar:1.6.0_23]
                      at java.net.URL.<init>(URL.java:413) [rt.jar:1.6.0_23]
                      at org.ops4j.pax.web.jsp.internal.JasperClassLoader.getLocationsOfBundlesInClassSpace(JasperClassLoader.java:177)
              

               

              That would be a silly bug in PaxWeb. Generally, you cannot assume that the bundle location

               

              1. Is a valid URL
              2. If it is a URI that it points to some meaningful location

               

              Intead PaxWeb should obtain the URL for a well known resource entry and work with that.

               

              Anyway, in jboss-as-7.2.0.Alpha1 we have thrown out PaxWeb and replaced that with our own implementation on top on JBossWeb. Your OSGi webapps would get access to the same set of functionality (i.e. security, session fail over, load balancing, ejb/cdi integration, resource injection, etc) as other enterprise webapps that run on AS7

               

              Perhaps you like to give that a try and provide feedback on the latest. You can build 7.2.0.Alpha1-SNAPSHOT from here: https://github.com/jbossas/jboss-as

              • 4. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                thehashcoder

                Hi Thomas,

                 

                     Thanks for the response. We would be using JBoss EAP 6 - ( Org decision). I guess it include AS 7.1. Is there any way to make the WAB work in 7.1 version, with some configuration tweaks? It would be great if you can guide me on this.

                 

                     I am not sure I have done proper configuration changes and installation of neccessary bundles. I have gone through the JBoss' provided examples ( like HTTPService example,WebApp example) but couldn't understand how the code work as a whole project.

                 

                 

                Thanks

                Ranis MK

                • 5. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                  thehashcoder

                  Hi David,

                   

                  I forgot to mention some points in my previous reply.

                   

                  As you guessed I am trying out on AS 7.1. We would be using JBoss EAP 6 which has AS 7.1 (Org decision). So your suggestion to try out AS 7.0/7.2 might not work out.

                   

                   

                  Thanks

                  Ranis MK

                  • 6. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                    thehashcoder

                    Hi,

                     

                    Just adding some more progress.

                     

                    I am now able to start pax-web-extender. I am getting the below messages when I deploy my WAB. But still I'm unable to access the servlet.

                     

                     

                    23:21:55,296 INFO  [org.jboss.osgi.framework] (HttpManagementService-threads - 6) JBOSGI011002: Bundle started: org.ops4j.pax.web.pax-web-extender-war:1.1.2

                    00:12:53,843 INFO  [org.jboss.osgi.framework] (MSC service thread 1-4) JBOSGI011005: Bundle uninstalled: RanisWAB:0.0.0

                    00:12:54,156 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment RanisWAB.war in 329ms

                    00:12:54,281 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018558: Undeployed "RanisWAB.war"

                    00:13:24,375 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "RanisWAB.war"

                    00:13:24,671 INFO  [org.jboss.osgi.framework] (MSC service thread 1-2) JBOSGI011001: Bundle installed: RanisWAB:0.0.0

                    00:13:24,812 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "RanisWAB.war"

                     

                     

                    Do I need to explicitely publish the installed WAB? I saw some examples as such, but I couldn't get the complete example code.

                     

                    Thanks

                    Ranis MK

                    • 7. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                      bosschaert

                      From what I can see, your RanisWAB bundle is installed but not started.

                       

                      In any case, I would recommend you to take a look at the latest AS 7.2 master, as Thomas mentioned, you can build that from here: https://github.com/jbossas/jboss-as

                      This provides native WAB support and although it's not yet fully complete you should be able to do a lot with it. It is the way WABs will be supported going forward.

                       

                      With AS 7.2 you don't need to install Pax or anything else. You can just deploy your WAB and it should work.

                       

                      For a test that shows how this works today, have a look at http://github.com/jbossas/jboss-as/blob/master/testsuite/integration/smoke/src/test/java/org/jboss/as/test/smoke/osgi/SimpleWebAppTestCase.java

                      • 8. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                        bosschaert

                        Ok - I see that you are working from a management decision to use AS 7.1. Let me see if I can get a example that works on that and I'll post it back here.

                        • 9. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                          bosschaert

                          Hi Ranis,

                           

                          I tried this with AS 7.1.2 which I think is the version that is bundled with EAP 6.

                           

                          First of all, I added the following configuration to standalone.xml to enable pax-web:

                          {code}<capability name="org.ops4j.pax.web:pax-web-jetty-bundle:1.1.2" startlevel="1"/>

                          <capability name="org.ops4j.pax.web:pax-web-jsp:1.1.2" startlevel="1"/>

                          <capability name="org.ops4j.pax.web:pax-web-extender-war:1.1.2" startlevel="1"/>{code}

                          Note that I added startlevel="1" to these capabilities to ensure they are started. (I updated the documentation with this too)

                           

                          Now I'm deploying a testwab osgi-demo-wab.jar which I created for a previous post.

                           

                          Next I'm using the CLI to deploy and start my Web Application Bundle:

                          {code}$ bin/jboss-cli.sh -c

                          [standalone@localhost:9999 /] deploy /home/someuser/osgi-demo-wab.jar

                          [standalone@localhost:9999 /] /subsystem=osgi/bundle=osgi-demo-wab.jar:start

                          {"outcome" => "success"}{code}

                           

                          Note that for this specific version of OSGi in AS 7.1.2, you need to start the bundle explicitly either through the CLI as I did here or through the Web Console). This needs to be done regardless of how the bundle was deployed. In newer versions of AS7 the bundle is automatically started if possible.

                           

                          When started, there is an exception on the console, which is the Pax-web bug that you can Thomas identified before (https://community.jboss.org/message/749778#749778) but the web application does work, I can access it from http://localhost:8090/TestWab/DemoServlet (note port 8090):

                           

                          Screen Shot 2012-07-26 at 10.10.21.png

                          Hope this works for you too.

                          • 10. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                            thomas.diesler

                            Here is the compatibility matrix.

                            • 11. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                              thehashcoder

                              Hi David,

                               

                              Thanks a lot for looking into this. That worked for me too.

                               

                              I tried all types of deployment models, even the 'drag and drop' into 'deployments' worked. Only thing we need to do extra is to explicitely start the bundle ( without caring the pax-web exceptions).

                               

                              Thanks

                              Ranis MK

                              • 12. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                                crramirez

                                Hello David,

                                 

                                I am searching in forums and looking for your answers regarding "so it was removed from the default configuration from AS 7.1." and I cannot find where I can download and how to install pax-web for Jboss 7.1. I have downloaded the bundles from pax-web but I don't know how to install them in order to work. I have dropped in deployments folder without result.

                                 

                                Regards,

                                Carlos

                                • 13. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                                  bosschaert

                                  Hi Carlos,

                                   

                                  Depending on the specific version of AS7 that you're using the bundles may need to be explicitly started.

                                  If you're using a capability to deploy the bundles adding the startlevel attribute will start them. If you're using another mechanism to deploy you can start them via the CLI or Web Console. This is described in my earlier reply, here: https://community.jboss.org/message/750403#750403

                                  • 14. Re: Getting 404 when hitting OSGi WAB servlet deployed on JBoss AS7
                                    crramirez

                                    Hello David,

                                     

                                    I have JBoss AS 7.1.1 and after enabling the capabilities:

                                     

                                    In 7.1.1.Final, 7.1.2.Final add these capabilities

                                     

                                    <capability name="org.ops4j.pax.web:pax-web-jetty-bundle:1.1.2" startlevel="1"/>

                                     

                                    <capability name="org.ops4j.pax.web:pax-web-jsp:1.1.2" startlevel="1"/>

                                    <capability name="org.apache.felix:org.apache.felix.webconsole:3.1.8" startlevel="1"/>


                                     

                                     

                                    But I don't know where download the correct jars and how to deploy them. If I put these files in deployment folder jboss complains:

                                     

                                    pax-web-extender-war-1.1.4.jar

                                    pax-web-extender-whiteboard-1.1.4.jar

                                    pax-web-jetty-1.1.4.jar

                                    pax-web-jetty-bundle-1.1.4.jar

                                    pax-web-jsp-1.1.4.jar

                                    pax-web-spi-1.1.4.jar

                                     

                                    So this is my doubt after adding the capabilities what is the next step

                                     

                                    Regards,

                                    Carlos

                                    1 2 Previous Next