bug 316909 cleanup and web-bundles don't need to be unzipped anymore. Jetty's standard WebInfConfiguration object takes care of unzipping wars on the fly as necessary to make the webapp consumable for JSPs.
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2048 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
76d1e6bb30
commit
863cc0a757
|
@ -20,6 +20,7 @@ import java.util.Properties;
|
|||
|
||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.DefaultJettyAtJettyHomeHelper;
|
||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.JettyServerServiceTracker;
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.IWebBundleDeployerHelper;
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.JettyContextHandlerServiceTracker;
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.WebBundleTrackerCustomizer;
|
||||
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
|
||||
|
@ -56,9 +57,6 @@ import org.osgi.util.tracker.BundleTracker;
|
|||
public class JettyBootstrapActivator implements BundleActivator
|
||||
{
|
||||
|
||||
/** development only: when set to true enable the jetty server service tracker */
|
||||
private static boolean _enableMultipleJettyServers = true;
|
||||
|
||||
private static JettyBootstrapActivator INSTANCE = null;
|
||||
|
||||
public static JettyBootstrapActivator getInstance()
|
||||
|
@ -92,36 +90,24 @@ public class JettyBootstrapActivator implements BundleActivator
|
|||
// should activate.
|
||||
_packageAdminServiceTracker = new PackageAdminServiceTracker(context);
|
||||
|
||||
|
||||
if (_enableMultipleJettyServers)
|
||||
{//new style...
|
||||
_jettyServerServiceTracker = new JettyServerServiceTracker();
|
||||
context.addServiceListener(_jettyServerServiceTracker,"(objectclass=" + Server.class.getName() + ")");
|
||||
_jettyServerServiceTracker = new JettyServerServiceTracker();
|
||||
context.addServiceListener(_jettyServerServiceTracker,"(objectclass=" + Server.class.getName() + ")");
|
||||
|
||||
//Register the Jetty Server Factory as a ManagedServiceFactory:
|
||||
//Register the Jetty Server Factory as a ManagedServiceFactory:
|
||||
// Properties jettyServerMgdFactoryServiceProps = new Properties();
|
||||
// jettyServerMgdFactoryServiceProps.put("pid", OSGiWebappConstants.MANAGED_JETTY_SERVER_FACTORY_PID);
|
||||
// _jettyServerFactoryService = context.registerService(
|
||||
// ManagedServiceFactory.class.getName(), new JettyServersManagedFactory(),
|
||||
// jettyServerMgdFactoryServiceProps);
|
||||
|
||||
_jettyContextHandlerTracker = new JettyContextHandlerServiceTracker(_jettyServerServiceTracker);
|
||||
}
|
||||
else
|
||||
{//old style...
|
||||
_server = new Server();
|
||||
// expose the server as a service.
|
||||
_registeredServer = context.registerService(_server.getClass().getName(),_server,new Properties());
|
||||
_jettyContextHandlerTracker = new JettyContextHandlerServiceTracker(context,_server);
|
||||
}
|
||||
|
||||
_jettyContextHandlerTracker = new JettyContextHandlerServiceTracker(_jettyServerServiceTracker);
|
||||
|
||||
// the tracker in charge of the actual deployment
|
||||
// and that will configure and start the jetty server.
|
||||
context.addServiceListener(_jettyContextHandlerTracker,"(objectclass=" + ContextHandler.class.getName() + ")");
|
||||
|
||||
if (_enableMultipleJettyServers)
|
||||
{
|
||||
DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context);
|
||||
}
|
||||
//see if we shoult start a default jetty instance right now.
|
||||
DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context);
|
||||
|
||||
// now ready to support the Extender pattern:
|
||||
_webBundleTracker = new BundleTracker(context,
|
||||
|
@ -288,6 +274,7 @@ public class JettyBootstrapActivator implements BundleActivator
|
|||
{
|
||||
ContextHandler contextHandler = new ContextHandler();
|
||||
dic.put(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH,contextFilePath);
|
||||
dic.put(IWebBundleDeployerHelper.INTERNAL_SERVICE_PROP_UNKNOWN_CONTEXT_HANDLER_TYPE,Boolean.TRUE.toString());
|
||||
contributor.getBundleContext().registerService(ContextHandler.class.getName(),contextHandler,dic);
|
||||
}
|
||||
|
||||
|
|
|
@ -289,6 +289,17 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExtract()
|
||||
{
|
||||
return _extractWars;
|
||||
}
|
||||
|
||||
public void setExtract(boolean extract)
|
||||
{
|
||||
_extractWars=extract;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
|
|
@ -18,11 +18,13 @@ import java.io.File;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
||||
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
@ -135,11 +137,10 @@ public class DefaultJettyAtJettyHomeHelper {
|
|||
properties.put(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS, configURLs);
|
||||
|
||||
//these properties usually are the ones passed to this type of configuration.
|
||||
//TODO remove the hardcoded defaults once we use 7.1.5
|
||||
setProperty(properties,SYS_PROP_JETTY_HOME,System.getProperty(SYS_PROP_JETTY_HOME));
|
||||
setProperty(properties,SYS_PROP_JETTY_HOST,System.getProperty(SYS_PROP_JETTY_HOST));
|
||||
setProperty(properties,SYS_PROP_JETTY_PORT,System.getProperty(SYS_PROP_JETTY_PORT, "8080"));
|
||||
setProperty(properties,SYS_PROP_JETTY_PORT_SSL,System.getProperty(SYS_PROP_JETTY_PORT_SSL, "8443"));
|
||||
setProperty(properties,SYS_PROP_JETTY_PORT,System.getProperty(SYS_PROP_JETTY_PORT));
|
||||
setProperty(properties,SYS_PROP_JETTY_PORT_SSL,System.getProperty(SYS_PROP_JETTY_PORT_SSL));
|
||||
|
||||
bundleContext.registerService(Server.class.getName(), server, properties);
|
||||
}
|
||||
|
@ -201,26 +202,18 @@ public class DefaultJettyAtJettyHomeHelper {
|
|||
}
|
||||
else
|
||||
{
|
||||
int last = etcFile.lastIndexOf('/');
|
||||
String path = last != -1 && last < etcFile.length() -2
|
||||
? etcFile.substring(0, last) : "/";
|
||||
if (!path.startsWith("/"))
|
||||
{
|
||||
path = "/" + path;
|
||||
}
|
||||
String pattern = last != -1 && last < etcFile.length() -2
|
||||
? etcFile.substring(last+1) : etcFile;
|
||||
Enumeration<URL> enUrls = configurationBundle.findEntries(path, pattern, false);
|
||||
Enumeration<URL> enUrls = BundleFileLocatorHelper.DEFAULT
|
||||
.findEntries(configurationBundle, etcFile);
|
||||
|
||||
//default for org.eclipse.osgi.boot where we look inside jettyhome for the default embedded configuration.
|
||||
//default inside jettyhome. this way fragments to the bundle can define their own configuration.
|
||||
if ((enUrls == null || !enUrls.hasMoreElements()) && pattern.equals("jetty.xml"))
|
||||
if ((enUrls == null || !enUrls.hasMoreElements()) && etcFile.endsWith("etc/jetty.xml"))
|
||||
{
|
||||
path = "/jettyhome" + path;
|
||||
pattern = "jetty-osgi-default.xml";
|
||||
enUrls = configurationBundle.findEntries(path, pattern, false);
|
||||
enUrls = BundleFileLocatorHelper.DEFAULT
|
||||
.findEntries(configurationBundle, "/jettyhome/etc/jetty-osgi-default.xml");
|
||||
System.err.println("Configuring jetty with the default embedded configuration:" +
|
||||
"bundle: " + configurationBundle.getSymbolicName() + " config: /jettyhome/etc/jetty-osgi-default.xml");
|
||||
"bundle: " + configurationBundle.getSymbolicName() +
|
||||
" config: /jettyhome/etc/jetty-osgi-default.xml");
|
||||
}
|
||||
if (enUrls != null)
|
||||
{
|
||||
|
@ -250,4 +243,5 @@ public class DefaultJettyAtJettyHomeHelper {
|
|||
properties.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
|||
import org.eclipse.jetty.osgi.boot.internal.jsp.TldLocatableURLClassloader;
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper;
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.WebBundleDeployerHelper;
|
||||
import org.eclipse.jetty.osgi.boot.internal.webapp.WebappRegistrationHelper;
|
||||
import org.eclipse.jetty.osgi.boot.utils.WebappRegistrationCustomizer;
|
||||
import org.eclipse.jetty.osgi.boot.utils.internal.DefaultFileLocatorHelper;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
@ -224,9 +223,10 @@ public class ServerInstanceWrapper {
|
|||
private URL[] getJarsWithTlds() throws Exception
|
||||
{
|
||||
ArrayList<URL> res = new ArrayList<URL>();
|
||||
WebBundleDeployerHelper.staticInit();//that is not looking great.
|
||||
for (WebappRegistrationCustomizer regCustomizer : WebBundleDeployerHelper.JSP_REGISTRATION_HELPERS)
|
||||
{
|
||||
URL[] urls = regCustomizer.getJarsWithTlds(_provider, WebBundleDeployerHelper.BUNDLE_FILE_LOCATOR_HELPER);
|
||||
URL[] urls = regCustomizer.getJarsWithTlds(_provider, WebBundleDeployerHelper.BUNDLE_FILE_LOCATOR_HELPER);
|
||||
for (URL url : urls)
|
||||
{
|
||||
if (!res.contains(url))
|
||||
|
@ -274,8 +274,7 @@ public class ServerInstanceWrapper {
|
|||
}
|
||||
catch (SAXParseException saxparse)
|
||||
{
|
||||
Log.getLogger(WebappRegistrationHelper.class.getName())
|
||||
.warn("Unable to configure the jetty/etc file " + jettyConfiguration,saxparse);
|
||||
__logger.warn("Unable to configure the jetty/etc file " + jettyConfiguration,saxparse);
|
||||
throw saxparse;
|
||||
}
|
||||
finally
|
||||
|
|
|
@ -14,11 +14,9 @@
|
|||
// ========================================================================
|
||||
package org.eclipse.jetty.osgi.boot.internal.webapp;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.deploy.ContextDeployer;
|
||||
import org.eclipse.jetty.deploy.WebAppDeployer;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +25,11 @@ import org.osgi.framework.Bundle;
|
|||
*/
|
||||
public interface IWebBundleDeployerHelper {
|
||||
|
||||
/** when this property is present, the type of context handler registered is not
|
||||
* known in advance. */
|
||||
public static final String INTERNAL_SERVICE_PROP_UNKNOWN_CONTEXT_HANDLER_TYPE = "unknownContextHandlerType";
|
||||
|
||||
|
||||
/**
|
||||
* Deploy a new web application on the jetty server.
|
||||
*
|
||||
|
@ -45,29 +48,10 @@ public interface IWebBundleDeployerHelper {
|
|||
* @return The contexthandler created and started
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract ContextHandler registerWebapplication(Bundle bundle,
|
||||
public abstract WebAppContext registerWebapplication(Bundle bundle,
|
||||
String webappFolderPath, String contextPath, String extraClasspath,
|
||||
String overrideBundleInstallLocation, String webXmlPath,
|
||||
String defaultWebXmlPath) throws Exception;
|
||||
|
||||
/**
|
||||
* TODO: refactor this into the createContext method of OSGiAppProvider.
|
||||
* @see WebAppDeployer#scan()
|
||||
|
||||
* @param contributor
|
||||
* @param webapp
|
||||
* @param contextPath
|
||||
* @param extraClasspath
|
||||
* @param bundleInstall
|
||||
* @param webXmlPath
|
||||
* @param defaultWebXmlPath
|
||||
* @return The contexthandler created and started
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract ContextHandler registerWebapplication(Bundle contributor,
|
||||
String pathInBundleToWebApp, File webapp, String contextPath,
|
||||
String extraClasspath, File bundleInstall, String webXmlPath,
|
||||
String defaultWebXmlPath) throws Exception;
|
||||
String defaultWebXmlPath, WebAppContext webAppContext) throws Exception;
|
||||
|
||||
/**
|
||||
* Stop a ContextHandler and remove it from the collection.
|
||||
|
@ -88,11 +72,13 @@ public interface IWebBundleDeployerHelper {
|
|||
* @param contextFileRelativePath
|
||||
* @param extraClasspath
|
||||
* @param overrideBundleInstallLocation
|
||||
* @param handler the context handler passed in the server
|
||||
* reference that will be configured, deployed and started.
|
||||
* @return The contexthandler created and started
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract ContextHandler registerContext(Bundle contributor,
|
||||
String contextFileRelativePath, String extraClasspath,
|
||||
String overrideBundleInstallLocation) throws Exception;
|
||||
String overrideBundleInstallLocation, ContextHandler handler) throws Exception;
|
||||
|
||||
}
|
|
@ -22,7 +22,6 @@ import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
|
|||
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
|
||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.IManagedJettyServerRegistry;
|
||||
import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.Scanner;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
@ -55,15 +54,12 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
|||
|
||||
/** New style: ability to manage multiple jetty instances */
|
||||
private final IManagedJettyServerRegistry _registry;
|
||||
/** Old style: ability to manage multiple jetty instances */
|
||||
private final WebappRegistrationHelper _helper;
|
||||
|
||||
/** The context-handler to deactivate indexed by context handler */
|
||||
private Map<ServiceReference, ContextHandler> _indexByServiceReference = new HashMap<ServiceReference, ContextHandler>();
|
||||
|
||||
/**
|
||||
* The index is the bundle-symbolic-name/paht/to/context/file when there is
|
||||
* such thing
|
||||
* The index is the bundle-symbolic-name/path/to/context/file when there is such thing
|
||||
*/
|
||||
private Map<String, ServiceReference> _indexByContextFile = new HashMap<String, ServiceReference>();
|
||||
|
||||
|
@ -71,24 +67,11 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
|||
private Scanner _scanner;
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param server
|
||||
*/
|
||||
public JettyContextHandlerServiceTracker(BundleContext context, Server server) throws Exception
|
||||
{
|
||||
_registry = null;
|
||||
_helper = new WebappRegistrationHelper(server);
|
||||
_helper.setup(context,new HashMap<String, String>());
|
||||
setupContextHomeScanner(_helper.getOSGiContextsHome());
|
||||
}
|
||||
/**
|
||||
* @param context
|
||||
* @param server
|
||||
* @param registry
|
||||
*/
|
||||
public JettyContextHandlerServiceTracker(IManagedJettyServerRegistry registry) throws Exception
|
||||
{
|
||||
_registry = registry;
|
||||
_helper = null;
|
||||
}
|
||||
|
||||
public void stop()
|
||||
|
@ -192,7 +175,11 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
|||
// is configured elsewhere.
|
||||
return;
|
||||
}
|
||||
if (contextHandler instanceof WebAppContext)
|
||||
String contextFilePath = (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH);
|
||||
if (contextHandler instanceof WebAppContext && contextFilePath == null)
|
||||
//it could be a web-application that will in fact be configured via a context file.
|
||||
//that case is identified by the fact that the contextFilePath is not null
|
||||
//in that case we must use the register context methods.
|
||||
{
|
||||
WebAppContext webapp = (WebAppContext)contextHandler;
|
||||
String contextPath = (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_PATH);
|
||||
|
@ -213,14 +200,23 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
|||
String war = (String)sr.getProperty("war");
|
||||
try
|
||||
{
|
||||
ContextHandler handler = getWebBundleDeployerHelp(sr)
|
||||
IWebBundleDeployerHelper deployerHelper = getWebBundleDeployerHelp(sr);
|
||||
if (deployerHelper == null)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
WebAppContext handler = deployerHelper
|
||||
.registerWebapplication(contributor,war,contextPath,(String)sr
|
||||
.getProperty(OSGiWebappConstants.SERVICE_PROP_EXTRA_CLASSPATH),(String)sr
|
||||
.getProperty(OSGiWebappConstants.SERVICE_PROP_BUNDLE_INSTALL_LOCATION_OVERRIDE),webXmlPath,defaultWebXmlPath);
|
||||
if (handler != null)
|
||||
{
|
||||
registerInIndex(handler,sr);
|
||||
}
|
||||
.getProperty(OSGiWebappConstants.SERVICE_PROP_BUNDLE_INSTALL_LOCATION_OVERRIDE),
|
||||
webXmlPath,defaultWebXmlPath,webapp);
|
||||
if (handler != null)
|
||||
{
|
||||
registerInIndex(handler,sr);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
|
@ -230,20 +226,33 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
|||
else
|
||||
{
|
||||
// consider this just an empty skeleton:
|
||||
String contextFilePath = (String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_CONTEXT_FILE_PATH);
|
||||
if (contextFilePath == null)
|
||||
{
|
||||
throw new IllegalArgumentException("the property contextFilePath is required");
|
||||
}
|
||||
try
|
||||
{
|
||||
ContextHandler handler = getWebBundleDeployerHelp(sr).registerContext(contributor,contextFilePath,(String)sr
|
||||
.getProperty(OSGiWebappConstants.SERVICE_PROP_EXTRA_CLASSPATH),(String)sr
|
||||
.getProperty(OSGiWebappConstants.SERVICE_PROP_BUNDLE_INSTALL_LOCATION_OVERRIDE));
|
||||
if (handler != null)
|
||||
{
|
||||
registerInIndex(handler,sr);
|
||||
}
|
||||
IWebBundleDeployerHelper deployerHelper = getWebBundleDeployerHelp(sr);
|
||||
if (deployerHelper == null)
|
||||
{
|
||||
//more warnings?
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Boolean.TRUE.toString().equals(sr.getProperty(
|
||||
IWebBundleDeployerHelper.INTERNAL_SERVICE_PROP_UNKNOWN_CONTEXT_HANDLER_TYPE)))
|
||||
{
|
||||
contextHandler = null;
|
||||
}
|
||||
ContextHandler handler = deployerHelper.registerContext(contributor,contextFilePath,
|
||||
(String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_EXTRA_CLASSPATH),
|
||||
(String)sr.getProperty(OSGiWebappConstants.SERVICE_PROP_BUNDLE_INSTALL_LOCATION_OVERRIDE),
|
||||
contextHandler);
|
||||
if (handler != null)
|
||||
{
|
||||
registerInIndex(handler,sr);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
|
@ -353,6 +362,7 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
|||
managedServerName = OSGiServerConstants.MANAGED_JETTY_SERVER_DEFAULT_NAME;
|
||||
}
|
||||
ServerInstanceWrapper wrapper = _registry.getServerInstanceWrapper(managedServerName);
|
||||
System.err.println("Returning " + managedServerName + " = " + wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
@ -360,12 +370,11 @@ public class JettyContextHandlerServiceTracker implements ServiceListener
|
|||
{
|
||||
if (_registry == null)
|
||||
{
|
||||
return _helper;
|
||||
return null;
|
||||
}
|
||||
String managedServerName = (String)sr.getProperty(OSGiServerConstants.MANAGED_JETTY_SERVER_NAME);
|
||||
ServerInstanceWrapper wrapper = getServerInstanceWrapper(managedServerName);
|
||||
return wrapper != null ? wrapper.getWebBundleDeployerHelp() : _helper;
|
||||
return wrapper != null ? wrapper.getWebBundleDeployerHelp() : null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,9 +23,8 @@ import java.io.InputStream;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.eclipse.jetty.deploy.ContextDeployer;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
|
||||
|
@ -36,6 +35,7 @@ import org.eclipse.jetty.osgi.boot.utils.WebappRegistrationCustomizer;
|
|||
import org.eclipse.jetty.osgi.boot.utils.internal.DefaultBundleClassLoaderHelper;
|
||||
import org.eclipse.jetty.osgi.boot.utils.internal.DefaultFileLocatorHelper;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -67,7 +67,7 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
private static Logger __logger = Log.getLogger(WebBundleDeployerHelper.class.getName());
|
||||
|
||||
private static boolean INITIALIZED = false;
|
||||
|
||||
|
||||
/**
|
||||
* By default set to: {@link DefaultBundleClassLoaderHelper}. It supports
|
||||
* equinox and apache-felix fragment bundles that are specific to an OSGi
|
||||
|
@ -103,12 +103,12 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
|
||||
public WebBundleDeployerHelper(ServerInstanceWrapper wrapper)
|
||||
{
|
||||
staticInit();
|
||||
_wrapper = wrapper;
|
||||
staticInit();
|
||||
}
|
||||
|
||||
// Inject the customizing classes that might be defined in fragment bundles.
|
||||
private static synchronized void staticInit()
|
||||
public static synchronized void staticInit()
|
||||
{
|
||||
if (!INITIALIZED)
|
||||
{
|
||||
|
@ -139,45 +139,60 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jetty.osgi.boot.internal.webapp.IWebBundleDeployerHelper#registerWebapplication(org.osgi.framework.Bundle, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public ContextHandler registerWebapplication(Bundle bundle, String webappFolderPath, String contextPath, String extraClasspath,
|
||||
String overrideBundleInstallLocation, String webXmlPath, String defaultWebXmlPath) throws Exception
|
||||
public WebAppContext registerWebapplication(Bundle bundle, String webappFolderPath, String contextPath, String extraClasspath,
|
||||
String overrideBundleInstallLocation, String webXmlPath, String defaultWebXmlPath, WebAppContext webAppContext) throws Exception
|
||||
{
|
||||
File bundleInstall = overrideBundleInstallLocation == null?BUNDLE_FILE_LOCATOR_HELPER.getBundleInstallLocation(bundle):new File(
|
||||
overrideBundleInstallLocation);
|
||||
File webapp = null;
|
||||
URL baseWebappInstallURL = null;
|
||||
if (webappFolderPath != null && webappFolderPath.length() != 0 && !webappFolderPath.equals("."))
|
||||
{
|
||||
if (webappFolderPath.startsWith("/") || webappFolderPath.startsWith("file:/"))
|
||||
if (webappFolderPath.startsWith("/") || webappFolderPath.startsWith("file:"))
|
||||
{
|
||||
webapp = new File(webappFolderPath);
|
||||
}
|
||||
else
|
||||
else if (bundleInstall != null && bundleInstall.isDirectory())
|
||||
{
|
||||
webapp = new File(bundleInstall,webappFolderPath);
|
||||
}
|
||||
else if (bundleInstall != null)
|
||||
{
|
||||
Enumeration<URL> urls = BUNDLE_FILE_LOCATOR_HELPER.findEntries(bundle, webappFolderPath);
|
||||
if (urls != null && urls.hasMoreElements())
|
||||
{
|
||||
baseWebappInstallURL = urls.nextElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
webapp = bundleInstall;
|
||||
}
|
||||
if (!webapp.exists())
|
||||
if (baseWebappInstallURL == null && (webapp == null || !webapp.exists()))
|
||||
{
|
||||
throw new IllegalArgumentException("Unable to locate " + webappFolderPath + " inside "
|
||||
+ (bundleInstall != null?bundleInstall.getAbsolutePath():"unlocated bundle '" + bundle.getSymbolicName() + "'"));
|
||||
}
|
||||
return registerWebapplication(bundle,webappFolderPath,webapp,contextPath,extraClasspath,bundleInstall,webXmlPath,defaultWebXmlPath);
|
||||
if (baseWebappInstallURL == null && webapp != null)
|
||||
{
|
||||
baseWebappInstallURL = webapp.toURI().toURL();
|
||||
}
|
||||
return registerWebapplication(bundle,webappFolderPath,baseWebappInstallURL,contextPath,
|
||||
extraClasspath,bundleInstall,webXmlPath,defaultWebXmlPath,webAppContext);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jetty.osgi.boot.internal.webapp.IWebBundleDeployerHelper#registerWebapplication(org.osgi.framework.Bundle, java.lang.String, java.io.File, java.lang.String, java.lang.String, java.io.File, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public ContextHandler registerWebapplication(Bundle contributor, String pathInBundleToWebApp, File webapp, String contextPath, String extraClasspath, File bundleInstall,
|
||||
String webXmlPath, String defaultWebXmlPath) throws Exception
|
||||
private WebAppContext registerWebapplication(Bundle contributor, String pathInBundleToWebApp,
|
||||
URL baseWebappInstallURL, String contextPath, String extraClasspath, File bundleInstall,
|
||||
String webXmlPath, String defaultWebXmlPath, WebAppContext context) throws Exception
|
||||
{
|
||||
|
||||
ClassLoader contextCl = Thread.currentThread().getContextClassLoader();
|
||||
String[] oldServerClasses = null;
|
||||
WebAppContext context = null;
|
||||
|
||||
try
|
||||
{
|
||||
// make sure we provide access to all the jetty bundles by going
|
||||
|
@ -187,7 +202,8 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
// that the contributor gives access to.
|
||||
Thread.currentThread().setContextClassLoader(composite);
|
||||
|
||||
context = new WebAppContext(webapp.getAbsolutePath(),contextPath);
|
||||
context.setWar(baseWebappInstallURL.toString());
|
||||
context.setContextPath(contextPath);
|
||||
context.setExtraClasspath(extraClasspath);
|
||||
|
||||
if (webXmlPath != null && webXmlPath.length() != 0)
|
||||
|
@ -242,7 +258,9 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
// through the webapp classloader.
|
||||
oldServerClasses = context.getServerClasses();
|
||||
context.setServerClasses(null);
|
||||
|
||||
_wrapper.getOSGiAppProvider().addContext(contributor,pathInBundleToWebApp,context);
|
||||
|
||||
return context;
|
||||
}
|
||||
finally
|
||||
|
@ -267,7 +285,8 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jetty.osgi.boot.internal.webapp.IWebBundleDeployerHelper#registerContext(org.osgi.framework.Bundle, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public ContextHandler registerContext(Bundle contributor, String contextFileRelativePath, String extraClasspath, String overrideBundleInstallLocation)
|
||||
public ContextHandler registerContext(Bundle contributor, String contextFileRelativePath, String extraClasspath,
|
||||
String overrideBundleInstallLocation, ContextHandler handler)
|
||||
throws Exception
|
||||
{
|
||||
File contextsHome = _wrapper.getOSGiAppProvider().getContextXmlDirAsFile();
|
||||
|
@ -276,15 +295,17 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
File prodContextFile = new File(contextsHome,contributor.getSymbolicName() + "/" + contextFileRelativePath);
|
||||
if (prodContextFile.exists())
|
||||
{
|
||||
return registerContext(contributor,contextFileRelativePath,prodContextFile,extraClasspath,overrideBundleInstallLocation);
|
||||
return registerContext(contributor,contextFileRelativePath,prodContextFile,extraClasspath,
|
||||
overrideBundleInstallLocation,handler);
|
||||
}
|
||||
}
|
||||
|
||||
File contextFile = overrideBundleInstallLocation != null?new File(overrideBundleInstallLocation,contextFileRelativePath):new File(
|
||||
BUNDLE_FILE_LOCATOR_HELPER.getBundleInstallLocation(contributor),contextFileRelativePath);
|
||||
if (contextFile.exists())
|
||||
File rootFolder = overrideBundleInstallLocation != null
|
||||
? Resource.newResource(overrideBundleInstallLocation).getFile()
|
||||
: BUNDLE_FILE_LOCATOR_HELPER.getBundleInstallLocation(contributor);
|
||||
File contextFile = rootFolder != null?new File(rootFolder,contextFileRelativePath):null;
|
||||
if (contextFile != null && contextFile.exists())
|
||||
{
|
||||
return registerContext(contributor,contextFileRelativePath,contextFile,extraClasspath,overrideBundleInstallLocation);
|
||||
return registerContext(contributor,contextFileRelativePath,contextFile,extraClasspath,overrideBundleInstallLocation,handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -297,39 +318,10 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
contextFileRelativePath = "/" + contextFileRelativePath;
|
||||
}
|
||||
|
||||
File overrideBundleInstallLocationF = overrideBundleInstallLocation != null ? Resource.newResource(overrideBundleInstallLocation).getFile() : null;
|
||||
if (overrideBundleInstallLocationF == null)
|
||||
URL contextURL = contributor.getEntry(contextFileRelativePath);
|
||||
if (contextURL != null)
|
||||
{
|
||||
URL contextURL = contributor.getEntry(contextFileRelativePath);
|
||||
if (contextURL != null)
|
||||
{
|
||||
return registerContext(contributor,contextFileRelativePath,contextURL.openStream(),extraClasspath,overrideBundleInstallLocation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JarFile zipFile = null;
|
||||
try
|
||||
{
|
||||
zipFile = new JarFile(overrideBundleInstallLocation);
|
||||
ZipEntry entry = zipFile.getEntry(contextFileRelativePath.substring(1));
|
||||
return registerContext(contributor,contextFileRelativePath,zipFile.getInputStream(entry),extraClasspath,overrideBundleInstallLocation);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (zipFile != null)
|
||||
try
|
||||
{
|
||||
zipFile.close();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
}
|
||||
return registerContext(contributor,contextFileRelativePath,contextURL.openStream(),extraClasspath,overrideBundleInstallLocation,handler);
|
||||
}
|
||||
throw new IllegalArgumentException("Could not find the context " + "file " + contextFileRelativePath + " for the bundle "
|
||||
+ contributor.getSymbolicName() + (overrideBundleInstallLocation != null?" using the install location " + overrideBundleInstallLocation:""));
|
||||
|
@ -346,24 +338,18 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
* @param classInBundle
|
||||
* @throws Exception
|
||||
*/
|
||||
private ContextHandler registerContext(Bundle contributor, String pathInBundle, File contextFile, String extraClasspath, String overrideBundleInstallLocation) throws Exception
|
||||
private ContextHandler registerContext(Bundle contributor, String pathInBundle, File contextFile,
|
||||
String extraClasspath, String overrideBundleInstallLocation, ContextHandler handler) throws Exception
|
||||
{
|
||||
InputStream contextFileInputStream = null;
|
||||
try
|
||||
{
|
||||
contextFileInputStream = new BufferedInputStream(new FileInputStream(contextFile));
|
||||
return registerContext(contributor, pathInBundle, contextFileInputStream,extraClasspath,overrideBundleInstallLocation);
|
||||
return registerContext(contributor, pathInBundle, contextFileInputStream,extraClasspath,overrideBundleInstallLocation, handler);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (contextFileInputStream != null)
|
||||
try
|
||||
{
|
||||
contextFileInputStream.close();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
IO.close(contextFileInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,7 +360,8 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
* happen.
|
||||
* @throws Exception
|
||||
*/
|
||||
private ContextHandler registerContext(Bundle contributor, String pathInsideBundle, InputStream contextFileInputStream, String extraClasspath, String overrideBundleInstallLocation)
|
||||
private ContextHandler registerContext(Bundle contributor, String pathInsideBundle, InputStream contextFileInputStream,
|
||||
String extraClasspath, String overrideBundleInstallLocation, ContextHandler handler)
|
||||
throws Exception
|
||||
{
|
||||
ClassLoader contextCl = Thread.currentThread().getContextClassLoader();
|
||||
|
@ -389,7 +376,7 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
// classes
|
||||
// that the contributor gives access to.
|
||||
Thread.currentThread().setContextClassLoader(composite);
|
||||
ContextHandler context = createContextHandler(contributor,contextFileInputStream,extraClasspath,overrideBundleInstallLocation);
|
||||
ContextHandler context = createContextHandler(handler, contributor,contextFileInputStream,extraClasspath,overrideBundleInstallLocation);
|
||||
if (context == null)
|
||||
{
|
||||
return null;// did not happen
|
||||
|
@ -449,11 +436,12 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
* @param contextFile
|
||||
* @return
|
||||
*/
|
||||
protected ContextHandler createContextHandler(Bundle bundle, File contextFile, String extraClasspath, String overrideBundleInstallLocation)
|
||||
protected ContextHandler createContextHandler(ContextHandler handlerToConfigure,
|
||||
Bundle bundle, File contextFile, String extraClasspath, String overrideBundleInstallLocation)
|
||||
{
|
||||
try
|
||||
{
|
||||
return createContextHandler(bundle,new BufferedInputStream(new FileInputStream(contextFile)),extraClasspath,overrideBundleInstallLocation);
|
||||
return createContextHandler(handlerToConfigure,bundle,new BufferedInputStream(new FileInputStream(contextFile)),extraClasspath,overrideBundleInstallLocation);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
|
@ -468,7 +456,8 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ContextHandler createContextHandler(Bundle bundle, InputStream contextInputStream, String extraClasspath, String overrideBundleInstallLocation)
|
||||
protected ContextHandler createContextHandler(ContextHandler handlerToConfigure,
|
||||
Bundle bundle, InputStream contextInputStream, String extraClasspath, String overrideBundleInstallLocation)
|
||||
{
|
||||
/*
|
||||
* Do something identical to what the ContextProvider would have done:
|
||||
|
@ -491,7 +480,17 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
setThisBundleHomeProperty(bundle,properties,overrideBundleInstallLocation);
|
||||
xmlConfiguration.setProperties(properties);
|
||||
|
||||
ContextHandler context = (ContextHandler)xmlConfiguration.configure();
|
||||
ContextHandler context = null;
|
||||
if (handlerToConfigure == null)
|
||||
{
|
||||
context = (ContextHandler)xmlConfiguration.configure();
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlConfiguration.configure(handlerToConfigure);
|
||||
context = handlerToConfigure;
|
||||
}
|
||||
|
||||
if (context instanceof WebAppContext)
|
||||
{
|
||||
((WebAppContext)context).setExtraClasspath(extraClasspath);
|
||||
|
@ -534,14 +533,7 @@ public class WebBundleDeployerHelper implements IWebBundleDeployerHelper
|
|||
}
|
||||
finally
|
||||
{
|
||||
if (contextInputStream != null)
|
||||
try
|
||||
{
|
||||
contextInputStream.close();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
}
|
||||
IO.close(contextInputStream);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,8 @@
|
|||
package org.eclipse.jetty.osgi.boot.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.eclipse.jetty.osgi.boot.utils.internal.DefaultFileLocatorHelper;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
@ -73,5 +75,16 @@ public interface BundleFileLocatorHelper
|
|||
* embedded inside it.
|
||||
*/
|
||||
public File[] locateJarsInsideBundle(Bundle bundle) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Helper method equivalent to Bundle#getEntry(String entryPath) except that
|
||||
* it searches for entries in the fragments by using the findEntries method.
|
||||
*
|
||||
* @param bundle
|
||||
* @param entryPath
|
||||
* @return null or all the entries found for that path.
|
||||
*/
|
||||
public Enumeration<URL> findEntries(Bundle bundle, String entryPath);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.net.URL;
|
|||
import java.net.URLConnection;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
|
||||
|
@ -141,13 +142,19 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
|
|||
{
|
||||
//location defined in the BundleArchive m_bundleArchive
|
||||
//it is relative to relative to the BundleArchive's m_archiveRootDir
|
||||
Object bundleArchive = getFelixBundleArchive(bundle);
|
||||
File archiveRoot = getFelixBundleArchiveRootDir(bundleArchive);
|
||||
String currentLocation = getFelixBundleArchiveCurrentLocation(bundleArchive);
|
||||
// System.err.println("Got the archive root " + archiveRoot.getAbsolutePath()
|
||||
// + " current location " + currentLocation);
|
||||
return new File(archiveRoot, currentLocation != null
|
||||
? currentLocation : location.substring("file:".length()));
|
||||
File res = new File(location.substring("file:".length()));
|
||||
if (!res.exists())
|
||||
{
|
||||
return null;
|
||||
// Object bundleArchive = getFelixBundleArchive(bundle);
|
||||
// File archiveRoot = getFelixBundleArchiveRootDir(bundleArchive);
|
||||
// String currentLocation = getFelixBundleArchiveCurrentLocation(bundleArchive);
|
||||
// System.err.println("Got the archive root " + archiveRoot.getAbsolutePath()
|
||||
// + " current location " + currentLocation + " is directory ?");
|
||||
// res = new File(archiveRoot, currentLocation != null
|
||||
// ? currentLocation : location.substring("file:".length()));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
else if (location.startsWith("reference:file:"))
|
||||
{
|
||||
|
@ -182,6 +189,29 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
|
|||
}
|
||||
return webapp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method equivalent to Bundle#getEntry(String entryPath) except that
|
||||
* it searches for entries in the fragments by using the Bundle#findEntries method.
|
||||
*
|
||||
* @param bundle
|
||||
* @param entryPath
|
||||
* @return null or all the entries found for that path.
|
||||
*/
|
||||
public Enumeration<URL> findEntries(Bundle bundle, String entryPath)
|
||||
{
|
||||
int last = entryPath.lastIndexOf('/');
|
||||
String path = last != -1 && last < entryPath.length() -2
|
||||
? entryPath.substring(0, last) : "/";
|
||||
if (!path.startsWith("/"))
|
||||
{
|
||||
path = "/" + path;
|
||||
}
|
||||
String pattern = last != -1 && last < entryPath.length() -2
|
||||
? entryPath.substring(last+1) : entryPath;
|
||||
Enumeration<URL> enUrls = bundle.findEntries(path, pattern, false);
|
||||
return enUrls;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the bundle is a jar, returns the jar. If the bundle is a folder, look
|
||||
|
@ -231,6 +261,7 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
|
|||
|
||||
|
||||
//introspection on equinox to invoke the getLocalURL method on BundleURLConnection
|
||||
//equivalent to using the FileLocator without depending on an equinox class.
|
||||
private static Method BUNDLE_URL_CONNECTION_getLocalURL = null;
|
||||
private static Method BUNDLE_URL_CONNECTION_getFileURL = null;
|
||||
/**
|
||||
|
@ -297,62 +328,5 @@ public class DefaultFileLocatorHelper implements BundleFileLocatorHelper
|
|||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
//introspection on felix
|
||||
private static Field m_bundleArchive_FIELD = null;
|
||||
private static Field m_archiveRootDir_FIELD = null;
|
||||
private static Field m_currentLocation_FIELD = null;
|
||||
private static Object getFelixBundleArchive(Bundle bundle)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_bundleArchive_FIELD == null)
|
||||
{
|
||||
m_bundleArchive_FIELD = bundle.getClass().getDeclaredField("m_archive");
|
||||
m_bundleArchive_FIELD.setAccessible(true);
|
||||
}
|
||||
return m_bundleArchive_FIELD.get(bundle);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private static File getFelixBundleArchiveRootDir(Object bundleArchive)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_archiveRootDir_FIELD == null)
|
||||
{
|
||||
m_archiveRootDir_FIELD = bundleArchive.getClass().getDeclaredField("m_archiveRootDir");
|
||||
m_archiveRootDir_FIELD.setAccessible(true);
|
||||
}
|
||||
return (File)m_archiveRootDir_FIELD.get(bundleArchive);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private static String getFelixBundleArchiveCurrentLocation(Object bundleArchive)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_currentLocation_FIELD == null)
|
||||
{
|
||||
m_currentLocation_FIELD = bundleArchive.getClass().getDeclaredField("m_currentLocation");
|
||||
m_currentLocation_FIELD.setAccessible(true);
|
||||
}
|
||||
return (String)m_currentLocation_FIELD.get(bundleArchive);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue