More Related Content Similar to Migration of Existing Web Applications to OSGi at Eclipse Summit Europe 2010 (20) Migration of Existing Web Applications to OSGi at Eclipse Summit Europe 20102. © SAP AG 2010. All rights reserved. / Page 2 Public
Agenda
1. OSGi Web Container
2. Migrating Existing Web Applications to OSGi
3. Challenges That We Overcome
4. Conclusions
3. © SAP AG 2010. All rights reserved. / Page 3 Public
Why web applications on OSGi?
Last years trends of software development
A good choice for product evolving
Encapsulated modules
Versioning
Class space isolation
Declarative dependencies
Dynamic refreshing and updating
Ongoing work to make OSGi platform more appealing to the enterprise
world
Eclipse Gemini – Enterprise Modules project
Eclipse Virgo – Dynamic Enterprise Application Platform project
4. © SAP AG 2010. All rights reserved. / Page 4 Public
OSGi Web Container
Based on Web Application Specification part of OSGi Enterprise
Specification
Provides support for Web Applications written to
Servlet 2.5 or later
JSP 2.1 or later
Java EE OSGi
WAR
5. © SAP AG 2010. All rights reserved. / Page 5 Public
Available OSGi specific features
Main Features in OSGi Web Container
Installation of WAR files
Installation of Web Application Bundles (WABs)
Control of configuration properties using URL parameters
Multiple applications with single context path
Web application lifecycle managed by OSGi bundle lifecycle
Facilitates interoperability between web application with other OSGi
components
Modularization – one big blob WAR to be broken into smaller modules
Dynamic deployment, and fast update of individual modules
6. © SAP AG 2010. All rights reserved. / Page 6 Public
Agenda
1. OSGi Web Container
2. Migrating Existing Web Applications to OSGi
3. Challenges That We Overcome
4. Conclusions
7. © SAP AG 2010. All rights reserved. / Page 7 Public
Migrating Web Applications to OSGi
• deploying standard WAR
• removing JAR files from WAR and declaring dependencies on
corresponding OSGi bundles
• separating web artifacts from services they depend on
Web Application
WAR
Services
CatalogService
PaymentService
Libraries
Resources
Images CSS
Spring
Hibernate
Services
CatalogService
PaymentService
How to modify the Web application in order to benefit from OSGi?
8. © SAP AG 2010. All rights reserved. / Page 8 Public
Agenda
1. OSGi Web Container
2. Migrating Existing Web Applications to OSGi
3. Challenges That We Overcome
4. Conclusions
9. © SAP AG 2010. All rights reserved. / Page 9 Public
Certain APIs and JARs are missing
Web application assumes that Java EE environment provides a certain API
or JARs in the classpath
In OSGi environment:
Manifest – single management point for the bundle
Export-Package
Import-Package
Require-Bundle
Do not rely on automated add for standard Java EE packages
Manual scan and update import packages for required ones
Or use tools like BND, Eclipse PDE, Bundlor STS
Be careful with
org.osgi.framework.bootdelagation
osgi.compatibility.bootdelagation (Eclipse Equinox specific)
10. © SAP AG 2010. All rights reserved. / Page 10 Public
Support for context.xml
Context.xml is widely adopted by web applications used to run on Tomcat
Support for web application context configuration was contributed to
Gemini Web
The configuration files are located as follow:
$SERVER_HOME/config/context.xml is the default context configuration file for all
web applications.
$SERVER_HOME/config/[enginename]/[hostname] directory contains:
o The default context configuration for all web applications of a given virtual host.
o Individual web applications’ context configuration files.
[enginename] is the name of Tomcat’s engine (“Catalina” by default) and [hostname]
names a virtual host, both of which are configured in tomcat-server.xml.
Note that the following context configuration features are not supported in Gemini Web:
• Custom class loaders.
• Specifying the context path. This is specified using the Web-ContextPath header in web
application’s MANIFEST.MF file.
• Specifying the document base directory.
11. © SAP AG 2010. All rights reserved. / Page 11 Public
WAR extraction
Web application assume it’s extracted on the file system
widely use file system operations
search for resources, configurations, customizations
WAB is installed as bundle
web application is run from the archive
file system operations do not work as expected
Problem
Application cannot access its configurations
Valid for web apps like Orbeon Forms, Jira,
or Confluence wiki
Solution
Implemented support for deploying web application
in exploded form from a file system directory,
following the format of the WAR file
12. © SAP AG 2010. All rights reserved. / Page 12 Public
Class and resource loading problems – Part I
Known problems for standard bundles are still valid for WAB
java.lang.ClassNotFoundException
Because of:
Missing import or export package
Import version mismatch
Forgotten/missing component (really missing!)
Wrong boot class delegation property
Missing file system permissions (can’t read the JARs)
java.lang.NoClassDefFoundError
Because of:
Exception in static block
Missing imported class (ClassNotFoundException for it)
Class version mismatch
Class definition is
found, but
instantiation failed!
Class definition
is missing!
13. © SAP AG 2010. All rights reserved. / Page 13 Public
Class and resource loading problems – Part II
java.lang.ClassCastException
Because of:
Additional copies (besides the system bundle) of the OSGi framework classes
Undesired additional JARs in classpath
Clash between RT.jar and application libs(previously used embedded jars)
JavaSE 5 vs.Java SE 6 does make a difference… (a bunch of new packages
added (StAX, JDBC 4.0, JAXB 2.0, etc.)
14. © SAP AG 2010. All rights reserved. / Page 14 Public
Class and resource loading problems – Part III
Classloader resource assumptions
Access resources as InputStream via the getResourceAsStream()
Access resource using URL object:
URL resourceURL = this.getClass().getResource(“agenda.txt”);
File resourceFile = new File(resourceURL.toURI());
The result is:
java.lang.IllegalArgumentException: URI scheme is not "file"
Because the URL for the resource is returned like this
bundleresource://46.fwk30983464/summit/agenda.txt
This is a limitation for Gemini Web, but is work around in Virgo
(see bug 325578).
15. © SAP AG 2010. All rights reserved. / Page 15 Public
Cluster Features
Some applications may use setups where some cluster functionality is
needed
If Tomcat’s “cluster-howto” doc is used the result is:
java.lang.ClassNotFoundException: org.apache.catalina.ha.tcp.SimpleTcpCluster
at
org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.doLoadClass(Cha
inedClassLoader.java:174)
at
org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.loadClass(Chain
edClassLoader.java:157)
at
org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:205)
Solution was provided in MS4 if Gemini Web based on fragments and:
Standard Apache Tomcat Cluster configuration is supported
Disabled by default but can be enabled when needed
16. © SAP AG 2010. All rights reserved. / Page 16 Public
Automatic Tools
There is NO tool for migrating standard Java EE web application (WAR) to
Web Application Bundle (WAB)
Eclipse PDE – can help with the MANIFEST.MF file
SpringSource Tool Suite
Different tools for creating MANIFEST.MF
BND tool
Apache Felix Maven plugin
Bundlor
OSGi Enterprise Tools (Eclipse proposal)
Wizard for creating WAB
Tools for converting existing Java EE Dynamic Web projects to WAB project
Tools for editing the OSGi metadata – manifest headers
Generic OSGi server adapter
17. © SAP AG 2010. All rights reserved. / Page 17 Public
Agenda
1. OSGi Web Container
2. Migrating Existing Web Applications to OSGi
3. Challenges That We Overcome
4. Conclusions
18. © SAP AG 2010. All rights reserved. / Page 18 Public
Takeaways
Learning curve
Know your application
Assumption for unique context root
Assumption for availability of default Java EE
lib jars
Know OSGi
How classloaders work
Classloader “hell”
ClassNotFoundException, NoClassDefFoundError, ClassCastException
Avoid Class.forName()
Know your wirings
Make sure that you understand the setup of your OSGi environment
19. © SAP AG 2010. All rights reserved. / Page 19 Public
Conclusions
Web on OSGi does work.
Just don’t stumble over small defects.
Working together with the community is the key for success.
20. © SAP AG 2010. All rights reserved. / Page 20 Public
Diyan Yordanov
diyan.yordanov@sap.com
Thank you!