This page describes new-style web application OSGi-bundles based on http-util-1.5.0
http-util provides a dynamic servlet registration listener, which registers servlets at an OSGi HttpService when the bundle is started or when the HttpService appears.
http-util is a runtime dependency, too.
Dependencies for GWT Projects
gwt-osgi defines org.clazzes.gwt.osgi.AopRemoteServiceSErvlet, which adapts GWT's REmoteServiceSErvlet to the class loading specifics of an OSGi container. gwt-sec is the swiss army knife for using a shared login service among all your web apps deployed in one OSGi container.
Warning: gwt-osgi-126.96.36.199 is not compatible with the new class loader based resource resolution scheme described below.
gwt-osgi and gwt-sec are alos required as runtime dependencies inside your OSGi container.
Dependencies for DOJO projects
All three libraries are needed as runtime dependencies, too.
Additional Runtime Requirements
The http service of choice is pax HTTP Service http://team.ops4j.org/wiki/display/paxweb/Pax+Web, to be installed on your OSGi console using:
Exporting Web Resources
A typical blueprint snippet for exporting web resources is
Be sure to place your web resources in your bundle under /OSGI-INF/webapp/my-web-app, because the static DefaultHttpContext of http-util-1.5.0 look in "/OSGI-INF/webapp/" + relativeUrl for resources ,which is especially needed for correctly serializing GWT RPC requests.
Warning: Never ever instantiate your own HttpContext, e.g. through org.clazzes.util.http.BasicHttpContext, if you want to share your HttpSession among bundles. clazzes.org's single-sign-on strategy builds heavily on session sharing, so in most cases, do not use your own HttpContext except you have a profound reason for doing so. The httpContext argument of the HttpServiceRegistrationListener is then intentionally left out, so the static DefaultHttpContext instance is used.
ResourceServlet's resourceClassLoaderHint is a bean of your choice, which consists of an instance of a class in your webapp bundle. The resource class loader hint will tell the ResourceServlet to deliver resources from the class loader deduced form this hint. The resource class loader should almost ever point to your webapp bundle's class loader, hence take a bean, which lives in your bundles class loader. Once said, I mean it!
Migrating projects from http-util versions prior to http-util-1.5.0
- Upgrade dependencies to http-util-1.5.0 and gwt-osgi-188.8.131.52, if applicable.
- Move all your deployed resources in the bundle from /WEB-INF to /OSGI-INF/webapp
This might incur checking your service.xml and your pom.xml , maybe you have to move resources inside src/main/resources; especially check Include-Resources of maven bundle plugin configuration (e.g. in gwt project)
- Remove instances of BasicHttpContext
This includes removing the httpContext property from your HttpServiceRegistrationListener bean.
- Prepend /OSGI-INF/webapp to the resourcePath property of your ResourceServlet bean
- Add an appropriate resourceClassLoaderHint to your ResourceServlet bean. (See the hints above for more explanations)