315925 Improved context xml configuration handling

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1932 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-06-07 05:50:31 +00:00
parent b56da2e598
commit a2bd4024c7
10 changed files with 78 additions and 53 deletions

View File

@ -11,6 +11,7 @@ jetty-7.1.4-SNAPSHOT
+ 315715 Improved Cookie version handling. Server.setMaxCookieVersion
+ 315744 Fixed STOP.PORT and STOP.KEY in start.jar
+ 315748 Removed --fromDaemon from start.jar
+ 315925 Improved context xml configuration handling
jetty-7.1.3.v20100526
+ 296567 HttpClient RedirectListener handles new HttpDestination

View File

@ -96,7 +96,15 @@ public class App
if (_context == null)
{
_context = getAppProvider().createContextHandler(this);
this._context.setAttributes(new AttributesMap(_manager.getContextAttributes()));
AttributesMap attributes = _manager.getContextAttributes();
if (attributes!=null && attributes.size()>0)
{
// Merge the manager attributes under the existing attributes
attributes = new AttributesMap(attributes);
attributes.addAll(_context.getAttributes());
_context.setAttributes(attributes);
}
}
return _context;
}

View File

@ -448,7 +448,14 @@ public class ContextDeployer extends AbstractLifeCycle
xmlConfiguration.setProperties(properties);
ContextHandler context=(ContextHandler)xmlConfiguration.configure();
context.setAttributes(new AttributesMap(_contextAttributes));
// merge attributes
if (_contextAttributes!=null && _contextAttributes.size()>0)
{
AttributesMap attributes = new AttributesMap(_contextAttributes);
attributes.addAll(context.getAttributes());
context.setAttributes(attributes);
}
return context;
}

View File

@ -102,11 +102,11 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
protected Context _scontext;
private AttributesMap _attributes;
private AttributesMap _contextAttributes;
private final AttributesMap _attributes;
private final AttributesMap _contextAttributes;
private final Map<String,String> _initParams;
private ClassLoader _classLoader;
private String _contextPath="/";
private Map<String,String> _initParams;
private String _displayName;
private Resource _baseResource;
private MimeTypes _mimeTypes;
@ -144,6 +144,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
super();
_scontext=new Context();
_attributes=new AttributesMap();
_contextAttributes=new AttributesMap();
_initParams=new HashMap<String,String>();
}
@ -156,6 +157,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
super();
_scontext=context;
_attributes=new AttributesMap();
_contextAttributes=new AttributesMap();
_initParams=new HashMap<String,String>();
}
@ -563,7 +565,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
Thread current_thread=null;
Context old_context=null;
_contextAttributes=new AttributesMap();
_contextAttributes.clearAttributes();
try
{
@ -700,9 +702,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
current_thread.setContextClassLoader(old_classloader);
}
if (_contextAttributes!=null)
_contextAttributes.clearAttributes();
_contextAttributes=null;
_contextAttributes.clearAttributes();
}
/* ------------------------------------------------------------ */
@ -1029,27 +1029,13 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
*/
public void setAttributes(Attributes attributes)
{
if (attributes instanceof AttributesMap)
_attributes.clearAttributes();
_attributes.addAll(attributes);
Enumeration e = _attributes.getAttributeNames();
while (e.hasMoreElements())
{
_attributes = (AttributesMap)attributes;
Enumeration e = _attributes.getAttributeNames();
while (e.hasMoreElements())
{
String name = (String)e.nextElement();
checkManagedAttribute(name,attributes.getAttribute(name));
}
}
else
{
_attributes=new AttributesMap();
Enumeration e = attributes.getAttributeNames();
while (e.hasMoreElements())
{
String name = (String)e.nextElement();
Object value=attributes.getAttribute(name);
checkManagedAttribute(name,value);
_attributes.setAttribute(name,value);
}
String name = (String)e.nextElement();
checkManagedAttribute(name,attributes.getAttribute(name));
}
}
@ -1108,17 +1094,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
}
}
/* ------------------------------------------------------------ */
/**
* @param initParams The initParams to set.
*/
public void setInitParams(Map<String,String> initParams)
{
if (initParams == null)
return;
_initParams = new HashMap<String,String>(initParams);
}
/* ------------------------------------------------------------ */
/**
* @param servletContextName The servletContextName to set.

View File

@ -40,7 +40,8 @@ public class AttributesMap implements Attributes
{
_map=map;
}
/* ------------------------------------------------------------ */
public AttributesMap(AttributesMap map)
{
_map=new HashMap<String,Object>(map._map);
@ -117,7 +118,13 @@ public class AttributesMap implements Attributes
{
_map.clear();
}
/* ------------------------------------------------------------ */
public int size()
{
return _map.size();
}
/* ------------------------------------------------------------ */
@Override
public String toString()
@ -130,5 +137,16 @@ public class AttributesMap implements Attributes
{
return _map.keySet();
}
/* ------------------------------------------------------------ */
public void addAll(Attributes attributes)
{
Enumeration<String> e = attributes.getAttributeNames();
while (e.hasMoreElements())
{
String name=e.nextElement();
setAttribute(name,attributes.getAttribute(name));
}
}
}

