Differences
This shows you the differences between two versions of the page.
vaadin_7.4_osgi_web_application [2017/08/24 10:35] |
vaadin_7.4_osgi_web_application [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Vaadin 7.4 OSGi Web Application ====== | ||
+ | <note important> | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | |||
+ | ===== OSGi Web Application Packaging ===== | ||
+ | OSGi Web Applications are called WAB ⇒ **W**eb **A**pplication **B**undle. Same as a bundle is just a jar file with an extended manifest file the same goes for the WAB. A web application bundle is just a WAR file with an extended manifest. | ||
+ | |||
+ | |||
+ | ===== Demo Vaadin 7 OSGi Web Applicaton ===== | ||
+ | The demo application is a stripped barebone Vaadin application. It uses the default widgetset and the default Vaadin Reindeer theme. | ||
+ | |||
+ | It is derived from the Vaadin application maven archetype and just shows a button which will display a message on click. | ||
+ | |||
+ | |||
+ | ===== Development ===== | ||
+ | Maven and the Maven Bundle Plugin (and some other plugins) are used for development. | ||
+ | |||
+ | ==== Application Code ==== | ||
+ | To get the application code from the source code repository just clone it with hg (Mercurial): | ||
+ | |||
+ | hg clone http:// | ||
+ | |||
+ | === VaadinServlet === | ||
+ | The VaadinServlet class is used to register the web application at the servlet container. Due to a classpath problem a class extending VaadinServlet must be created so that the bundle can resolve all needed classes. | ||
+ | |||
+ | <sxh java title=OsgiVaadinServlet> | ||
+ | public class OsgiVaadinServlet extends VaadinServlet { | ||
+ | |||
+ | @Override | ||
+ | protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) | ||
+ | throws ServiceException { | ||
+ | |||
+ | VaadinServletService service = new VaadinServletService(this, | ||
+ | |||
+ | @Override | ||
+ | public ClassLoader getClassLoader() { | ||
+ | return OsgiVaadinServlet.class.getClassLoader(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected List< | ||
+ | ClassLoader actual = Thread.currentThread().getContextClassLoader(); | ||
+ | try { | ||
+ | Thread.currentThread().setContextClassLoader(DefaultBroadcaster.class.getClassLoader()); | ||
+ | return super.createRequestHandlers(); | ||
+ | } | ||
+ | finally { | ||
+ | Thread.currentThread().setContextClassLoader(actual); | ||
+ | } | ||
+ | } | ||
+ | }; | ||
+ | | ||
+ | service.init(); | ||
+ | | ||
+ | return service; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === web.xml === | ||
+ | The registration of the servlet is done via the //web.xml// file (annotations didn't work). | ||
+ | |||
+ | <sxh xml> | ||
+ | <?xml version=" | ||
+ | <web-app xmlns=" | ||
+ | xsi: | ||
+ | http:// | ||
+ | version=" | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | === Maven Bundle Plugin === | ||
+ | The Maven Bundle Plugin takes care of all things related to the building of a bundle with the needed entries in the manifest file. Just add it to the pom.xml. | ||
+ | |||
+ | <sxh xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | <!-- Read all OSGi configuration info from this optional file --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | === MANIFEST.MF === | ||
+ | The MANIFEST.MF file contains the information about the bundle or WAB. By default the MANIFEST.MF generated by the maven-bundle-plugin is located under '' | ||
+ | |||
+ | <sxh xml> | ||
+ | < | ||
+ | <!-- Need to use this plugin to build war files --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <!-- add bundle plugin generated manifest to the war --> | ||
+ | < | ||
+ | ${project.build.outputDirectory}/ | ||
+ | </ | ||
+ | <!-- Adding Bundle-ClassPath in maven-bundle-plugin confuses that plugin | ||
+ | and it generates wrong Import-Package, | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | <!-- We don't always have a web.xml --> | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== vaadinbootstrap.js ==== | ||
+ | The file // | ||
+ | |||
+ | ==== Classpath ==== | ||
+ | Vaadin expects some things to be on the classpath of the application, | ||
+ | |||
+ | Bundle-ClassPath: | ||
+ | | ||
+ | ===== Building ===== | ||
+ | Building the web application bundle with maven is no more than doing a | ||
+ | |||
+ | mvn clean package | ||
+ | |||
+ | The " | ||
+ | |||
+ | ===== Deployment ===== | ||
+ | |||
+ | ==== Apache Karaf ==== | ||
+ | For the testing purpose I am using Apache Karaf 3.0.3 which is the latest stable version of Apache Karaf at the moment of writing and can be downloaded from the Apache Karaf website. | ||
+ | |||
+ | Karaf is a very easy to manage OSGi container. Just unpack the archive and start it with | ||
+ | |||
+ | bin/karaf | ||
+ | |||
+ | The bundles can be dumped into the deploy folder which will automatically start the bundles. | ||
+ | |||
+ | === Installing Prerequisites === | ||
+ | |||
+ | The //war// feature need to be installed with the command | ||
+ | |||
+ | feature: | ||
+ | | ||
+ | Now drop all the dependencies into the deploy folder and you are ready to proceed. | ||
+ | |||
+ | === Installing Vaadin === | ||
+ | Sadly not all libraries delivered with the Vaadin All-In-One archive are provided with a valid OSGi manifest header. But for most use cases a subset of libraries is sufficient enough. For this demo only the following libraries are needed: | ||
+ | | ||
+ | * flute-1.3.0.gg2.jar | ||
+ | * atmosphere-runtime-2.2.4.vaadin2.jar | ||
+ | * org.apache.commons.beanutils-1.8.3.jar | ||
+ | * org.apache.commons.codec-1.8.0.jar | ||
+ | * org.apache.commons-collections-3.2.1.jar | ||
+ | * org.apache.commons.io-2.4.0.jar | ||
+ | * org.apache.commons.lang3-3.1.0.jar | ||
+ | * vaadin-slf4j-jdk14-1.6.1.jar | ||
+ | * jsoup-1.8.1.jar | ||
+ | * guava-16.0.1.vaadin1.jar | ||
+ | * streamhtmlparser-jsilver-0.0.10.vaadin1.jar | ||
+ | * vaadin-shared-7.4.4.jar | ||
+ | * vaadin-server-7.4.4.jar | ||
+ | * vaadin-client-7.4.4.jar | ||
+ | |||
+ | <note tip>Some of the libraries in the Vaadin archive have no OSGi manifest header entries, check for Bundle-* entries. OSGi versions of these libraries can be downloaded here (TODO) or from the [[http:// | ||
+ | |||
+ | === Installing Demo === | ||
+ | Just copy the test.vaadin-x.x.x.war to the deploy folder and you are done. The web application is available under the path which is specified in the manifest with the // | ||
+ | |||
+ | So point the browser to '' | ||
+ | === Checking the web application === | ||
+ | Apache Karaf uses Jetty as its HTTP server. By default it uses the port 8181. You can check this by either pointing your browser to http:// | ||
+ | |||
+ | netstat -an | grep 8181 | ||
+ | | ||
+ | A good place to start looking for your application is always the log, see karaf/ | ||
+ | |||
+ | Another nice method is by using the Apache Felix Webconsole. You can install it with '' | ||
+ | |||
+ | |||
+ | ===== Stylesheet Compiling ===== | ||
+ | If a CSS style is used or one of the predefined styles then everything is alright and should work. But if you are using your own style (or extending an existing one) then normally Vaadin would compile it on the fly during the first call of the servlet. But that ends in a nice error message. | ||
+ | |||
+ | java.lang.NoClassDefFoundError: | ||
+ | | ||
+ | But the Book of Vaadin explains nicely how to compile the stylesheet before the deployment. | ||
+ | |||
+ | For myself the easiest way was to manually compile it with the following command | ||
+ | |||
+ | java -cp "/ | ||
+ | |||
+ | | ||
+ | ===== Open Questions ===== | ||
+ | The Vaadin Push support has been tested in this setup. It may need some additional classes which has to be available on the bundle classpath. | ||
+ | |||
+ | |||
+ | ===== Source Code ===== | ||
+ | * {{:: | ||
+ | * [[https:// | ||
+ | |||
+ | |||
+ | ===== Links ===== | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | |||
+ | {{tag> |