clazzes.org Web Application Bundles

This page describes new-style web application OSGi-bundles based on http-util-1.5.0

Dependencies

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.

    <dependency>
      <groupId>org.clazzes.util</groupId>
      <artifactId>http-util</artifactId>
      <version>1.5.0</version>
    </dependency>

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.

    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>2.4.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.clazzes.gwt</groupId>
      <artifactId>gwt-osgi</artifactId>
      <version>2.4.0.2</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.clazzes.gwt</groupId>
      <artifactId>gwt-sec</artifactId>
      <version>1.1.0</version>
    </dependency>

Warning: gwt-osgi-2.4.0.1 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

dojo-module-api and dojo-provider are exposing DOJO's JavaScript files under /dojo-1.8 in your OSGi-deployed HttpService.

    <dependency>
      <groupId>org.clazzes.dojo</groupId>
      <artifactId>dojo-module-api</artifactId>
      <version>1.0.0</version>
    </dependency>
    <dependency>
      <groupId>org.clazzes.dojo</groupId>
      <artifactId>dojo-provider</artifactId>
      <version>1.8.0.2</version>
    </dependency>
    <dependency>
      <groupId>org.clazzes.dojo</groupId>
      <artifactId>gson-rpc2</artifactId>
      <version>1.0.1</version>
    </dependency>

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:

install -s http://repo2.maven.org/maven2/org/ops4j/pax/web/pax-web-jetty-bundle/2.1.0/pax-web-jetty-bundle-2.1.0.jar

Exporting Web Resources

A typical blueprint snippet for exporting web resources is

 <bp:reference id="httpService" availability="optional" interface="org.osgi.service.http.HttpService">
    <bp:reference-listener ref="listener" bind-method="httpServiceBound" unbind-method="httpServiceUnbound" />
 </bp:reference>


 <bp:bean id="listener" class="org.clazzes.util.http.osgi.HttpServiceRegistrationListener">
   <bp:property name="servlets">
      <bp:map>
        <bp:entry key="/my-web-app" value-ref="resourceServlet"/>
        <bp:entry key="/my-web-app/myService" value-ref="myServiceServlet"/>
      </bp:map>
   </bp:property>
 </bp:bean>

 <bp:bean id="resourceServlet" class="org.clazzes.util.http.ResourceServlet">
   <bp:property name="resourcePath" value="OSGI-INF/webapp/http-login-testpad"/>
   <bp:property name="resourceClassLoaderHint" ref="testLoginServiceImpl"/>
   <bp:property name="excludeMimeTypes">
     <bp:set>
       <bp:value>image/png</bp:value>
       <bp:value>image/gif</bp:value>
       <bp:value>image/jpeg</bp:value>
       <bp:value>image/tiff</bp:value>
     </bp:set>
   </bp:property>
   <bp:property name="aliases">
     <bp:map>
       <bp:entry key="/" value="/index.html"/>
     </bp:map>
   </bp:property>
   <bp:property name="redirects">
     <bp:map>
       <bp:entry key="" value="/my-web-app/"/>
       <bp:entry key="?locales=de,en" value="/my-web-app/"/>
     </bp:map>
   </bp:property>
   <bp:property name="additionalHeaders">
     <bp:list>
       <bp:bean class="org.clazzes.util.http.AdditionalHeader">
         <bp:property name="header" value="X-Frame-Options"/>
         <bp:property name="value" value="DENY"/>
         <bp:property name="mimeTypeRegex" value="text/html"/>
       </bp:bean>
       <bp:bean class="org.clazzes.util.http.AdditionalHeader">
         <bp:property name="header" value="X-Frame-Options"/>
         <bp:property name="value" value="SAMEORIGIN"/>
         <bp:property name="pathRegex" value=".*\.cache\.html"/>
       </bp:bean>
     </bp:list>
   </bp:property>
 </bp:bean>

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

  1. Upgrade dependencies to http-util-1.5.0 and gwt-osgi-2.4.0.2, if applicable.
  2. 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)
  3. Remove instances of BasicHttpContext
    This includes removing the httpContext property from your HttpServiceRegistrationListener bean.
  4. Prepend /OSGI-INF/webapp to the resourcePath property of your ResourceServlet bean
  5. Add an appropriate resourceClassLoaderHint to your ResourceServlet bean. (See the hints above for more explanations)