View File

@ -462,12 +462,9 @@ public class ResourceCollection extends Resource
public String toString()
{
if(_resources==null)
return "";
return "[]";
StringBuilder buffer = new StringBuilder();
for(Resource r : _resources)
buffer.append(r.toString()).append(';');
return buffer.toString();
return String.valueOf(Arrays.asList(_resources));
}
/* ------------------------------------------------------------ */

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.util.LazyList;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
/* ------------------------------------------------------------ */
@ -123,6 +124,24 @@ public class WebAppClassLoader extends URLClassLoader
{
return _context;
}
/* ------------------------------------------------------------ */
/**
* @param classPath Comma or semicolon separated path of filenames or URLs
* pointing to directories or jar files. Directories should end
* with '/'.
*/
public void addClassPath(Resource resource)
throws IOException
{
if (resource instanceof ResourceCollection)
{
for (Resource r : ((ResourceCollection)resource).getResources())
addClassPath(r);
}
else
addURL(resource.getURL());
}
/* ------------------------------------------------------------ */
/**
@ -188,10 +207,11 @@ public class WebAppClassLoader extends URLClassLoader
String[] files=lib.list();
for (int f=0;files!=null && f<files.length;f++)
{
try {
try
{
Resource fn=lib.addPath(files[f]);
String fnlc=fn.getName().toLowerCase();
if (isFileSupported(fnlc))
if (!fn.isDirectory() && isFileSupported(fnlc))
{
String jar=fn.toString();
jar=StringUtil.replace(jar, ",", "%2C");

View File

@ -136,7 +136,7 @@ public class WebInfConfiguration implements Configuration
// Look for classes directory
Resource classes= web_inf.addPath("classes/");
if (classes.exists())
((WebAppClassLoader)context.getClassLoader()).addClassPath(classes.toString());
((WebAppClassLoader)context.getClassLoader()).addClassPath(classes);
// Look for jars
Resource lib= web_inf.addPath("lib/");

View File

@ -29,7 +29,7 @@ public class WebAppClassLoaderTest
_loader = new WebAppClassLoader(_context);
_loader.addJars(webapp.addPath("WEB-INF/lib"));
_loader.addClassPath(webapp.addPath("WEB-INF/classes").toString());
_loader.addClassPath(webapp.addPath("WEB-INF/classes"));
_loader.setName("test");
}

View File

@ -92,15 +92,14 @@ public class TestServer
server.setStopAtShutdown(true);
server.setSendServerVersion(true);
WebAppContext webapp = new WebAppContext();
webapp.setParentLoaderPriority(true);
webapp.setResourceBase("./src/main/webapp");
webapp.setAttribute("testAttribute","testValue");
contexts.addHandler(webapp);
server.start();
server.join();
}