364430 Support web.xml enabled state for servlets

This commit is contained in:
Jan Bartel 2011-11-22 14:09:45 +11:00
parent 837f8d33c4
commit cbec18af60
4 changed files with 26 additions and 7 deletions

View File

@ -506,7 +506,10 @@ public class ServletContextHandler extends ContextHandler
public RequestDispatcher getNamedDispatcher(String name)
{
ContextHandler context=org.eclipse.jetty.servlet.ServletContextHandler.this;
if (_servletHandler==null || _servletHandler.getServlet(name)==null)
if (_servletHandler==null)
return null;
ServletHolder holder = _servletHandler.getServlet(name);
if (holder==null || !holder.isEnabled())
return null;
return new Dispatcher(context, name);
}

View File

@ -1191,7 +1191,7 @@ public class ServletHandler extends ScopedHandler
ServletHolder servlet_holder = (ServletHolder)_servletNameMap.get(_servletMappings[i].getServletName());
if (servlet_holder==null)
throw new IllegalStateException("No such servlet: "+_servletMappings[i].getServletName());
else if (_servletMappings[i].getPathSpecs()!=null)
else if (servlet_holder.isEnabled() && _servletMappings[i].getPathSpecs()!=null)
{
String[] pathSpecs = _servletMappings[i].getPathSpecs();
for (int j=0;j<pathSpecs.length;j++)

View File

@ -74,6 +74,7 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
private transient Servlet _servlet;
private transient Config _config;
private transient long _unavailable;
private transient boolean _enabled = true;
private transient UnavailableException _unavailableEx;
public static final Map<String,String> NO_MAPPED_ROLES = Collections.emptyMap();
@ -246,11 +247,26 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
_forcedPath = forcedPath;
}
public boolean isEnabled()
{
return _enabled;
}
public void setEnabled(boolean enabled)
{
_enabled = enabled;
}
/* ------------------------------------------------------------ */
public void doStart()
throws Exception
{
_unavailable=0;
if (!_enabled)
return;
try
{
super.doStart();

View File

@ -513,15 +513,14 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String enabled = node.getString("enabled", false, true);
if (enabled!=null)
{
boolean is_enabled = enabled.length()==0||Boolean.valueOf(enabled);
// TODO handle enabled?
boolean is_enabled = enabled.length()==0||Boolean.valueOf(enabled);
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.enabled");
switch (o)
{
case NotSet:
{
//hasn't been set yet, so set it
//TODO
holder.setEnabled(is_enabled);
context.getMetaData().setOrigin(servlet_name+".servlet.enabled", descriptor);
break;
}
@ -532,7 +531,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//was set in a web xml descriptor, only allow override from another web xml descriptor
if (!(descriptor instanceof FragmentDescriptor))
{
//TODO
holder.setEnabled(is_enabled);
context.getMetaData().setOrigin(servlet_name+".servlet.enabled", descriptor);
}
break;
@ -540,7 +539,8 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case WebFragment:
{
//was set by another fragment, this fragment's value must match
//TODO
if (holder.isEnabled() != is_enabled)
throw new IllegalStateException("Conflicting value of servlet enabled for servlet "+servlet_name+" in "+descriptor.getResource());
break;
}
}