users@glassfish.java.net

Re: Can a web service deployed in Grizzly access Felix

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 21 May 2009 22:56:35 +0530

See reply inline...
paulbrickell wrote:
> Sahoo,
>
> I thought about this and you are dead right.
>
> I stopped the thrash and worked to a solution. It wasn't quite the way I
> intended but I did get there. I am pretty certain that all the problems I
> have encountered were of my own making and I really want to thank you,
> Jerome and bhakti for your patience.
>
> So, as payback and for the benefit of future generations here is what I did.
>
> 1. I created a maven project for an OSGi bundle which I package using the
> org.apache.felix/maven-bundle-plugin.
> 2. I played around with the various configuration elements in this plugin
> (in my pom) to import and export the various packages of my bundle and it's
> dependencies.
> 3. I create a BundleActivator class and configured this in the bundle plugin
> configuration as well.
> 4. I put this in the autodeploy-bundle directory of a nightly build
> glassfish v3 deployment and started the server.
>
> This all works exactly how I would expect.
>
> 5. Create a simple web application with a servlet.
> 6. Look up the habitat like this..
> Habitat habitat = (Habitat)
> getServletContext().getAttribute("org.glassfish.servlet.habitat");
> 7. Lookup my service like this...
> MyAPI api = habitat.getByContract(MyAPI.class);
>
> This returned a null reference,
This is expected as per on your explanation below. If you didn't
register the service in OSGi, it wasn't available in Habitat.
> so I did this...
>
> 8. I register my service in my bundle activator's start method thus...
> ctx.registerService(MyAPI.class.getName(), new MyImpl(), new
> Properties());
> 9. Unpacked a clean glass v3 nightly, put my updated bundle in the
> autodeploy-bundles directory and redeployed my web application.
>
> Now it all works.
>
>
> The @Resource injection works for the habitat, I have not tried for MyAPI
> just yet. I did not pesue this course because I am still interested in using
> v3 prelude and @Resource doesn't seem to work in v3 prelude (I will get to
> this in a bit).
>
>
> Things I am still not sure I have right...
>
> 1. The configuration for the maven-bundle-plugin. I have looked at the
> generated manifest, but I cannot be sure it is exactly right. There is an
> entry which looks like it should export MyAPI, but given my experimentation
> I do not believe it gets exported.
>
This should be straight forward. Look at
http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
> 2. I do not know how to deploy a new version of bundle into Glassfish. Just
> dropping a new jar in the autodeploy-bundles directory? Do I need to use the
> asadmin tool to undeploy/deploy? I have tried the first approach (didn't
> seem to work), but not the second. I wouldn't be sure how undeploy.
>
Yes, you can just use cp and rm command to deploy/update and undeploy.
If you overwrite the jar in autodeploy-bundles, it gets updated
immediately. Take a look at
http://weblogs.java.net/blog/ss141213/archive/2009/05/using_filesyste.html.
> 3. I still cannot deploy a web service application to a nightly V3 but that
> problem is for another day.
>
>
>
> OK taking a step back, I was also interested in how I might make this work
> in v3 prelude. I have a project I want to deploy soon and the v3 prelude is
> the only v3 that has support available should my client need it (not decided
> yet). The timescale for this deployment does not lend itself to a wait for
> another supported release.
>
>
I have started to forget what works and what does not work in Prelude. I
am glad you got it working and your approach seems good enough. We have
another release (3.0-Preview) coming up very soon, but I am not sure
about support status of the same. You can ask in a separate thread about it.

Good Luck,
Sahoo
> I did manage to get this working as well, only slightly differently.
>
> 1. I placed my bundle jar in the glassfish/modules directory (could be
> anywhere I suppose)
> 2. I edited the felix/conf/config.properties file. In this file there is a
> section commented with...
>
> # Auto-start osgi-adapter module, which is our management bundle.
> # Also start all its dependencies.
>
> I added the path to my bundle to the bottom of this section. I have not yet
> found another way that activates my bundle at server startup in v3 prelude.
>
> 3. Deployed both a service and servlet based web application and, using the
> web context's looked up the service successfully.
>
>
>
> OK, thats me. I hope my experience helps somebody else. If I find solutions
> to the outstanding issues I will certainly document them here.
>
> Thanks,
> Paul B.
>