mirror of
https://github.com/jetty/jetty.project.git
synced 2025-02-28 19:09:10 +00:00
320073 template deployments
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2203 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
a93c6445e1
commit
16caeeb478
23
jetty-deploy/src/main/config/etc/jetty-contexts.xml
Normal file
23
jetty-deploy/src/main/config/etc/jetty-contexts.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Add a ContextProvider to the deployment manager -->
|
||||
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
|
||||
<!-- This scans the webapps directory for war files and directories -->
|
||||
<!-- to deploy. -->
|
||||
<!-- This configuration must be used with jetty-deploy.xml, which -->
|
||||
<!-- creates the deployment manager instance -->
|
||||
<!-- =============================================================== -->
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<Ref id="DeploymentManager">
|
||||
<Call name="addAppProvider">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.ContextProvider">
|
||||
<Set name="monitoredDir"><Property name="jetty.home" default="." />/contexts</Set>
|
||||
<Set name="scanInterval">1</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Ref>
|
||||
</Configure>
|
@ -2,18 +2,18 @@
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the Jetty Deployers -->
|
||||
<!-- Create the deployment manager -->
|
||||
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
|
||||
<!-- The deplyment manager handles the lifecycle of deploying web -->
|
||||
<!-- applications. Apps are provided by instances of the -->
|
||||
<!-- AppProvider interface. Typically these are provided by -->
|
||||
<!-- one or more of: -->
|
||||
<!-- jetty-webapps.xml - monitors webapps for wars and dirs -->
|
||||
<!-- jetty-contexts.xml - monitors contexts for context xml -->
|
||||
<!-- jetty-templates.xml - monitors contexts and templates -->
|
||||
<!-- =============================================================== -->
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Configure the deployment manager -->
|
||||
<!-- -->
|
||||
<!-- Sets up 2 monitored dir app providers that are configured -->
|
||||
<!-- to behave in a similaraly to the legacy ContextDeployer -->
|
||||
<!-- and WebAppDeployer from previous versions of Jetty. -->
|
||||
<!-- =========================================================== -->
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
|
||||
@ -24,28 +24,6 @@
|
||||
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
|
||||
<Arg>.*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$</Arg>
|
||||
</Call>
|
||||
<!-- Providers of Apps via Context XML files.
|
||||
Configured to behave similar to the legacy ContextDeployer -->
|
||||
<Call name="addAppProvider">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.ContextProvider">
|
||||
<Set name="monitoredDir"><Property name="jetty.home" default="." />/contexts</Set>
|
||||
<Set name="scanInterval">5</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
<!-- Providers of Apps via WAR file existence.
|
||||
Configured to behave similar to the legacy WebAppDeployer -->
|
||||
<Call name="addAppProvider">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||
<Set name="monitoredDir"><Property name="jetty.home" default="." />/webapps</Set>
|
||||
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
||||
<Set name="scanInterval">5</Set>
|
||||
<Set name="contextXmlDir"><Property name="jetty.home" default="." />/contexts</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
26
jetty-deploy/src/main/config/etc/jetty-webapps.xml
Normal file
26
jetty-deploy/src/main/config/etc/jetty-webapps.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Add a WebAppProvider to the deployment manager -->
|
||||
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
|
||||
<!-- This scans the webapps directory for war files and directories -->
|
||||
<!-- to deploy. -->
|
||||
<!-- This configuration must be used with jetty-deploy.xml, which -->
|
||||
<!-- creates the deployment manager instance -->
|
||||
<!-- =============================================================== -->
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<Ref id="DeploymentManager">
|
||||
<Call name="addAppProvider">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||
<Set name="monitoredDir"><Property name="jetty.home" default="." />/webapps</Set>
|
||||
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
||||
<Set name="scanInterval">1</Set>
|
||||
<Set name="contextXmlDir"><Property name="jetty.home" default="." />/contexts</Set>
|
||||
<Set name="extractWars">false</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Ref>
|
||||
</Configure>
|
@ -22,5 +22,5 @@ import java.util.Map;
|
||||
*/
|
||||
public interface ConfigurationManager
|
||||
{
|
||||
public Map<String, ?> getProperties();
|
||||
public Map<String, Object> getProperties();
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import java.io.FilenameFilter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.deploy.providers.MonitoredDirAppProvider;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
@ -70,6 +69,7 @@ import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
* a configurable interval."
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated
|
||||
public class ContextDeployer extends AbstractLifeCycle
|
||||
{
|
||||
private int _scanInterval=10;
|
||||
@ -82,6 +82,7 @@ public class ContextDeployer extends AbstractLifeCycle
|
||||
private boolean _recursive = false;
|
||||
private AttributesMap _contextAttributes = new AttributesMap();
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected class ScannerListener implements Scanner.DiscreteListener
|
||||
{
|
||||
@ -126,6 +127,7 @@ public class ContextDeployer extends AbstractLifeCycle
|
||||
*/
|
||||
public ContextDeployer()
|
||||
{
|
||||
Log.warn("ContextDeployer is deprecated. Use ContextProvider");
|
||||
_scanner=new Scanner();
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ public class DeploymentManager extends AbstractLifeCycle
|
||||
|
||||
private final List<AppProvider> _providers = new ArrayList<AppProvider>();
|
||||
private final AppLifeCycle _lifecycle = new AppLifeCycle();
|
||||
private final LinkedList<AppEntry> _apps = new LinkedList<AppEntry>();
|
||||
private final List<AppEntry> _apps = new LinkedList<AppEntry>();
|
||||
private AttributesMap _contextAttributes = new AttributesMap();
|
||||
private ContextHandlerCollection _contexts;
|
||||
private boolean _useStandardBindings = true;
|
||||
|
@ -44,7 +44,7 @@ public class FileConfigurationManager implements ConfigurationManager
|
||||
/**
|
||||
* @see org.eclipse.jetty.deploy.ConfigurationManager#getProperties()
|
||||
*/
|
||||
public Map<String, ?> getProperties()
|
||||
public Map<String, Object> getProperties()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -59,7 +59,7 @@ public class FileConfigurationManager implements ConfigurationManager
|
||||
|
||||
private void loadProperties() throws FileNotFoundException, IOException
|
||||
{
|
||||
if (_map.isEmpty())
|
||||
if (_map.isEmpty() && _file!=null)
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
properties.load(_file.getInputStream());
|
||||
|
@ -15,7 +15,6 @@ package org.eclipse.jetty.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.jetty.deploy.providers.MonitoredDirAppProvider;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
@ -44,6 +43,7 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
||||
* This deployer does not do hot deployment or undeployment. Nor does it support per web application configuration. For
|
||||
* these features see {@link ContextDeployer}.
|
||||
*
|
||||
* @deprecated
|
||||
* @see DeploymentManager
|
||||
* @see MonitoredDirAppProvider
|
||||
* @see ContextDeployer
|
||||
@ -60,7 +60,13 @@ public class WebAppDeployer extends AbstractLifeCycle
|
||||
private boolean _allowDuplicates;
|
||||
private ArrayList _deployed;
|
||||
private AttributesMap _contextAttributes = new AttributesMap();
|
||||
|
||||
|
||||
|
||||
public WebAppDeployer()
|
||||
{
|
||||
Log.warn("WebAppDeployer is deprecated. Use WebAppProvider");
|
||||
}
|
||||
|
||||
public String[] getConfigurationClasses()
|
||||
{
|
||||
return _configurationClasses;
|
||||
|
@ -1,388 +0,0 @@
|
||||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
// ------------------------------------------------------------------------
|
||||
// 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.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
package org.eclipse.jetty.deploy.providers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.deploy.App;
|
||||
import org.eclipse.jetty.deploy.AppProvider;
|
||||
import org.eclipse.jetty.deploy.ConfigurationManager;
|
||||
import org.eclipse.jetty.deploy.DeploymentManager;
|
||||
import org.eclipse.jetty.deploy.util.FileID;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.Scanner;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
/**
|
||||
* AppProvider for Monitoring directories for contexts.
|
||||
*
|
||||
* A Context may either be a WAR, a directory or an XML descriptor.
|
||||
*/
|
||||
public abstract class MonitoredDirAppProvider extends AbstractLifeCycle implements AppProvider
|
||||
{
|
||||
class MonitoredFilenameFilter implements FilenameFilter
|
||||
{
|
||||
public boolean accept(File file, String name)
|
||||
{
|
||||
if (!file.exists())
|
||||
return false;
|
||||
|
||||
String lowername = name.toLowerCase();
|
||||
|
||||
if (_acceptContextXmlFiles && !file.isDirectory() && lowername.endsWith(".xml"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_acceptWarFiles && !file.isDirectory() && lowername.endsWith(".war"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_acceptDirectories && file.isDirectory())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean _acceptContextXmlFiles = true;
|
||||
private boolean _acceptWarFiles = true;
|
||||
private boolean _acceptDirectories = true;
|
||||
private Resource _monitoredDir;
|
||||
private Scanner _scanner;
|
||||
private int _scanInterval = 10;
|
||||
private boolean _recursive = false;
|
||||
private boolean _extractWars = false;
|
||||
private boolean _parentLoaderPriority = false;
|
||||
private String _defaultsDescriptor;
|
||||
private DeploymentManager _deploymentManager;
|
||||
private FilenameFilter _filenamefilter;
|
||||
private ConfigurationManager _configurationManager;
|
||||
|
||||
private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
|
||||
{
|
||||
public void fileAdded(String filename) throws Exception
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("added ", filename);
|
||||
addConfiguredContextApp(filename);
|
||||
}
|
||||
|
||||
public void fileChanged(String filename) throws Exception
|
||||
{
|
||||
System.err.println("changed "+filename);
|
||||
// TODO should this not be an add/remove?
|
||||
if (Log.isDebugEnabled()) Log.debug("changed ", filename);
|
||||
addConfiguredContextApp(filename);
|
||||
}
|
||||
|
||||
public void fileRemoved(String filename) throws Exception
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("removed ", filename);
|
||||
|
||||
// TODO: How to determine ID from filename that doesn't exist?
|
||||
// TODO: we probably need a map from discovered filename to resulting App
|
||||
}
|
||||
};
|
||||
|
||||
public MonitoredDirAppProvider()
|
||||
{
|
||||
_filenamefilter = new MonitoredFilenameFilter();
|
||||
}
|
||||
|
||||
protected MonitoredDirAppProvider(boolean xml,boolean war, boolean dir)
|
||||
{
|
||||
_acceptContextXmlFiles=xml;
|
||||
_acceptWarFiles=war;
|
||||
_acceptDirectories=dir;
|
||||
_filenamefilter = new MonitoredFilenameFilter();
|
||||
}
|
||||
|
||||
protected MonitoredDirAppProvider(FilenameFilter filter, boolean xml,boolean war, boolean dir)
|
||||
{
|
||||
_acceptContextXmlFiles=xml;
|
||||
_acceptWarFiles=war;
|
||||
_acceptDirectories=dir;
|
||||
_filenamefilter = filter;
|
||||
}
|
||||
|
||||
private App addConfiguredContextApp(String filename)
|
||||
{
|
||||
App app = new App(_deploymentManager,this,filename);
|
||||
_deploymentManager.addApp(app);
|
||||
return app;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Create a context Handler for an App instance.
|
||||
* This method can create a {@link ContextHandler} from a context XML file
|
||||
* or a {@link WebAppContext} from a WAR file or directory, depending on the
|
||||
* settings of the accept fields.
|
||||
* @see #setAcceptContextXmlFiles(boolean)
|
||||
* @see #setAcceptWarFiles(boolean)
|
||||
* @see #setAcceptDirectories(boolean)
|
||||
* @see org.eclipse.jetty.deploy.AppProvider#createContextHandler(org.eclipse.jetty.deploy.App)
|
||||
*/
|
||||
public ContextHandler createContextHandler(final App app) throws Exception
|
||||
{
|
||||
Resource resource = Resource.newResource(app.getOriginId());
|
||||
File file=resource.getFile();
|
||||
|
||||
if (!resource.exists())
|
||||
throw new IllegalStateException("App resouce does not exist "+resource);
|
||||
|
||||
if (_acceptContextXmlFiles && FileID.isXmlFile(file))
|
||||
{
|
||||
// TODO - it is a bit wierd that this ignores
|
||||
// _defaultsDescriptor, _extractWars and _parentLoaderPriority
|
||||
// This reflects that there really is the common base for Context
|
||||
// and WebApp deployers should probably not have these bits in them
|
||||
|
||||
XmlConfiguration xmlc = new XmlConfiguration(resource.getURL());
|
||||
Map props = new HashMap();
|
||||
props.put("Server",_deploymentManager.getServer());
|
||||
if (getConfigurationManager() != null)
|
||||
props.putAll(getConfigurationManager().getProperties());
|
||||
xmlc.setProperties(props);
|
||||
return (ContextHandler)xmlc.configure();
|
||||
}
|
||||
|
||||
String context = file.getName();
|
||||
|
||||
if (_acceptWarFiles && FileID.isWebArchiveFile(file))
|
||||
{
|
||||
// Context Path is the same as the archive.
|
||||
context = context.substring(0,context.length() - 4);
|
||||
}
|
||||
else if (_acceptDirectories && file.isDirectory())
|
||||
{
|
||||
// must be a directory
|
||||
}
|
||||
else
|
||||
throw new IllegalStateException("unable to create ContextHandler for "+app);
|
||||
|
||||
|
||||
// special case of archive (or dir) named "root" is / context
|
||||
if (context.equalsIgnoreCase("root") || context.equalsIgnoreCase("root/"))
|
||||
context = URIUtil.SLASH;
|
||||
|
||||
// Ensure "/" is Prepended to all context paths.
|
||||
if (context.charAt(0) != '/')
|
||||
context = "/" + context;
|
||||
|
||||
// Ensure "/" is Not Trailing in context paths.
|
||||
if (context.endsWith("/") && context.length() > 0)
|
||||
context = context.substring(0,context.length() - 1);
|
||||
|
||||
WebAppContext wah = new WebAppContext();
|
||||
wah.setContextPath(context);
|
||||
wah.setWar(file.getAbsolutePath());
|
||||
if (_defaultsDescriptor != null)
|
||||
wah.setDefaultsDescriptor(_defaultsDescriptor);
|
||||
wah.setExtractWAR(_extractWars);
|
||||
wah.setParentLoaderPriority(_parentLoaderPriority);
|
||||
|
||||
return wah;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
if (_monitoredDir == null)
|
||||
{
|
||||
throw new IllegalStateException("No configuration dir specified");
|
||||
}
|
||||
|
||||
File scandir = _monitoredDir.getFile();
|
||||
Log.info("Deployment monitor " + scandir+ " at interval "+_scanInterval);
|
||||
_scanner=new Scanner();
|
||||
_scanner.setScanDirs(Collections.singletonList(scandir));
|
||||
_scanner.setScanInterval(_scanInterval);
|
||||
_scanner.setRecursive(_recursive);
|
||||
_scanner.setFilenameFilter(_filenamefilter);
|
||||
_scanner.setReportDirs(_acceptDirectories);
|
||||
_scanner.addListener(_scannerListener);
|
||||
_scanner.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
_scanner.stop();
|
||||
_scanner.removeListener(_scannerListener);
|
||||
_scanner=null;
|
||||
}
|
||||
|
||||
public ConfigurationManager getConfigurationManager()
|
||||
{
|
||||
return _configurationManager;
|
||||
}
|
||||
|
||||
public String getDefaultsDescriptor()
|
||||
{
|
||||
return _defaultsDescriptor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the deploymentManager.
|
||||
* @return the deploymentManager
|
||||
*/
|
||||
public DeploymentManager getDeploymentManager()
|
||||
{
|
||||
return _deploymentManager;
|
||||
}
|
||||
|
||||
public Resource getMonitoredDir()
|
||||
{
|
||||
return _monitoredDir;
|
||||
}
|
||||
|
||||
public int getScanInterval()
|
||||
{
|
||||
return _scanInterval;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the acceptContextXmlFiles.
|
||||
* @return the acceptContextXmlFiles
|
||||
*/
|
||||
public boolean isAcceptContextXmlFiles()
|
||||
{
|
||||
return _acceptContextXmlFiles;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the acceptDirectories.
|
||||
* @return the acceptDirectories
|
||||
*/
|
||||
public boolean isAcceptDirectories()
|
||||
{
|
||||
return _acceptDirectories;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the acceptWarFiles.
|
||||
* @return the acceptWarFiles
|
||||
*/
|
||||
public boolean isAcceptWarFiles()
|
||||
{
|
||||
return _acceptWarFiles;
|
||||
}
|
||||
|
||||
public boolean isExtractWars()
|
||||
{
|
||||
return _extractWars;
|
||||
}
|
||||
|
||||
public boolean isParentLoaderPriority()
|
||||
{
|
||||
return _parentLoaderPriority;
|
||||
}
|
||||
|
||||
public boolean isRecursive()
|
||||
{
|
||||
return _recursive;
|
||||
}
|
||||
|
||||
public void setAcceptContextXmlFiles(boolean flag)
|
||||
{
|
||||
if (isRunning())
|
||||
throw new IllegalStateException();
|
||||
_acceptContextXmlFiles = flag;
|
||||
}
|
||||
|
||||
public void setAcceptDirectories(boolean flag)
|
||||
{
|
||||
if (isRunning())
|
||||
throw new IllegalStateException();
|
||||
_acceptDirectories = flag;
|
||||
}
|
||||
|
||||
public void setAcceptWarFiles(boolean flag)
|
||||
{
|
||||
if (isRunning())
|
||||
throw new IllegalStateException();
|
||||
_acceptWarFiles = flag;
|
||||
}
|
||||
|
||||
public void setConfigurationManager(ConfigurationManager configurationManager)
|
||||
{
|
||||
_configurationManager = configurationManager;
|
||||
}
|
||||
|
||||
public void setDefaultsDescriptor(String defaultsDescriptor)
|
||||
{
|
||||
_defaultsDescriptor = defaultsDescriptor;
|
||||
}
|
||||
|
||||
public void setDeploymentManager(DeploymentManager deploymentManager)
|
||||
{
|
||||
_deploymentManager = deploymentManager;
|
||||
}
|
||||
|
||||
public void setExtractWars(boolean extractWars)
|
||||
{
|
||||
_extractWars = extractWars;
|
||||
}
|
||||
|
||||
public void setMonitoredDir(Resource contextsDir)
|
||||
{
|
||||
_monitoredDir = contextsDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dir
|
||||
* Directory to scan for context descriptors or war files
|
||||
*/
|
||||
public void setMonitoredDir(String dir)
|
||||
{
|
||||
try
|
||||
{
|
||||
_monitoredDir = Resource.newResource(dir);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setParentLoaderPriority(boolean parentLoaderPriority)
|
||||
{
|
||||
_parentLoaderPriority = parentLoaderPriority;
|
||||
}
|
||||
|
||||
public void setRecursive(boolean recursive)
|
||||
{
|
||||
_recursive = recursive;
|
||||
}
|
||||
|
||||
public void setScanInterval(int scanInterval)
|
||||
{
|
||||
_scanInterval = scanInterval;
|
||||
}
|
||||
}
|
@ -48,50 +48,33 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
|
||||
private boolean _recursive = false;
|
||||
private int _scanInterval = 10;
|
||||
private Scanner _scanner;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
|
||||
{
|
||||
public void fileAdded(String filename) throws Exception
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("added ",filename);
|
||||
App app = ScanningAppProvider.this.createApp(filename);
|
||||
if (app != null)
|
||||
{
|
||||
_appMap.put(filename,app);
|
||||
_deploymentManager.addApp(app);
|
||||
}
|
||||
ScanningAppProvider.this.fileAdded(filename);
|
||||
}
|
||||
|
||||
public void fileChanged(String filename) throws Exception
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("changed ",filename);
|
||||
App app = _appMap.remove(filename);
|
||||
if (app != null)
|
||||
{
|
||||
_deploymentManager.removeApp(app);
|
||||
}
|
||||
app = ScanningAppProvider.this.createApp(filename);
|
||||
if (app != null)
|
||||
{
|
||||
_appMap.put(filename,app);
|
||||
_deploymentManager.addApp(app);
|
||||
}
|
||||
ScanningAppProvider.this.fileChanged(filename);
|
||||
}
|
||||
|
||||
public void fileRemoved(String filename) throws Exception
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("removed ",filename);
|
||||
App app = _appMap.remove(filename);
|
||||
if (app != null)
|
||||
_deploymentManager.removeApp(app);
|
||||
ScanningAppProvider.this.fileRemoved(filename);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected ScanningAppProvider(FilenameFilter filter)
|
||||
{
|
||||
_filenameFilter = filter;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return The index of currently deployed applications.
|
||||
*/
|
||||
@ -100,6 +83,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
|
||||
return _appMap;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Called by the Scanner.DiscreteListener to create a new App object.
|
||||
* Isolated in a method so that it is possible to override the default App
|
||||
@ -115,6 +99,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
|
||||
return new App(_deploymentManager,this,filename);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
@ -140,11 +125,52 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
_scanner.stop();
|
||||
_scanner.removeListener(_scannerListener);
|
||||
_scanner = null;
|
||||
if (_scanner!=null)
|
||||
{
|
||||
_scanner.stop();
|
||||
_scanner.removeListener(_scannerListener);
|
||||
_scanner = null;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void fileAdded(String filename) throws Exception
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("added ",filename);
|
||||
App app = ScanningAppProvider.this.createApp(filename);
|
||||
if (app != null)
|
||||
{
|
||||
_appMap.put(filename,app);
|
||||
_deploymentManager.addApp(app);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void fileChanged(String filename) throws Exception
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("changed ",filename);
|
||||
App app = _appMap.remove(filename);
|
||||
if (app != null)
|
||||
{
|
||||
_deploymentManager.removeApp(app);
|
||||
}
|
||||
app = ScanningAppProvider.this.createApp(filename);
|
||||
if (app != null)
|
||||
{
|
||||
_appMap.put(filename,app);
|
||||
_deploymentManager.addApp(app);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void fileRemoved(String filename) throws Exception
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("removed ",filename);
|
||||
App app = _appMap.remove(filename);
|
||||
if (app != null)
|
||||
_deploymentManager.removeApp(app);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Get the deploymentManager.
|
||||
|
@ -20,6 +20,10 @@ import org.eclipse.jetty.webapp.WebInfConfiguration;
|
||||
* <p>This specialization of {@link MonitoredDirAppProvider} is the
|
||||
* replacement for {@link WebAppDeployer} and it will scan a directory
|
||||
* only for war files or directories files.</p>
|
||||
* <p>
|
||||
* Webapps with names root or starting with root- are deployed at /.
|
||||
* If the name is in the format root-hostname, then the webapp is deployed
|
||||
* at / in the virtual host hostname.
|
||||
* @see WebAppDeployer
|
||||
*/
|
||||
public class WebAppProvider extends ScanningAppProvider
|
||||
@ -31,7 +35,7 @@ public class WebAppProvider extends ScanningAppProvider
|
||||
private File _tempDirectory;
|
||||
private String[] _configurationClasses;
|
||||
|
||||
private static class Filter implements FilenameFilter
|
||||
public static class Filter implements FilenameFilter
|
||||
{
|
||||
private File _contexts;
|
||||
|
||||
@ -236,12 +240,29 @@ public class WebAppProvider extends ScanningAppProvider
|
||||
{
|
||||
throw new IllegalStateException("unable to create ContextHandler for "+app);
|
||||
}
|
||||
|
||||
// Ensure "/" is Not Trailing in context paths.
|
||||
if (context.endsWith("/") && context.length() > 0)
|
||||
{
|
||||
context = context.substring(0,context.length() - 1);
|
||||
}
|
||||
|
||||
// Start building the webapplication
|
||||
WebAppContext wah = new WebAppContext();
|
||||
wah.setDisplayName(context);
|
||||
|
||||
// special case of archive (or dir) named "root" is / context
|
||||
if (context.equalsIgnoreCase("root") || context.equalsIgnoreCase("root/"))
|
||||
if (context.equalsIgnoreCase("root"))
|
||||
{
|
||||
context = URIUtil.SLASH;
|
||||
}
|
||||
else if (context.toLowerCase().startsWith("root-"))
|
||||
{
|
||||
int dash=context.toLowerCase().indexOf('-');
|
||||
String virtual = context.substring(dash+1);
|
||||
wah.setVirtualHosts(new String[]{virtual});
|
||||
context = URIUtil.SLASH;
|
||||
}
|
||||
|
||||
// Ensure "/" is Prepended to all context paths.
|
||||
if (context.charAt(0) != '/')
|
||||
@ -249,13 +270,7 @@ public class WebAppProvider extends ScanningAppProvider
|
||||
context = "/" + context;
|
||||
}
|
||||
|
||||
// Ensure "/" is Not Trailing in context paths.
|
||||
if (context.endsWith("/") && context.length() > 0)
|
||||
{
|
||||
context = context.substring(0,context.length() - 1);
|
||||
}
|
||||
|
||||
WebAppContext wah = new WebAppContext();
|
||||
wah.setContextPath(context);
|
||||
wah.setWar(file.getAbsolutePath());
|
||||
if (_defaultsDescriptor != null)
|
||||
|
@ -56,5 +56,7 @@ etc/jetty.xml
|
||||
# etc/jetty-ssl.xml
|
||||
# etc/jetty-requestlog.xml
|
||||
etc/jetty-deploy.xml
|
||||
etc/jetty-webapps.xml
|
||||
etc/jetty-contexts.xml
|
||||
etc/jetty-testrealm.xml
|
||||
#===========================================================
|
||||
|
@ -137,7 +137,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
||||
private boolean _configurationClassesSet=false;
|
||||
private boolean _configurationsSet=false;
|
||||
|
||||
private final MetaData _metadata;
|
||||
private MetaData _metadata;
|
||||
|
||||
public static WebAppContext getCurrentWebAppContext()
|
||||
{
|
||||
@ -169,33 +169,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
||||
throw new IllegalArgumentException("template is started");
|
||||
_scontext=new Context();
|
||||
setErrorHandler(new ErrorPageErrorHandler());
|
||||
|
||||
|
||||
//Make a new MetaData to hold descriptor and annotation metadata
|
||||
_metadata = template.getMetaData();
|
||||
|
||||
_configurations = new Configuration[]{new CloneConfiguration(template)};
|
||||
|
||||
|
||||
// TODO we need some better way to work out what attributes should be copied at this stage.
|
||||
|
||||
setAliases(template.isAliases());
|
||||
setBaseResource(template.getBaseResource());
|
||||
setClassLoader(template.getClassLoader());
|
||||
setContextPath(template.getContextPath());
|
||||
setCompactPath(template.isCompactPath());
|
||||
setDisplayName(template.getDisplayName());
|
||||
setLogger(template.getLogger()); // TODO maybe not shared ???
|
||||
setMaxFormContentSize(template.getMaxFormContentSize());
|
||||
|
||||
Enumeration<?> names=template.getAttributeNames();
|
||||
while(names.hasMoreElements())
|
||||
{
|
||||
String name = (String)names.nextElement();
|
||||
Object val = template.getAttribute(name);
|
||||
if (!name.startsWith("javax.servlet."))
|
||||
setAttribute(name,val);
|
||||
}
|
||||
setTemplate(template);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@ -230,6 +204,45 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
||||
_metadata = new MetaData();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Configure this WebAppContext from a shared WebAppContext as template.
|
||||
* <p>The MetaData is reused from the template.
|
||||
* @param template The template to base this webappcontext on
|
||||
*/
|
||||
public void setTemplate(WebAppContext template)
|
||||
{
|
||||
if (template==null)
|
||||
throw new IllegalStateException("null template");
|
||||
if (isRunning() || template.isRunning())
|
||||
throw new IllegalStateException("Running");
|
||||
|
||||
//Make a new MetaData to hold descriptor and annotation metadata
|
||||
_metadata = template.getMetaData();
|
||||
|
||||
_configurations = new Configuration[]{new CloneConfiguration(template)};
|
||||
|
||||
// TODO we need some better way to work out what attributes should be copied at this stage.
|
||||
|
||||
setAliases(template.isAliases());
|
||||
setBaseResource(template.getBaseResource());
|
||||
setClassLoader(template.getClassLoader());
|
||||
setContextPath(template.getContextPath());
|
||||
setCompactPath(template.isCompactPath());
|
||||
setDisplayName(template.getDisplayName());
|
||||
setLogger(template.getLogger()); // TODO maybe not shared ???
|
||||
setMaxFormContentSize(template.getMaxFormContentSize());
|
||||
|
||||
Enumeration<?> names=template.getAttributeNames();
|
||||
while(names.hasMoreElements())
|
||||
{
|
||||
String name = (String)names.nextElement();
|
||||
Object val = template.getAttribute(name);
|
||||
if (!name.startsWith("javax.servlet."))
|
||||
setAttribute(name,val);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param servletContextName The servletContextName to set.
|
||||
|
Loading…
x
Reference in New Issue
Block a user