Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
    <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.1<2</version>
    </dependency>
    <dependency>
      <groupId>org.clazzes.dojo</groupId>
      <artifactId>gson-rpc2</artifactId>
      <version>1.0.0<1</version>
    </dependency>

...

All three libraries are needed as runtime dependencies, too.

Additional Runtime Requirements

...

Code Block
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

Code Block
 <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)