Search |
||
OSGi enabled web applications inGlassFishPosted by ss141213 on June 4, 2009 at 3:29 PM PDT
Since the OSGi-fication of GlassFish started, the initial response was very encouraging, but we were often asked as to how we planned to expose the benefits of OSGi platform to end users in a more direct way. We are committed to making this possible as is evident from the following quote from our initial proposal: "If GlassFish can benefit from OSGi, why not applications deployed in GlassFish? Application developers would like to use sophisticated versioning, class loading, dependency management and component model of OSGi. There is a growing demand for servers that expose such facilities to application developers. So, we shall investigate the use of OSGi by applications." I am glad to say that we have made considerable progress in this area. I just now put back a very preliminary implementation of OSGi EEG RFC #66 in GlassFish workspace that allows web applications (war files) to be deployed as OSGi bundles and there by taking advantage of OSGi platform as well as Java EE platform. Web applications and OSGi is a subject which is being actively discussed in OSGi Enterprise Expert Group (EEG) as RFC #66. As I said, what I have put back is just the start. Basic servlet. JSP, JSF, JDBC, JNDI, etc. works. Injection should work, but I have not tried yet. I know for sure JPA does not yet work as JPA classloading requirements conflict with OSGi's. Work is in progress to resolve it - stay tuned. So, how do you use these features in GlassFish? There are basically two starting points: a) You have a plain vanilla war file. b) You have a war file that has OSGi metadata in it. In the former case, you have to somehow instruct the server that it has to add necessary OSGi metadata to the war file. You should also be able to customize the transformation step. It is achieved by use of a special URl protocol called webbundle together with use of URL query parameters. The server has a custom URL handler for this protocol and it does an in place manifest rewrite when it encounters this scheme. To use it, you can do something like this in GlassFish: telnet localhost 6666 install webbundle:file:///tmp/mybundle.war start #bundle_id (telnet support in GlassFish is provided by use of remote shell as described here.) The above commands will make your web app available at localhost:8080/mybundle/. Now you can control the life cycle of the web app via the OSGi bundle. e.g., if you stop the bundle by issuing stop #bundle_id, the web app gets undeployed. To deploy it again, issue the start command. In the latter case, i.e., case #b above, you just have to add a specific meta-data called Web-ContextPath in the manifest.mf to mark the OSGi bundle as a Web Application Bundle, (WAB) in short. Once you have done that, you can either install and start by running the shell commands without using webbundle protocol or simply copy the bundle to glassfish/domains/domain1/autodeploy-bundles/ dir. How this directory works is already described in a previous blog. Although I want to write more now, it's pretty late here. SO, catch you soon with instructions to install the new feature in GlassFish with some concrete example. Thanks. »
Related Topics >>
Java Enterprise Comments
Comments are listed in date ascending order (oldest first)
Submitted by mahsat1 on Fri, 2009-07-31 12:59.
Hi Sahoo,
I am getting the following error when i try to install the war file -
-> install webbundle:file:///tmp/mybundle.war
java.net.MalformedURLException: Unknown protocol: webbundle
Any ideas?
Thanks,
Mahendra.
Submitted by ss141213 on Sat, 2009-08-01 01:29.
Mahendra,
rfc#66 implementation is not "yet" part of GlassFish distribution. I think in the next promoted build, it will be part of distribution. In the meanwhile, you need to download the implementation bundle from http://download.java.net/maven/glassfish/org/glassfish/web/osgi-web-cont... and copy it to autodeploy-bundles directory. No need to restart server. You can then try your example. I explained these steps in the next blog: http://weblogs.java.net/blog/ss141213/archive/2009/06/developing_hybr.html Thanks, Sahoo
Submitted by mahsat1 on Mon, 2009-08-03 09:11.
Hi Sahoo,
Thanks for your reply. I had already deployed the osgi-web-container jar, but I tried redeploying the same and I noticed the following exception in the log file. Also, I can see the bundle in the actice state (Felix remote shell)
[#|2009-08-03T07:57:19.045-0400|INFO|glassfish|null|_ThreadID=15;_ThreadName=Thread-1;|Installed /services/glassfishv3/glassfish/domains/domain1/autodeploy-bundles/osgi-web-container-3.0-SNAPSHOT.jar|#]
[#|2009-08-03T07:57:19.067-0400|SEVERE|glassfish|null|_ThreadID=23;_ThreadName=Thread-1;|Exception in thread "Thread-25" |#]
[#|2009-08-03T07:57:19.068-0400|SEVERE|glassfish|null|_ThreadID=23;_ThreadName=Thread-1;|java.lang.NoSuchMethodError: org.glassfish.api.admin.ServerEnvironment.getStatus()Lorg/glassfish/api/admin/ServerEnvironment$Status;|#]
[#|2009-08-03T07:57:19.069-0400|SEVERE|glassfish|null|_ThreadID=23;_ThreadName=Thread-1;| at org.glassfish.web.osgi.WebExtender.isServerStarted(WebExtender.java:148)|#]
[#|2009-08-03T07:57:19.069-0400|SEVERE|glassfish|null|_ThreadID=23;_ThreadName=Thread-1;| at org.glassfish.web.osgi.WebExtender.access$300(WebExtender.java:66)|#]
[#|2009-08-03T07:57:19.069-0400|SEVERE|glassfish|null|_ThreadID=23;_ThreadName=Thread-1;| at org.glassfish.web.osgi.WebExtender$2.run(WebExtender.java:130)|#]
[#|2009-08-03T07:57:19.070-0400|SEVERE|glassfish|null|_ThreadID=23;_ThreadName=Thread-1;| at java.lang.Thread.run(Thread.java:619)|#]
I would be thankful if you can reply.
Mahendra.
Submitted by ss141213 on Mon, 2009-08-03 21:59.
Mahendra,
That basically means the bundle is not in synch with your glassfish distribution. Which build of GF are you using? If you are using a promoted build, then you need to download corresponding build of osgi-web-container. e.g., let's say you are using b57 of GFv3, then you can download osgi-web-container.jar from http://download.java.net/maven/glassfish/org/glassfish/web/osgi-web-cont... If you go one directory up, you shall find all the versions. You can say why you didn't see a version mismatch exception from OSGi, well, that's a long story and I can't explain our version policy in this comment. Feel free to ask questions at users(at)glassfish.dev.java.net. Sahoo |
||
|
|