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 + 315715 Improved Cookie version handling. Server.setMaxCookieVersion
+ 315744 Fixed STOP.PORT and STOP.KEY in start.jar + 315744 Fixed STOP.PORT and STOP.KEY in start.jar
+ 315748 Removed --fromDaemon from start.jar + 315748 Removed --fromDaemon from start.jar
+ 315925 Improved context xml configuration handling
jetty-7.1.3.v20100526 jetty-7.1.3.v20100526
+ 296567 HttpClient RedirectListener handles new HttpDestination + 296567 HttpClient RedirectListener handles new HttpDestination

View File

@ -96,7 +96,15 @@ public class App
if (_context == null) if (_context == null)
{ {
_context = getAppProvider().createContextHandler(this); _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; return _context;
} }

View File

@ -448,7 +448,14 @@ public class ContextDeployer extends AbstractLifeCycle
xmlConfiguration.setProperties(properties); xmlConfiguration.setProperties(properties);
ContextHandler context=(ContextHandler)xmlConfiguration.configure(); 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; return context;
} }

View File

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

View File

@ -40,7 +40,8 @@ public class AttributesMap implements Attributes
{ {
_map=map; _map=map;
} }
/* ------------------------------------------------------------ */
public AttributesMap(AttributesMap map) public AttributesMap(AttributesMap map)
{ {
_map=new HashMap<String,Object>(map._map); _map=new HashMap<String,Object>(map._map);
@ -117,7 +118,13 @@ public class AttributesMap implements Attributes
{ {
_map.clear(); _map.clear();
} }
/* ------------------------------------------------------------ */
public int size()
{
return _map.size();
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@Override @Override
public String toString() public String toString()
@ -130,5 +137,16 @@ public class AttributesMap implements Attributes
{ {
return _map.keySet(); 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() public String toString()
{ {
if(_resources==null) if(_resources==null)
return ""; return "[]";
StringBuilder buffer = new StringBuilder(); return String.valueOf(Arrays.asList(_resources));
for(Resource r : _resources)
buffer.append(r.toString()).append(';');
return buffer.toString();
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.util.LazyList;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.Resource; 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; 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(); String[] files=lib.list();
for (int f=0;files!=null && f<files.length;f++) for (int f=0;files!=null && f<files.length;f++)
{ {
try { try
{
Resource fn=lib.addPath(files[f]); Resource fn=lib.addPath(files[f]);
String fnlc=fn.getName().toLowerCase(); String fnlc=fn.getName().toLowerCase();
if (isFileSupported(fnlc)) if (!fn.isDirectory() && isFileSupported(fnlc))
{ {
String jar=fn.toString(); String jar=fn.toString();
jar=StringUtil.replace(jar, ",", "%2C"); jar=StringUtil.replace(jar, ",", "%2C");

View File

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

View File

@ -29,7 +29,7 @@ public class WebAppClassLoaderTest
_loader = new WebAppClassLoader(_context); _loader = new WebAppClassLoader(_context);
_loader.addJars(webapp.addPath("WEB-INF/lib")); _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"); _loader.setName("test");
} }

View File

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