org.eclipse.jetty.osgi.boot.internal.webapp
Class WebappRegistrationHelper

java.lang.Object
  extended by org.eclipse.jetty.osgi.boot.internal.webapp.WebappRegistrationHelper

public class WebappRegistrationHelper
extends Object

Bridges the jetty deployers with the OSGi lifecycle where applications are managed inside OSGi-bundles.

This class should be called as a consequence of the activation of a new service that is a ContextHandler.
This way the new webapps are exposed as OSGi services.

Helper methods to register a bundle that is a web-application or a context.

Limitations:


Field Summary
static BundleClassLoaderHelper BUNDLE_CLASS_LOADER_HELPER
          By default set to: DefaultBundleClassLoaderHelper.
static BundleFileLocatorHelper BUNDLE_FILE_LOCATOR_HELPER
          By default set to: DefaultBundleClassLoaderHelper.
static Collection<WebappRegistrationCustomizer> JSP_REGISTRATION_HELPERS
          By default set to: DefaultBundleClassLoaderHelper.
 
Constructor Summary
WebappRegistrationHelper(Server server)
           
 
Method Summary
protected  void configureWebappClassLoader(org.osgi.framework.Bundle contributor, ContextHandler context, OSGiWebappClassLoader webappClassLoader)
          Configure a classloader onto the context.
protected  void configureWebAppContext(WebAppContext wah, org.osgi.framework.Bundle contributor)
          Applies the properties of WebAppDeployer as defined in jetty.xml.
protected  ContextHandler createContextHandler(org.osgi.framework.Bundle bundle, File contextFile, String extraClasspath, String overrideBundleInstallLocation)
           
protected  ContextHandler createContextHandler(org.osgi.framework.Bundle bundle, InputStream contextInputStream, String extraClasspath, String overrideBundleInstallLocation)
           
protected  OSGiWebappClassLoader createWebappClassLoader(org.osgi.framework.Bundle contributor)
          No matter what the type of webapp, we create a WebappClassLoader.
 ContextHandler registerContext(org.osgi.framework.Bundle contributor, String contextFileRelativePath, String extraClasspath, String overrideBundleInstallLocation)
          This type of registration relies on jetty's complete context xml file.
 ContextHandler registerWebapplication(org.osgi.framework.Bundle contributor, File webapp, String contextPath, String extraClasspath, File bundleInstall, String webXmlPath, String defaultWebXmlPath)
           
 ContextHandler registerWebapplication(org.osgi.framework.Bundle bundle, String webappFolderPath, String contextPath, String extraClasspath, String overrideBundleInstallLocation, String webXmlPath, String defaultWebXmlPath)
          Deploy a new web application on the jetty server.
 void setup(org.osgi.framework.BundleContext context, Map<String,String> configProperties)
          Look for the home directory of jetty as defined by the system property 'jetty.home'.
static String stripQuotesIfPresent(String filePath)
          Removes quotes around system property values before we try to make them into file pathes.
 void unregister(ContextHandler contextHandler)
          Stop a ContextHandler and remove it from the collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUNDLE_CLASS_LOADER_HELPER

public static BundleClassLoaderHelper BUNDLE_CLASS_LOADER_HELPER
By default set to: DefaultBundleClassLoaderHelper. It supports equinox and apache-felix fragment bundles that are specific to an OSGi implementation should set a different implementation.


BUNDLE_FILE_LOCATOR_HELPER

public static BundleFileLocatorHelper BUNDLE_FILE_LOCATOR_HELPER
By default set to: DefaultBundleClassLoaderHelper. It supports equinox and apache-felix fragment bundles that are specific to an OSGi implementation should set a different implementation.


JSP_REGISTRATION_HELPERS

public static Collection<WebappRegistrationCustomizer> JSP_REGISTRATION_HELPERS
By default set to: DefaultBundleClassLoaderHelper. It supports equinox and apache-felix fragment bundles that are specific to an OSGi implementation should set a different implementation.

Several of those objects can be added here: For example we could have an optional fragment that setups a specific implementation of JSF for the whole of jetty-osgi.

Constructor Detail

WebappRegistrationHelper

public WebappRegistrationHelper(Server server)
Method Detail

stripQuotesIfPresent

public static String stripQuotesIfPresent(String filePath)
Removes quotes around system property values before we try to make them into file pathes.


setup

