cleaned the workaround now that bug 294799 is fixed. added to OSGiAppProvieder the same parameters that WebAppProvider for configuration of WebAppContext
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1201 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
8cd60cd604
commit
fdaa364ee4
|
@ -80,24 +80,6 @@ public class WebAppProvider extends ScanningAppProvider
|
|||
setScanInterval(0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the extractWars.
|
||||
* @return the extractWars
|
||||
*/
|
||||
public boolean isExtractWars()
|
||||
{
|
||||
return _extractWars;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set the extractWars.
|
||||
* @param extractWars the extractWars to set
|
||||
*/
|
||||
public void setExtractWars(boolean extractWars)
|
||||
{
|
||||
_extractWars = extractWars;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the parentLoaderPriority.
|
||||
* @return the parentLoaderPriority
|
||||
|
|
|
@ -41,14 +41,15 @@ public class WebappRegistrationCustomizerImpl implements WebappRegistrationCusto
|
|||
public WebappRegistrationCustomizerImpl()
|
||||
{
|
||||
fixupDtdResolution();
|
||||
//sanity check:
|
||||
try
|
||||
{
|
||||
Class cl = getClass().getClassLoader().loadClass("org.apache.jasper.servlet.JspServlet");
|
||||
System.err.println("found the jsp servlet: " + cl.getName());
|
||||
//System.err.println("found the jsp servlet: " + cl.getName());
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
System.err.println("Unable to locate the JspServlet: jsp support unavailable.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
|||
import org.eclipse.jetty.deploy.App;
|
||||
import org.eclipse.jetty.deploy.AppProvider;
|
||||
import org.eclipse.jetty.deploy.DeploymentManager;
|
||||
import org.eclipse.jetty.deploy.providers.ContextProvider;
|
||||
import org.eclipse.jetty.deploy.providers.ScanningAppProvider;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -44,6 +45,10 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
|
||||
{
|
||||
|
||||
private boolean _extractWars = false;
|
||||
private boolean _parentLoaderPriority = false;
|
||||
private String _defaultsDescriptor;
|
||||
|
||||
/**
|
||||
* When a context file corresponds to a deployed bundle and is changed we
|
||||
* reload the corresponding bundle.
|
||||
|
@ -79,15 +84,25 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
|
|||
return null;
|
||||
}
|
||||
|
||||
public OSGiAppProvider(File contextsDir) {
|
||||
/**
|
||||
* Default OSGiAppProvider consutructed when none are defined in the jetty.xml
|
||||
* configuration.
|
||||
* @param contextsDir
|
||||
*/
|
||||
public OSGiAppProvider() {
|
||||
super(new Filter());
|
||||
((Filter)super._filenameFilter)._enclosedInstance = this;
|
||||
try {
|
||||
setMonitoredDir(Resource.newResource(contextsDir.toURI()));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default OSGiAppProvider consutructed when none are defined in the jetty.xml
|
||||
* configuration.
|
||||
* @param contextsDir
|
||||
*/
|
||||
public OSGiAppProvider(File contextsDir) throws IOException {
|
||||
this();
|
||||
setMonitoredDir(Resource.newResource(contextsDir.toURI()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,5 +191,113 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
|
|||
}
|
||||
}
|
||||
|
||||
////copied from WebAppProvider as the parameters are identical.
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the extractWars.
|
||||
* @return the extractWars
|
||||
*/
|
||||
public boolean isExtractWars()
|
||||
{
|
||||
return _extractWars;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set the extractWars.
|
||||
* @param extractWars the extractWars to set
|
||||
*/
|
||||
public void setExtractWars(boolean extractWars)
|
||||
{
|
||||
_extractWars = extractWars;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the parentLoaderPriority.
|
||||
* @return the parentLoaderPriority
|
||||
*/
|
||||
public boolean isParentLoaderPriority()
|
||||
{
|
||||
return _parentLoaderPriority;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set the parentLoaderPriority.
|
||||
* @param parentLoaderPriority the parentLoaderPriority to set
|
||||
*/
|
||||
public void setParentLoaderPriority(boolean parentLoaderPriority)
|
||||
{
|
||||
_parentLoaderPriority = parentLoaderPriority;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the defaultsDescriptor.
|
||||
* @return the defaultsDescriptor
|
||||
*/
|
||||
public String getDefaultsDescriptor()
|
||||
{
|
||||
return _defaultsDescriptor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set the defaultsDescriptor.
|
||||
* @param defaultsDescriptor the defaultsDescriptor to set
|
||||
*/
|
||||
public void setDefaultsDescriptor(String defaultsDescriptor)
|
||||
{
|
||||
_defaultsDescriptor = defaultsDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* The context xml directory.
|
||||
* In fact it is the directory watched by the scanner.
|
||||
*/
|
||||
public File getContextXmlDirAsFile()
|
||||
{
|
||||
try {
|
||||
Resource monitoredDir = getMonitoredDir();
|
||||
if (monitoredDir == null)
|
||||
return null;
|
||||
return monitoredDir.getFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* The context xml directory.
|
||||
* In fact it is the directory watched by the scanner.
|
||||
*/
|
||||
public String getContextXmlDir()
|
||||
{
|
||||
try {
|
||||
Resource monitoredDir = getMonitoredDir();
|
||||
if (monitoredDir == null)
|
||||
return null;
|
||||
return monitoredDir.getFile().toURI().toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the directory in which to look for context XML files.
|
||||
* <p>
|
||||
* If a webapp call "foo/" or "foo.war" is discovered in the monitored
|
||||
* directory, then the ContextXmlDir is examined to see if a foo.xml
|
||||
* file exists. If it does, then this deployer will not deploy the webapp
|
||||
* and the ContextProvider should be used to act on the foo.xml file.
|
||||
* @see ContextProvider
|
||||
* @param contextsDir
|
||||
*/
|
||||
public void setContextXmlDir(String contextsDir)
|
||||
{
|
||||
setMonitoredDir(contextsDir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.FileInputStream;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
@ -32,7 +31,9 @@ import java.util.jar.JarFile;
|
|||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.eclipse.jetty.deploy.AppProvider;
|
||||
import org.eclipse.jetty.deploy.ContextDeployer;
|
||||
import org.eclipse.jetty.deploy.DeploymentManager;
|
||||
import org.eclipse.jetty.deploy.WebAppDeployer;
|
||||
import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiAppProvider;
|
||||
import org.eclipse.jetty.osgi.boot.OSGiWebappConstants;
|
||||
|
@ -50,12 +51,9 @@ import org.eclipse.jetty.server.handler.DefaultHandler;
|
|||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.RequestLogHandler;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.util.AttributesMap;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
@ -382,9 +380,18 @@ class WebappRegistrationHelper
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (_provider == null) {
|
||||
if (_provider == null)
|
||||
{
|
||||
//create it on the fly with reasonable default values.
|
||||
_provider = new OSGiAppProvider(getOSGiContextsHome());
|
||||
try
|
||||
{
|
||||
_provider = new OSGiAppProvider();
|
||||
_provider.setMonitoredDir(
|
||||
Resource.newResource(getDefaultOSGiContextsHome(
|
||||
new File(System.getProperty("jetty.home"))).toURI()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
_deploymentManager.addAppProvider(_provider);
|
||||
}
|
||||
}
|
||||
|
@ -442,6 +449,7 @@ class WebappRegistrationHelper
|
|||
|
||||
/**
|
||||
* @See {@link WebAppDeployer#scan()}
|
||||
* TODO: refacotr this into the createContext method of OSGiAppProvider.
|
||||
*
|
||||
* @param webapp
|
||||
* @param contextPath
|
||||
|
@ -461,93 +469,11 @@ class WebappRegistrationHelper
|
|||
// make sure we provide access to all the jetty bundles by going
|
||||
// through this bundle.
|
||||
OSGiWebappClassLoader composite = createWebappClassLoader(contributor);
|
||||
// configure with access to all jetty classes and also all the
|
||||
// classes
|
||||
// configure with access to all jetty classes and also all the classes
|
||||
// that the contributor gives access to.
|
||||
Thread.currentThread().setContextClassLoader(composite);
|
||||
|
||||
// final WebXmlConfiguration webXml = new WebXmlConfiguration();
|
||||
// webXml.configure(context);
|
||||
|
||||
final JettyWebXmlConfiguration jettyXml = new JettyWebXmlConfiguration()
|
||||
{
|
||||
// workaround for
|
||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294799
|
||||
// remove it when it is fixed.
|
||||
/**
|
||||
* Configure Apply web-jetty.xml configuration
|
||||
*
|
||||
* @see Configuration#configure(WebAppContext)
|
||||
*/
|
||||
public void configure(WebAppContext context) throws Exception
|
||||
{
|
||||
// cannot configure if the _context is already started
|
||||
if (context.isStarted())
|
||||
{
|
||||
if (Log.isDebugEnabled())
|
||||
{
|
||||
Log.debug("Cannot configure webapp after it is started");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Log.isDebugEnabled())
|
||||
Log.debug("Configuring web-jetty.xml");
|
||||
|
||||
Resource web_inf = context.getWebInf();
|
||||
// handle any WEB-INF descriptors
|
||||
if (web_inf != null && web_inf.isDirectory())
|
||||
{
|
||||
// do jetty.xml file
|
||||
Resource jetty = web_inf.addPath("jetty7-web.xml");
|
||||
if (!jetty.exists())
|
||||
jetty = web_inf.addPath("jetty-web.xml");
|
||||
if (!jetty.exists())
|
||||
jetty = web_inf.addPath("web-jetty.xml");
|
||||
|
||||
if (jetty.exists())
|
||||
{
|
||||
// No server classes while configuring
|
||||
String[] old_server_classes = context.getServerClasses();
|
||||
try
|
||||
{
|
||||
context.setServerClasses(null);
|
||||
if (Log.isDebugEnabled())
|
||||
Log.debug("Configure: " + jetty);
|
||||
XmlConfiguration jetty_config = new XmlConfiguration(jetty.getURL());
|
||||
jetty_config.configure(context);
|
||||
// jetty_config.getProperties().add("jetty.home", );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (context.getServerClasses() == null)
|
||||
context.setServerClasses(old_server_classes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
// jettyXml.configure(context);
|
||||
|
||||
context = new WebAppContext(webapp.getAbsolutePath(),contextPath)
|
||||
{
|
||||
@Override
|
||||
protected void loadConfigurations() throws Exception
|
||||
{
|
||||
super.loadConfigurations();
|
||||
// now replace the default JettyWebXmlConfiguration by our
|
||||
// own.
|
||||
for (int i = 0; i < getConfigurations().length; i++)
|
||||
{
|
||||
if (getConfigurations()[i] instanceof JettyWebXmlConfiguration)
|
||||
{
|
||||
getConfigurations()[i] = jettyXml;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
context = new WebAppContext(webapp.getAbsolutePath(),contextPath);
|
||||
context.setExtraClasspath(extraClasspath);
|
||||
|
||||
if (webXmlPath != null && webXmlPath.length() != 0)
|
||||
|
@ -567,6 +493,11 @@ class WebappRegistrationHelper
|
|||
}
|
||||
}
|
||||
|
||||
if (defaultWebXmlPath == null || defaultWebXmlPath.length() == 0)
|
||||
{
|
||||
//use the one defined by the OSGiAppProvider.
|
||||
defaultWebXmlPath = _provider.getDefaultsDescriptor();
|
||||
}
|
||||
if (defaultWebXmlPath != null && defaultWebXmlPath.length() != 0)
|
||||
{
|
||||
File defaultWebXml = null;
|
||||
|
@ -583,14 +514,11 @@ class WebappRegistrationHelper
|
|||
context.setDefaultsDescriptor(defaultWebXml.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
//other parameters that might be defines on the OSGiAppProvider:
|
||||
context.setParentLoaderPriority(_provider.isParentLoaderPriority());
|
||||
|
||||
configureWebAppContext(context,contributor);
|
||||
|
||||
// ok now register this webapp. we checked when we started jetty
|
||||
// that there
|
||||
// was at least one such handler for webapps.
|
||||
// _ctxtHandler.addHandler(context);
|
||||
|
||||
configureWebappClassLoader(contributor,context,composite);
|
||||
|
||||
// @see
|
||||
|
@ -600,7 +528,7 @@ class WebappRegistrationHelper
|
|||
// through the webapp classloader.
|
||||
oldServerClasses = context.getServerClasses();
|
||||
context.setServerClasses(null);
|
||||
_provider.addContext(context);//context.start();//we don't start the context ourselves anymore.
|
||||
_provider.addContext(context);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
@ -629,11 +557,13 @@ class WebappRegistrationHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* @return The folder in which the context files of the osgi bundles are
|
||||
* located and watched. Or null when the system property
|
||||
* @return The default folder in which the context files of the osgi bundles
|
||||
* are located and watched. Or null when the system property
|
||||
* "jetty.osgi.contexts.home" is not defined.
|
||||
* If the configuration file defines the OSGiAppProvider's context.
|
||||
* This will not be taken into account.
|
||||
*/
|
||||
File getOSGiContextsHome()
|
||||
File getDefaultOSGiContextsHome(File jettyHome)
|
||||
{
|
||||
String jettyContextsHome = System.getProperty("jetty.osgi.contexts.home");
|
||||
if (jettyContextsHome != null)
|
||||
|
@ -645,7 +575,12 @@ class WebappRegistrationHelper
|
|||
}
|
||||
return contextsHome;
|
||||
}
|
||||
return new File(System.getProperty("jetty.home") + "/contexts");
|
||||
return new File(jettyHome, "/contexts");
|
||||
}
|
||||
|
||||
File getOSGiContextsHome()
|
||||
{
|
||||
return _provider.getContextXmlDirAsFile();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -661,7 +596,7 @@ class WebappRegistrationHelper
|
|||
public ContextHandler registerContext(Bundle contributor, String contextFileRelativePath, String extraClasspath, String overrideBundleInstallLocation)
|
||||
throws Exception
|
||||
{
|
||||
File contextsHome = getOSGiContextsHome();
|
||||
File contextsHome = _provider.getContextXmlDirAsFile();
|
||||
if (contextsHome != null)
|
||||
{
|
||||
File prodContextFile = new File(contextsHome,contributor.getSymbolicName() + "/" + contextFileRelativePath);
|
||||
|
|
Loading…
Reference in New Issue