Prune unused code; add more comments; rename classes.

This commit is contained in:
Jan Bartel 2013-04-11 14:23:36 +10:00
parent 9bb0260410
commit 6783975707
20 changed files with 229 additions and 309 deletions

View File

@ -30,25 +30,30 @@ import java.util.regex.Pattern;
import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration; import org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration;
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper; import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
import org.eclipse.jetty.osgi.boot.utils.WebappRegistrationCustomizer; import org.eclipse.jetty.osgi.boot.utils.TldBundleDiscoverer;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil; import org.osgi.framework.FrameworkUtil;
/** /**
* PluggableWebAppRegistrationCustomizerImpl * ContainerTldBundleDiscoverer
* *
* *
* Use a System property to define bundles that contain tlds that need to * Use a System property to define bundles that contain tlds that need to
* be treated by jasper as if they were on the jetty container's classpath. * be treated by jasper as if they were on the jetty container's classpath.
* *
* The value of the property is evaluated against the DeploymentManager
* context attribute "org.eclipse.jetty.server.webapp.containerIncludeBundlePattern",
* which defines a pattern of matching bundle names.
*
* The bundle locations are converted to URLs for jasper's use. * The bundle locations are converted to URLs for jasper's use.
* *
* Eg: * Eg:
* -Dorg.eclipse.jetty.osgi.tldbundles=org.springframework.web.servlet,com.opensymphony.module.sitemesh * -Dorg.eclipse.jetty.osgi.tldbundles=org.springframework.web.servlet,com.opensymphony.module.sitemesh
*
*/ */
public class PluggableWebAppRegistrationCustomizerImpl implements WebappRegistrationCustomizer public class ContainerTldBundleDiscoverer implements TldBundleDiscoverer
{ {
/** /**
* Comma separated list of names of bundles that contain tld files that should be * Comma separated list of names of bundles that contain tld files that should be
@ -66,7 +71,7 @@ public class PluggableWebAppRegistrationCustomizerImpl implements WebappRegistra
* *
* @return The location of the jars that contain tld files as URLs. * @return The location of the jars that contain tld files as URLs.
*/ */
public URL[] getJarsWithTlds(DeploymentManager deploymentManager, BundleFileLocatorHelper locatorHelper) throws Exception public URL[] getUrlsForBundlesWithTlds(DeploymentManager deploymentManager, BundleFileLocatorHelper locatorHelper) throws Exception
{ {
// naive way of finding those bundles. // naive way of finding those bundles.
// lots of assumptions: for example we assume a single version of each // lots of assumptions: for example we assume a single version of each
@ -77,7 +82,7 @@ public class PluggableWebAppRegistrationCustomizerImpl implements WebappRegistra
// probably using custom properties in the ContextHandler service // probably using custom properties in the ContextHandler service
// and mirroring those in the MANIFEST.MF // and mirroring those in the MANIFEST.MF
Bundle[] bundles = FrameworkUtil.getBundle(PluggableWebAppRegistrationCustomizerImpl.class).getBundleContext().getBundles(); Bundle[] bundles = FrameworkUtil.getBundle(ContainerTldBundleDiscoverer.class).getBundleContext().getBundles();
HashSet<URL> urls = new HashSet<URL>(); HashSet<URL> urls = new HashSet<URL>();
String tmp = System.getProperty(SYS_PROP_TLD_BUNDLES); //comma separated exact names String tmp = System.getProperty(SYS_PROP_TLD_BUNDLES); //comma separated exact names
List<String> sysNames = new ArrayList<String>(); List<String> sysNames = new ArrayList<String>();

View File

@ -34,7 +34,7 @@ import org.apache.jasper.xmlparser.ParserUtils;
import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator; import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator;
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper; import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
import org.eclipse.jetty.osgi.boot.utils.WebappRegistrationCustomizer; import org.eclipse.jetty.osgi.boot.utils.TldBundleDiscoverer;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
@ -45,19 +45,19 @@ import org.xml.sax.SAXException;
/** /**
* *
* WebappRegistrationCustomizerImpl * JSTLBundleDiscoverer
* *
* Fix various shortcomings with the way jasper parses the tld files. Plugs the * Fix various shortcomings with the way jasper parses the tld files. Plugs the
* JSTL tlds assuming that they are packaged with the bundle that contains the * JSTL tlds assuming that they are packaged with the bundle that contains the
* JSTL classes. * JSTL classes.
* <p> * <p>
* Pluggable tlds at the server level are handled by * Pluggable tlds at the server level are handled by
* {@link PluggableWebAppRegistrationCustomizerImpl}. * {@link ContainerTldBundleDiscoverer}.
* </p> * </p>
*/ */
public class WebappRegistrationCustomizerImpl implements WebappRegistrationCustomizer public class JSTLBundleDiscoverer implements TldBundleDiscoverer
{ {
private static final Logger LOG = Log.getLogger(WebappRegistrationCustomizerImpl.class); private static final Logger LOG = Log.getLogger(JSTLBundleDiscoverer.class);
/** /**
@ -86,7 +86,7 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
*/ */
private static String DEFAULT_JSP_FACTORY_IMPL_CLASS = "org.apache.jasper.runtime.JspFactoryImpl"; private static String DEFAULT_JSP_FACTORY_IMPL_CLASS = "org.apache.jasper.runtime.JspFactoryImpl";
public WebappRegistrationCustomizerImpl() public JSTLBundleDiscoverer()
{ {
fixupDtdResolution(); fixupDtdResolution();
@ -139,7 +139,7 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
* @return array of URLs * @return array of URLs
* @throws Exception * @throws Exception
*/ */
public URL[] getJarsWithTlds(DeploymentManager deployer, BundleFileLocatorHelper locatorHelper) throws Exception public URL[] getUrlsForBundlesWithTlds(DeploymentManager deployer, BundleFileLocatorHelper locatorHelper) throws Exception
{ {
ArrayList<URL> urls = new ArrayList<URL>(); ArrayList<URL> urls = new ArrayList<URL>();
@ -151,7 +151,7 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
// So we can look for this class using this bundle's classloader: // So we can look for this class using this bundle's classloader:
try try
{ {
Class<?> jstlClass = WebappRegistrationCustomizerImpl.class.getClassLoader().loadClass(DEFAULT_JSTL_BUNDLE_CLASS); Class<?> jstlClass = JSTLBundleDiscoverer.class.getClassLoader().loadClass(DEFAULT_JSTL_BUNDLE_CLASS);
classesToAddToTheTldBundles.add(jstlClass); classesToAddToTheTldBundles.add(jstlClass);
} }

View File

@ -19,21 +19,26 @@
package org.eclipse.jetty.osgi.boot.jsp; package org.eclipse.jetty.osgi.boot.jsp;
import org.eclipse.jetty.osgi.boot.BundleWebAppProvider; import org.eclipse.jetty.osgi.boot.BundleWebAppProvider;
import org.eclipse.jetty.osgi.boot.internal.webapp.WebBundleTrackerCustomizer; import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
import org.eclipse.jetty.osgi.boot.jasper.PluggableWebAppRegistrationCustomizerImpl; import org.eclipse.jetty.osgi.boot.jasper.ContainerTldBundleDiscoverer;
import org.eclipse.jetty.osgi.boot.jasper.WebappRegistrationCustomizerImpl; import org.eclipse.jetty.osgi.boot.jasper.JSTLBundleDiscoverer;
import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
/** /**
* Pseudo fragment activator. Called by the main org.eclipse.jetty.osgi.boot * FragmentActivator
* bundle. Please note: this is not a real BundleActivator. Simply something *
* called back by the host bundle. * Sets up support for jsp. All relevant jsp jars must also be installed
* <p> * into the osgi environment.
* It must be placed in the org.eclipse.jetty.osgi.boot.jsp package: this is * <p>
* because org.eclipse.jetty.osgi.boot.jsp is the symbolic-name of this * Note that as this is part of a bundle fragment, this activator is NOT
* fragment. From that name, the PackageadminTracker will call this class. IN a * called by the OSGi environment. Instead, the org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminTracker
* different package it won't be called. * simulates fragment activation and causes this class's start() method to
* be called.
* </p>
* <p>
* The package of this class MUST match the Bundle-SymbolicName of this fragment
* in order for the PackageAdminTracker to find it.
* </p> * </p>
*/ */
public class FragmentActivator implements BundleActivator public class FragmentActivator implements BundleActivator
@ -43,12 +48,14 @@ public class FragmentActivator implements BundleActivator
*/ */
public void start(BundleContext context) throws Exception public void start(BundleContext context) throws Exception
{ {
//jsr199 compilation does not work in osgi
System.setProperty("org.apache.jasper.compiler.disablejsr199", Boolean.TRUE.toString()); System.setProperty("org.apache.jasper.compiler.disablejsr199", Boolean.TRUE.toString());
WebBundleTrackerCustomizer.JSP_REGISTRATION_HELPERS.add(new WebappRegistrationCustomizerImpl());
WebBundleTrackerCustomizer.JSP_REGISTRATION_HELPERS.add(new PluggableWebAppRegistrationCustomizerImpl()); //set up some classes that will look for bundles with tlds that must be converted
//Put in the support for the tag libs //to urls and treated as if they are on the Jetty container's classpath so that
addTagLibSupport(); //jasper can deal with them
ServerInstanceWrapper.addContainerTldBundleDiscoverer(new JSTLBundleDiscoverer());
ServerInstanceWrapper.addContainerTldBundleDiscoverer(new ContainerTldBundleDiscoverer());
} }
/** /**
@ -58,12 +65,4 @@ public class FragmentActivator implements BundleActivator
{ {
} }
public void addTagLibSupport ()
{
String[] defaultConfigurations = new String[BundleWebAppProvider.getDefaultConfigurations().length+1];
System.arraycopy(BundleWebAppProvider.getDefaultConfigurations(), 0, defaultConfigurations, 0, BundleWebAppProvider.getDefaultConfigurations().length);
defaultConfigurations[defaultConfigurations.length-1] = "org.eclipse.jetty.osgi.boot.jsp.TagLibOSGiConfiguration";
BundleWebAppProvider.setDefaultConfigurations(defaultConfigurations);
}
} }

View File

@ -58,10 +58,9 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
public static String __defaultConfigurations[] = { public static String __defaultConfigurations[] = {
"org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration", "org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration", "org.eclipse.jetty.webapp.WebXmlConfiguration",
"org.eclipse.jetty.osgi.boot.OSGiMetaInfConfiguration", "org.eclipse.jetty.webapp.MetaInfConfiguration",
"org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.webapp.FragmentConfiguration",
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration"//, "org.eclipse.jetty.webapp.JettyWebXmlConfiguration"
//"org.eclipse.jetty.osgi.boot.jsp.TagLibOSGiConfiguration"
}; };
public static void setDefaultConfigurations (String[] defaultConfigs) public static void setDefaultConfigurations (String[] defaultConfigs)

View File

@ -18,13 +18,8 @@
package org.eclipse.jetty.osgi.boot; package org.eclipse.jetty.osgi.boot;
import java.util.Dictionary;
import java.util.Hashtable;
import org.eclipse.jetty.osgi.boot.internal.serverfactory.DefaultJettyAtJettyHomeHelper; 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.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.JettyContextHandlerServiceTracker;
import org.eclipse.jetty.osgi.boot.internal.webapp.WebBundleTrackerCustomizer; import org.eclipse.jetty.osgi.boot.internal.webapp.WebBundleTrackerCustomizer;
import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker; import org.eclipse.jetty.osgi.boot.utils.internal.PackageAdminServiceTracker;
@ -32,16 +27,11 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.WebAppContext;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration; import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.BundleTracker; import org.osgi.util.tracker.BundleTracker;
import org.osgi.util.tracker.ServiceTracker;
/** /**
* JettyBootstrapActivator * JettyBootstrapActivator

View File

@ -38,6 +38,7 @@ import org.osgi.framework.Bundle;
* Extension of standard Jetty MetaInfConfiguration class to handle OSGi bundle * Extension of standard Jetty MetaInfConfiguration class to handle OSGi bundle
* fragments that may also need to be scanned for META-INF info. * fragments that may also need to be scanned for META-INF info.
* *
* @deprecated
*/ */
public class OSGiMetaInfConfiguration extends MetaInfConfiguration public class OSGiMetaInfConfiguration extends MetaInfConfiguration
{ {

View File

@ -1,69 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.osgi.boot.internal.jsp;
import java.net.URL;
/**
* Add a classloader to the
* org.apache.jasper.compiler.TldLocatableURLClassloader. Hopefuly not
* necessary: still experimenting.
*
* @see TldLocatableURLClassloader
*/
public class TldLocatableURLClassloaderWithInsertedJettyClassloader extends TldLocatableURLClassloader
{
private ClassLoader _internalClassLoader;
/**
*
* @param osgiClassLoaderParent
* The parent classloader
* @param internalClassLoader
* The classloader that will be at the same level than the
* jarsWithTldsInside
* @param jarsWithTldsInside
* jars that are scanned for tld files.
*/
public TldLocatableURLClassloaderWithInsertedJettyClassloader(ClassLoader osgiClassLoaderParent, ClassLoader internalClassLoader, URL[] jarsWithTldsInside)
{
super(osgiClassLoaderParent,jarsWithTldsInside);
_internalClassLoader = internalClassLoader;
}
protected Class<?> findClass(String name) throws ClassNotFoundException
{
try
{
return super.findClass(name);
}
catch (ClassNotFoundException cne)
{
if (_internalClassLoader != null)
{
return _internalClassLoader.loadClass(name);
}
else
{
throw cne;
}
}
}
}

View File

@ -66,6 +66,7 @@ public class DefaultJettyAtJettyHomeHelper
public static final String DEFAULT_JETTYHOME = "/jettyhome/"; public static final String DEFAULT_JETTYHOME = "/jettyhome/";
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* Called by the JettyBootStrapActivator. If the system property jetty.home * Called by the JettyBootStrapActivator. If the system property jetty.home

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.osgi.boot.internal.serverfactory; package org.eclipse.jetty.osgi.boot.internal.serverfactory;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@ -27,8 +26,10 @@ import java.util.Collection;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.eclipse.jetty.deploy.AppLifeCycle; import org.eclipse.jetty.deploy.AppLifeCycle;
@ -44,11 +45,10 @@ import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
import org.eclipse.jetty.osgi.boot.OSGiUndeployer; import org.eclipse.jetty.osgi.boot.OSGiUndeployer;
import org.eclipse.jetty.osgi.boot.ServiceContextProvider; import org.eclipse.jetty.osgi.boot.ServiceContextProvider;
import org.eclipse.jetty.osgi.boot.ServiceWebAppProvider; import org.eclipse.jetty.osgi.boot.ServiceWebAppProvider;
import org.eclipse.jetty.osgi.boot.internal.jsp.TldLocatableURLClassloader;
import org.eclipse.jetty.osgi.boot.internal.webapp.BundleFileLocatorHelperFactory; import org.eclipse.jetty.osgi.boot.internal.webapp.BundleFileLocatorHelperFactory;
import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper; import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper;
import org.eclipse.jetty.osgi.boot.internal.webapp.WebBundleTrackerCustomizer; import org.eclipse.jetty.osgi.boot.utils.FakeURLClassLoader;
import org.eclipse.jetty.osgi.boot.utils.WebappRegistrationCustomizer; import org.eclipse.jetty.osgi.boot.utils.TldBundleDiscoverer;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
@ -72,6 +72,9 @@ public class ServerInstanceWrapper
* support the case where the bundle is zipped. * support the case where the bundle is zipped.
*/ */
public static final String PROPERTY_THIS_JETTY_XML_FOLDER_URL = "this.jetty.xml.parent.folder.url"; public static final String PROPERTY_THIS_JETTY_XML_FOLDER_URL = "this.jetty.xml.parent.folder.url";
private static Collection<TldBundleDiscoverer> __containerTldBundleDiscoverers = new ArrayList<TldBundleDiscoverer>();
private static Logger LOG = Log.getLogger(ServerInstanceWrapper.class.getName()); private static Logger LOG = Log.getLogger(ServerInstanceWrapper.class.getName());
@ -96,6 +99,21 @@ public class ServerInstanceWrapper
private DeploymentManager _deploymentManager; private DeploymentManager _deploymentManager;
/* ------------------------------------------------------------ */
public static void addContainerTldBundleDiscoverer (TldBundleDiscoverer tldBundleDiscoverer)
{
__containerTldBundleDiscoverers.add(tldBundleDiscoverer);
}
/* ------------------------------------------------------------ */
public static Collection<TldBundleDiscoverer> getContainerTldBundleDiscoverers()
{
return __containerTldBundleDiscoverers;
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public ServerInstanceWrapper(String managedServerName) public ServerInstanceWrapper(String managedServerName)
{ {
@ -173,9 +191,29 @@ public class ServerInstanceWrapper
configure(server, props); configure(server, props);
init(); init();
//if support for jsp is enabled, we need to convert locations of bundles that contain tlds into urls.
//these are tlds that we want jasper to treat as if they are on the container's classpath. Web bundles
//can use the Require-TldBundle MANIFEST header to name other tld-containing bundles that should be regarded
//as on the webapp classpath.
if (!__containerTldBundleDiscoverers.isEmpty())
{
Set<URL> urls = new HashSet<URL>();
//discover bundles with tlds that need to be on the container's classpath as URLs
for (TldBundleDiscoverer d:__containerTldBundleDiscoverers)
{
URL[] list = d.getUrlsForBundlesWithTlds(_deploymentManager, BundleFileLocatorHelperFactory.getFactory().getHelper());
if (list != null)
{
for (URL u:list)
urls.add(u);
}
}
_commonParentClassLoaderForWebapps = new FakeURLClassLoader(libExtClassLoader, urls.toArray(new URL[urls.size()]));
}
else
_commonParentClassLoaderForWebapps = libExtClassLoader;
URL[] jarsWithTlds = getJarsWithTlds();
_commonParentClassLoaderForWebapps = jarsWithTlds == null ? libExtClassLoader : new TldLocatableURLClassloader(libExtClassLoader, jarsWithTlds);
if (LOG.isDebugEnabled()) LOG.debug("common classloader = "+_commonParentClassLoaderForWebapps); if (LOG.isDebugEnabled()) LOG.debug("common classloader = "+_commonParentClassLoaderForWebapps);
@ -219,54 +257,7 @@ public class ServerInstanceWrapper
} }
/* ------------------------------------------------------------ */
/**
* TODO: right now only the jetty-jsp bundle is scanned for common taglibs.
* Should support a way to plug more bundles that contain taglibs.
*
* The jasper TldScanner expects a URLClassloader to parse a jar for the
* /META-INF/*.tld it may contain. We place the bundles that we know contain
* such tag-libraries. Please note that it will work if and only if the
* bundle is a jar (!) Currently we just hardcode the bundle that contains
* the jstl implementation.
*
* A workaround when the tld cannot be parsed with this method is to copy
* and paste it inside the WEB-INF of the webapplication where it is used.
*
* Support only 2 types of packaging for the bundle: - the bundle is a jar
* (recommended for runtime.) - the bundle is a folder and contain jars in
* the root and/or in the lib folder (nice for PDE development situations)
* Unsupported: the bundle is a jar that embeds more jars.
*
* @return
* @throws Exception
*/
private URL[] getJarsWithTlds() throws Exception
{
//Jars that are added onto the equivalent of the container classpath are:
// jstl jars: identified by the class WhenTag (and the boot-bundle manifest imports the jstl packages
// bundles identified by System property org.eclipse.jetty.osgi.tldbundles
// bundle symbolic name patterns defined in the DeploymentManager
//
// Any bundles mentioned in the Require-TldBundle manifest header of the webapp bundle MUST ALSO HAVE Import-Bundle
// in order to get them onto the classpath of the webapp.
ArrayList<URL> res = new ArrayList<URL>();
for (WebappRegistrationCustomizer regCustomizer : WebBundleTrackerCustomizer.JSP_REGISTRATION_HELPERS)
{
URL[] urls = regCustomizer.getJarsWithTlds(_deploymentManager, BundleFileLocatorHelperFactory.getFactory().getHelper());
for (URL url : urls)
{
if (!res.contains(url)) res.add(url);
}
}
if (!res.isEmpty())
return res.toArray(new URL[res.size()]);
else
return null;
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
private void configure(Server server, Dictionary props) throws Exception private void configure(Server server, Dictionary props) throws Exception
@ -340,7 +331,9 @@ public class ServerInstanceWrapper
} }
} }
/* ------------------------------------------------------------ */
/** /**
* Must be called after the server is configured. * Must be called after the server is configured.
* *
@ -438,7 +431,9 @@ public class ServerInstanceWrapper
} }
} }
} }
/* ------------------------------------------------------------ */
/** /**
* @return The default folder in which the context files of the osgi bundles * @return The default folder in which the context files of the osgi bundles
* are located and watched. Or null when the system property * are located and watched. Or null when the system property
@ -463,7 +458,7 @@ public class ServerInstanceWrapper
return new File(jettyHome, "/contexts"); return new File(jettyHome, "/contexts");
} }
/* ------------------------------------------------------------ */
/** /**
* @return the urls in this string. * @return the urls in this string.
*/ */
@ -485,7 +480,9 @@ public class ServerInstanceWrapper
} }
return urls; return urls;
} }
/* ------------------------------------------------------------ */
/** /**
* Get the folders that might contain jars for the legacy J2EE shared * Get the folders that might contain jars for the legacy J2EE shared
* libraries * libraries

View File

@ -1,88 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.osgi.boot.internal.webapp;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.webapp.WebAppContext;
import org.osgi.framework.Bundle;
/**
* Internal interface for the class that deploys a webapp on a server. Used as
* we migrate from the single instance of the jety server to multiple jetty
* servers.
*/
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.
*
* @param bundle The bundle
* @param webappFolderPath The path to the root of the webapp. Must be a
* path relative to bundle; either an absolute path.
* @param contextPath The context path. Must start with "/"
* @param extraClasspath
* @param overrideBundleInstallLocation
* @param requireTldBundle The list of bundles's symbolic names that contain
* tld files that are required by this WAB.
* @param webXmlPath
* @param defaultWebXmlPath TODO: parameter description
* @return The contexthandler created and started
* @throws Exception
*/
public abstract WebAppContext registerWebapplication(Bundle bundle, String webappFolderPath, String contextPath, String extraClasspath,
String overrideBundleInstallLocation, String requireTldBundle, String webXmlPath,
String defaultWebXmlPath, WebAppContext webAppContext) throws Exception;
/**
* Stop a ContextHandler and remove it from the collection.
*
* @see ContextDeployer#undeploy
* @param contextHandler
* @throws Exception
*/
public abstract void unregister(ContextHandler contextHandler) 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.
*
* @param contributor
* @param contextFileRelativePath
* @param extraClasspath
* @param overrideBundleInstallLocation
* @param requireTldBundle The list of bundles'symbolic name that contain
* tld files for this webapp.
* @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, String requireTldBundle, ContextHandler handler) throws Exception;
}

View File

@ -60,17 +60,23 @@ import org.eclipse.jetty.server.Server;
*/ */
public class LibExtClassLoaderHelper public class LibExtClassLoaderHelper
{ {
/* ------------------------------------------------------------ */
/** /**
* Class called back * IFilesInJettyHomeResourcesProcessor
*
* Interface for callback impls
*/ */
public interface IFilesInJettyHomeResourcesProcessor public interface IFilesInJettyHomeResourcesProcessor
{ {
void processFilesInResourcesFolder(File jettyHome, Map<String, File> filesInResourcesFolder); void processFilesInResourcesFolder(File jettyHome, Map<String, File> filesInResourcesFolder);
} }
public static Set<IFilesInJettyHomeResourcesProcessor> registeredFilesInJettyHomeResourcesProcessors = new HashSet<IFilesInJettyHomeResourcesProcessor>(); public static Set<IFilesInJettyHomeResourcesProcessor> registeredFilesInJettyHomeResourcesProcessors = new HashSet<IFilesInJettyHomeResourcesProcessor>();
/* ------------------------------------------------------------ */
/** /**
* @param server * @param server
* @return a url classloader with the jars of resources, lib/ext and the * @return a url classloader with the jars of resources, lib/ext and the
@ -125,6 +131,8 @@ public class LibExtClassLoaderHelper
return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader); return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader);
} }
/* ------------------------------------------------------------ */
/** /**
* @param server * @param server
* @return a url classloader with the jars of resources, lib/ext and the * @return a url classloader with the jars of resources, lib/ext and the
@ -168,6 +176,7 @@ public class LibExtClassLoaderHelper
return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader); return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader);
} }
/* ------------------------------------------------------------ */
/** /**
* When we find files typically used for central logging configuration we do * When we find files typically used for central logging configuration we do
* what it takes in this method to do what the user expects. Without * what it takes in this method to do what the user expects. Without

View File

@ -80,7 +80,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
private boolean _lookInOsgiFirst = true; private boolean _lookInOsgiFirst = true;
/* ------------------------------------------------------------ */
/** /**
* @param parent The parent classloader. * @param parent The parent classloader.
* @param context The WebAppContext * @param context The WebAppContext
@ -94,7 +94,10 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
_contributor = contributor; _contributor = contributor;
_osgiBundleClassLoader = BundleClassLoaderHelperFactory.getFactory().getHelper().getBundleClassLoader(contributor); _osgiBundleClassLoader = BundleClassLoaderHelperFactory.getFactory().getHelper().getBundleClassLoader(contributor);
} }
/* ------------------------------------------------------------ */
/** /**
* Returns the <code>Bundle</code> that defined this web-application. * Returns the <code>Bundle</code> that defined this web-application.
* *
@ -106,7 +109,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
return _contributor; return _contributor;
} }
/* ------------------------------------------------------------ */
@Override @Override
public Enumeration<URL> getResources(String name) throws IOException public Enumeration<URL> getResources(String name) throws IOException
{ {
@ -121,7 +124,10 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
return Collections.enumeration(toList(urls, osgiUrls)); return Collections.enumeration(toList(urls, osgiUrls));
} }
} }
/* ------------------------------------------------------------ */
@Override @Override
public URL getResource(String name) public URL getResource(String name)
{ {
@ -136,7 +142,10 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
return url != null ? url : _osgiBundleClassLoader.getResource(name); return url != null ? url : _osgiBundleClassLoader.getResource(name);
} }
} }
/* ------------------------------------------------------------ */
private List<URL> toList(Enumeration<URL> e, Enumeration<URL> e2) private List<URL> toList(Enumeration<URL> e, Enumeration<URL> e2)
{ {
List<URL> list = new ArrayList<URL>(); List<URL> list = new ArrayList<URL>();
@ -147,9 +156,8 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
return list; return list;
} }
/**
* /* ------------------------------------------------------------ */
*/
protected Class<?> findClass(String name) throws ClassNotFoundException protected Class<?> findClass(String name) throws ClassNotFoundException
{ {
try try
@ -168,7 +176,10 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
} }
} }
} }
/* ------------------------------------------------------------ */
/** /**
* Parse the classpath ourselves to be able to filter things. This is a * Parse the classpath ourselves to be able to filter things. This is a
* derivative work of the super class * derivative work of the super class
@ -197,6 +208,8 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
} }
/* ------------------------------------------------------------ */
/** /**
* @param lib * @param lib
* @return true if the lib should be included in the webapp classloader. * @return true if the lib should be included in the webapp classloader.
@ -245,6 +258,8 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe
private static Field _contextField; private static Field _contextField;
/* ------------------------------------------------------------ */
/** /**
* In the case of the generation of a webapp via a jetty context file we * In the case of the generation of a webapp via a jetty context file we
* need a proper classloader to setup the app before we have the * need a proper classloader to setup the app before we have the

View File

@ -28,7 +28,7 @@ import java.util.Map.Entry;
import org.eclipse.jetty.osgi.boot.BundleProvider; import org.eclipse.jetty.osgi.boot.BundleProvider;
import org.eclipse.jetty.osgi.boot.OSGiServerConstants; import org.eclipse.jetty.osgi.boot.OSGiServerConstants;
import org.eclipse.jetty.osgi.boot.utils.WebappRegistrationCustomizer; import org.eclipse.jetty.osgi.boot.utils.TldBundleDiscoverer;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
@ -53,7 +53,7 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer
{ {
private static final Logger LOG = Log.getLogger(WebBundleTrackerCustomizer.class); private static final Logger LOG = Log.getLogger(WebBundleTrackerCustomizer.class);
public static Collection<WebappRegistrationCustomizer> JSP_REGISTRATION_HELPERS = new ArrayList<WebappRegistrationCustomizer>(); public static Collection<TldBundleDiscoverer> JSP_REGISTRATION_HELPERS = new ArrayList<TldBundleDiscoverer>();
public static final String FILTER = "(objectclass=" + BundleProvider.class.getName() + ")"; public static final String FILTER = "(objectclass=" + BundleProvider.class.getName() + ")";
@ -78,24 +78,28 @@ public class WebBundleTrackerCustomizer implements BundleTrackerCustomizer
} }
/* ------------------------------------------------------------ */
public boolean isWaitForDefaultServer() public boolean isWaitForDefaultServer()
{ {
return _waitForDefaultServer; return _waitForDefaultServer;
} }
/* ------------------------------------------------------------ */
public void setWaitForDefaultServer(boolean waitForDefaultServer) public void setWaitForDefaultServer(boolean waitForDefaultServer)
{ {
_waitForDefaultServer = waitForDefaultServer; _waitForDefaultServer = waitForDefaultServer;
} }
/* ------------------------------------------------------------ */
public void setBundleTracker (BundleTracker bundleTracker) public void setBundleTracker (BundleTracker bundleTracker)
{ {
_bundleTracker = bundleTracker; _bundleTracker = bundleTracker;
} }
/* ------------------------------------------------------------ */
public void open () throws Exception public void open () throws Exception
{ {
if (_waitForDefaultServer && !_defaultServerReady) if (_waitForDefaultServer && !_defaultServerReady)

View File

@ -22,6 +22,10 @@ import org.eclipse.jetty.osgi.boot.utils.internal.DefaultBundleClassLoaderHelper
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
/** /**
*
* BundleClassLoaderHelper
*
*
* Is there a clean OSGi way to go from the Bundle object to the classloader of * Is there a clean OSGi way to go from the Bundle object to the classloader of
* the Bundle ? You can certainly take a class inside the bundle and get the * the Bundle ? You can certainly take a class inside the bundle and get the
* bundle's classloader that way. Getting the classloader directly from the * bundle's classloader that way. Getting the classloader directly from the

View File

@ -32,15 +32,19 @@ public class BundleClassLoaderHelperFactory
private static BundleClassLoaderHelperFactory _instance = new BundleClassLoaderHelperFactory(); private static BundleClassLoaderHelperFactory _instance = new BundleClassLoaderHelperFactory();
/* ------------------------------------------------------------ */
public static BundleClassLoaderHelperFactory getFactory() public static BundleClassLoaderHelperFactory getFactory()
{ {
return _instance; return _instance;
} }
/* ------------------------------------------------------------ */
private BundleClassLoaderHelperFactory() private BundleClassLoaderHelperFactory()
{ {
} }
/* ------------------------------------------------------------ */
public BundleClassLoaderHelper getHelper() public BundleClassLoaderHelper getHelper()
{ {
//use the default //use the default

View File

@ -26,6 +26,9 @@ import org.eclipse.jetty.osgi.boot.utils.internal.DefaultFileLocatorHelper;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
/** /**
* BundleFileLocatorHelper
*
*
* From a bundle to its location on the filesystem. Assumes the bundle is not a * From a bundle to its location on the filesystem. Assumes the bundle is not a
* jar. * jar.
* *

View File

@ -21,14 +21,18 @@ package org.eclipse.jetty.osgi.boot.utils;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Hashtable; import java.util.Hashtable;
import javax.security.auth.login.FailedLoginException;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil; import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceReference;
import org.osgi.service.event.Event; import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin; import org.osgi.service.event.EventAdmin;
/**
* EventSender
*
* Utility class for emiting OSGi EventAdmin events
*
*/
public class EventSender public class EventSender
{ {
//OSGi Event Admin events for webapps //OSGi Event Admin events for webapps
@ -43,6 +47,13 @@ public class EventSender
private Bundle _myBundle; private Bundle _myBundle;
private EventAdmin _eventAdmin; private EventAdmin _eventAdmin;
/* ------------------------------------------------------------ */
/**
*
*/
private EventSender () private EventSender ()
{ {
_myBundle = FrameworkUtil.getBundle(EventSender.class); _myBundle = FrameworkUtil.getBundle(EventSender.class);
@ -50,13 +61,27 @@ public class EventSender
if (ref != null) if (ref != null)
_eventAdmin = (EventAdmin)_myBundle.getBundleContext().getService(ref); _eventAdmin = (EventAdmin)_myBundle.getBundleContext().getService(ref);
} }
/* ------------------------------------------------------------ */
/**
* @return
*/
public static EventSender getInstance() public static EventSender getInstance()
{ {
return __instance; return __instance;
} }
/* ------------------------------------------------------------ */
/**
* @param topic
* @param wab
* @param contextPath
*/
public void send (String topic, Bundle wab, String contextPath) public void send (String topic, Bundle wab, String contextPath)
{ {
if (topic==null || wab==null || contextPath==null) if (topic==null || wab==null || contextPath==null)
@ -66,6 +91,14 @@ public class EventSender
} }
/* ------------------------------------------------------------ */
/**
* @param topic
* @param wab
* @param contextPath
* @param ex
*/
public void send (String topic, Bundle wab, String contextPath, Exception ex) public void send (String topic, Bundle wab, String contextPath, Exception ex)
{ {
if (_eventAdmin == null) if (_eventAdmin == null)

View File

@ -16,29 +16,42 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.osgi.boot.internal.jsp; package org.eclipse.jetty.osgi.boot.utils;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
/** /**
* Tricky url classloader. In fact we don't want a real URLClassLoader: we want *
* OSGi to provide its classloader and let it does. But to let * FakeURLClassLoader
* {@link org.apache.jasper.compiler.TldLocationsCache} find the core tlds *
* inside the jars we must be a URLClassLoader that returns an array of jars * A URLClassloader that overrides the getURLs() method to return the list
* where tlds are stored when the method getURLs is called. * of urls passed in to the constructor, but otherwise acts as if it has no
* urls, which would cause it to delegate to the parent classloader (in this
* case an OSGi classloader).
*
* The main use of this class is with jars containing tlds. Jasper expects a
* URL classloader to inspect for jars with tlds.
*
*/ */
public class TldLocatableURLClassloader extends URLClassLoader public class FakeURLClassLoader extends URLClassLoader
{ {
private URL[] _jarsWithTldsInside; private URL[] _jars;
public TldLocatableURLClassloader(ClassLoader osgiClassLoader, URL[] jarsWithTldsInside)
/* ------------------------------------------------------------ */
/**
* @param osgiClassLoader
* @param jars
*/
public FakeURLClassLoader(ClassLoader osgiClassLoader, URL[] jars)
{ {
super(new URL[] {},osgiClassLoader); super(new URL[] {},osgiClassLoader);
_jarsWithTldsInside = jarsWithTldsInside; _jars = jars;
} }
/* ------------------------------------------------------------ */
/** /**
* @return the jars that contains tlds so that TldLocationsCache or * @return the jars that contains tlds so that TldLocationsCache or
* TldScanner can find them. * TldScanner can find them.
@ -46,16 +59,21 @@ public class TldLocatableURLClassloader extends URLClassLoader
@Override @Override
public URL[] getURLs() public URL[] getURLs()
{ {
return _jarsWithTldsInside; return _jars;
} }
/* ------------------------------------------------------------ */
/**
* @see java.lang.Object#toString()
*/
public String toString() public String toString()
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
if (_jarsWithTldsInside != null) if (_jars != null)
{ {
for (URL u:_jarsWithTldsInside) for (URL u:_jars)
builder.append(" "+u.toString()); builder.append(" "+u.toString());
return builder.toString(); return builder.toString();
} }

View File

@ -24,20 +24,12 @@ import org.eclipse.jetty.deploy.DeploymentManager;
/** /**
* WebappRegistrationCustomizer * TldBundleDiscoverer
* *
* Convert bundles that contain tlds into URL locations for consumption by jasper. * Convert bundles that contain tlds into URL locations for consumption by jasper.
*/ */
public interface WebappRegistrationCustomizer public interface TldBundleDiscoverer
{ {
/**
* we could do something a lot more pluggable with a custom header in the
* manifest or some customer declarative services let's keep it simple for
* now. hopefully the rest of the world won't need to customize this.
*/
public static final String CLASS_NAME = "org.eclipse.jetty.osgi.boot.jasper.WebappRegistrationCustomizerImpl";
/** /**
* Find bundles that contain tlds and convert into URL references to their location. * Find bundles that contain tlds and convert into URL references to their location.
* *
@ -46,6 +38,6 @@ public interface WebappRegistrationCustomizer
* @return array of URLs representing locations of tld containing bundles * @return array of URLs representing locations of tld containing bundles
* @throws Exception * @throws Exception
*/ */
URL[] getJarsWithTlds(DeploymentManager manager, BundleFileLocatorHelper fileLocator) throws Exception; URL[] getUrlsForBundlesWithTlds(DeploymentManager manager, BundleFileLocatorHelper fileLocator) throws Exception;
} }

View File

@ -39,7 +39,10 @@ import org.osgi.service.startlevel.StartLevel;
* *
* *
* When the PackageAdmin service is activated we can look for the fragments * When the PackageAdmin service is activated we can look for the fragments
* attached to this bundle and "activate" them. * attached to this bundle and do a fake "activate" on them.
*
* See particularly the jetty-osgi-boot-jsp fragment bundle that uses this
* facility.
*/ */
public class PackageAdminServiceTracker implements ServiceListener public class PackageAdminServiceTracker implements ServiceListener
{ {