public void setup(org.osgi.framework.BundleContext context,
                  Map<String,String> configProperties)
           throws Exception
Look for the home directory of jetty as defined by the system property 'jetty.home'. If undefined, look at the current bundle and uses its own jettyhome folder for this feature.

Special case: inside eclipse-SDK:
If the bundle is jarred, see if we are inside eclipse-PDE itself. In that case, look for the installation directory of eclipse-PDE, try to create a jettyhome folder there and install the sample jettyhome folder at that location. This makes the installation in eclipse-SDK easier.
This is a bit redundant with the work done by the jetty configuration launcher.

Parameters:
context -
Throws:
Exception

registerWebapplication

public ContextHandler registerWebapplication(org.osgi.framework.Bundle bundle,
                                             String webappFolderPath,
                                             String contextPath,
                                             String extraClasspath,
                                             String overrideBundleInstallLocation,
                                             String webXmlPath,
                                             String defaultWebXmlPath)
                                      throws Exception
Deploy a new web application on the jetty server.

Parameters:
context - The current bundle context
webappFolderPath - The path to the root of the webapp. Must be a path relative to bundle; either an absolute path.
contextPath - The context path. Must start with "/"
classInBundle - A class that belongs to the current bundle to inherit from the osgi classloader. Null to not have access to the OSGI classloader.
Throws:
Exception

registerWebapplication

public ContextHandler registerWebapplication(org.osgi.framework.Bundle contributor,
                                             File webapp,
                                             String contextPath,
                                             String extraClasspath,
                                             File bundleInstall,
                                             String webXmlPath,
                                             String defaultWebXmlPath)
                                      throws Exception
Parameters:
webapp -
contextPath -
classInBundle -
Returns:
The contexthandler created and started
Throws:
Exception

unregister

public void unregister(ContextHandler contextHandler)
                throws Exception
Stop a ContextHandler and remove it from the collection.

Parameters:
contextHandler -
Throws:
Exception

registerContext

public ContextHandler registerContext(org.osgi.framework.Bundle contributor,
                                      String contextFileRelativePath,
                                      String extraClasspath,
                                      String overrideBundleInstallLocation)
                               throws Exception
This type of registration relies on jetty's complete context xml file. Context encompasses jndi and all other things. This makes the definition of the webapp a lot more self-contained.

Parameters:
webapp -
contextPath -
classInBundle -
Throws:
Exception

configureWebAppContext

protected void configureWebAppContext(WebAppContext wah,
                                      org.osgi.framework.Bundle contributor)
Applies the properties of WebAppDeployer as defined in jetty.xml.

See Also:
around the comment // configure it

createContextHandler

protected ContextHandler createContextHandler(org.osgi.framework.Bundle bundle,
                                              File contextFile,
                                              String extraClasspath,
                                              String overrideBundleInstallLocation)
Parameters:
contextFile -
Returns:

createContextHandler

protected ContextHandler createContextHandler(org.osgi.framework.Bundle bundle,
                                              InputStream contextInputStream,
                                              String extraClasspath,
                                              String overrideBundleInstallLocation)
Parameters:
contextFile -
Returns:

configureWebappClassLoader

protected void configureWebappClassLoader(org.osgi.framework.Bundle contributor,
                                          ContextHandler context,
                                          OSGiWebappClassLoader webappClassLoader)
                                   throws Exception
Configure a classloader onto the context. If the context is a WebAppContext, build a WebAppClassLoader that has access to all the jetty classes thanks to the classloader of the JettyBootStrapper bundle and also has access to the classloader of the bundle that defines this context.

If the context is not a WebAppContext, same but with a simpler URLClassLoader. Note that the URLClassLoader is pretty much fake: it delegate all actual classloading to the parent classloaders.

The URL[] returned by the URLClassLoader create contained specifically the jars that some j2ee tools expect and look into. For example the jars that contain tld files for jasper's jstl support.

Also as the jars in the lib folder and the classes in the classes folder might already be in the OSGi classloader we filter them out of the WebAppClassLoader

Parameters:
context -
contributor -
webapp -
contextPath -
classInBundle -
Throws:
Exception

createWebappClassLoader

protected OSGiWebappClassLoader createWebappClassLoader(org.osgi.framework.Bundle contributor)
                                                 throws Exception
No matter what the type of webapp, we create a WebappClassLoader.

Throws:
Exception


Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.