Vaadin Application as OSGi WAB on Glassfish 4

Hi all,

in the last few weeks I did a lot of research about running vaadin in an OSGi environment (also read and tried out all the articles I found in the wiki, etc.). As it came out, it is not very straightforward.

Currently I am struggling with a problem I was not able to solve by myself.

I am trying to deploy my application on Glassfish 4 as an OSGi Web Application Bundle. I run into several issues, maybe someone here in the community has some experience and can help me.

I want to deploy the application independent of all the vaadin libs, that are deployed as separate bundles. For that purpose I implemented a bundle listener that looks for vaadin bundles, keeps track of them, and serves their resources if requested.

This approach emerged from the articles I read.


What is important to know:
Glassfish has a special context path for resources and servlets that are registered inside an OSGi bundle (see
http://docs.oracle.com/cd/E18930_01/html/821-2418/gkqff.html
). You can change this, but I want to avoid it if possible.

So I will simply start with my questions here:


1.
If I want my application to be accessible only via a defined url (e.g. http://localhost/osgi/simple), I have to register 2 servlets in my BundleListener, one for all requests to “/simple” and one for all requests to “/VAADIN” for the resources, is this correct? Basically I did it the following way (the resource provider scans all registered vaadin bundles for the requested resource):

MyVaadinServlet vaadinServlet = new MyVaadinServlet(); httpService.registerServlet("/simple", vaadinServlet, null, getResourceProvider()); httpService.registerServlet("/VAADIN", vaadinServlet, null, getResourceProvider()); But then also a simple request to http://localhost/osgi/VAADIN will result in the UI associated with MyVaadinServlet. Is there a way to prevent this? Using some custom servlet e.g. ?


2.
If I restructure the application bundle to a WAB and provide a Web-ContextPath (e.g. /simple), I can access the application using http://localhost/simple. But then, of course, the required resources (e.g. bootStrap.js) are not found, as my bundle does not contain those (as they are in the separate vaadin bundles).

What is the best practice to solve this? Do I simply include all the required resources in my bundle and discard the approach of separate vaadin bundles? Or is it somehow possible to override the requests to use my resource provider?

I did not find out how to do the latter, as the registerServlet-methods from above refer to the prefixed Glassfish “/osgi” urls (so only requests to http://localhost/osgi/VAADIN will be served, no requests to http://localhost/VAADIN).

Would you generally avoid a WAB structure?

Thanks in advance for your help!