408910 META-INF/jetty-webapp-context.xml file should be able to refer to bundle-relative locations

This commit is contained in:
Jan Bartel 2013-05-28 13:10:49 +10:00
parent 20aeae5914
commit 7e797d8eed
4 changed files with 18 additions and 6 deletions

View File

@ -214,7 +214,7 @@ public abstract class AbstractContextProvider extends AbstractLifeCycle implemen
//put the server instance in
properties.put("Server", getServerInstanceWrapper().getServer());
//put in the location of the bundle root
properties.put("bundle.root", rootResource.toString());
properties.put(OSGiWebappConstants.JETTY_BUNDLE_ROOT, rootResource.toString());
// insert the bundle's location as a property.
xmlConfiguration.getProperties().putAll(properties);

View File

@ -34,6 +34,8 @@ import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.JarResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.osgi.framework.Bundle;
@ -195,6 +197,14 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
? BundleFileLocatorHelperFactory.getFactory().getHelper().getBundleInstallLocation(_bundle)
: new File(overrideBundleInstallLocation));
URL url = null;
Resource rootResource = Resource.newResource(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(bundleInstallLocation.toURI().toURL()));
//try and make sure the rootResource is useable - if its a jar then make it a jar file url
if (rootResource.exists()&& !rootResource.isDirectory() && !rootResource.toString().startsWith("jar:"))
{
Resource jarResource = JarResource.newJarResource(rootResource);
if (jarResource.exists() && jarResource.isDirectory())
rootResource = jarResource;
}
//if the path wasn't set or it was ., then it is the root of the bundle's installed location
if (_webAppPath == null || _webAppPath.length() == 0 || ".".equals(_webAppPath))
@ -284,7 +294,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
// apply any META-INF/context.xml file that is found to configure
// the webapp first
applyMetaInfContextXml();
applyMetaInfContextXml(rootResource);
// pass the value of the require tld bundle so that the TagLibOSGiConfiguration
// can pick it up.
@ -342,7 +352,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
}
protected void applyMetaInfContextXml()
protected void applyMetaInfContextXml(Resource rootResource)
throws Exception
{
if (_bundle == null) return;
@ -366,6 +376,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXmlUrl);
HashMap properties = new HashMap();
properties.put("Server", getDeploymentManager().getServer());
properties.put(OSGiWebappConstants.JETTY_BUNDLE_ROOT, rootResource.toString());
xmlConfiguration.getProperties().putAll(properties);
xmlConfiguration.configure(_webApp);
}

View File

@ -79,6 +79,10 @@ public class OSGiWebappConstants
public static final String JETTY_WAR_PATCH_FRAGMENT_FOLDER_PATH = "Jetty-WarPatchFragmentFolderPath";
/** installation path of webapp bundle
*
*/
public static final String JETTY_BUNDLE_ROOT = "bundle.root";
/**
* web app context path
* @deprecated see RFC66_WEB_CONTEXTPATH

View File

@ -160,12 +160,9 @@ public class DefaultJettyAtJettyHomeHelper
{
Thread.currentThread().setContextClassLoader(JettyBootstrapActivator.class.getClassLoader());
// these properties usually are the ones passed to this type of
// configuration.
properties.put(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME, OSGiServerConstants.MANAGED_JETTY_SERVER_DEFAULT_NAME);
//Util.setProperty(properties, OSGiServerConstants.JETTY_HOME, System.getProperty(OSGiServerConstants.JETTY_HOME));
Util.setProperty(properties, OSGiServerConstants.JETTY_HOST, System.getProperty(OSGiServerConstants.JETTY_HOST));
Util.setProperty(properties, OSGiServerConstants.JETTY_PORT, System.getProperty(OSGiServerConstants.JETTY_PORT));
Util.setProperty(properties, OSGiServerConstants.JETTY_PORT_SSL, System.getProperty(OSGiServerConstants.JETTY_PORT_SSL));