364430 Support web.xml enabled state for servlets
This commit is contained in:
parent
837f8d33c4
commit
cbec18af60
|
@ -506,7 +506,10 @@ public class ServletContextHandler extends ContextHandler
|
||||||
public RequestDispatcher getNamedDispatcher(String name)
|
public RequestDispatcher getNamedDispatcher(String name)
|
||||||
{
|
{
|
||||||
ContextHandler context=org.eclipse.jetty.servlet.ServletContextHandler.this;
|
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 null;
|
||||||
return new Dispatcher(context, name);
|
return new Dispatcher(context, name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1191,7 +1191,7 @@ public class ServletHandler extends ScopedHandler
|
||||||
ServletHolder servlet_holder = (ServletHolder)_servletNameMap.get(_servletMappings[i].getServletName());
|
ServletHolder servlet_holder = (ServletHolder)_servletNameMap.get(_servletMappings[i].getServletName());
|
||||||
if (servlet_holder==null)
|
if (servlet_holder==null)
|
||||||
throw new IllegalStateException("No such servlet: "+_servletMappings[i].getServletName());
|
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();
|
String[] pathSpecs = _servletMappings[i].getPathSpecs();
|
||||||
for (int j=0;j<pathSpecs.length;j++)
|
for (int j=0;j<pathSpecs.length;j++)
|
||||||
|
|
|
@ -74,6 +74,7 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
|
||||||
private transient Servlet _servlet;
|
private transient Servlet _servlet;
|
||||||
private transient Config _config;
|
private transient Config _config;
|
||||||
private transient long _unavailable;
|
private transient long _unavailable;
|
||||||
|
private transient boolean _enabled = true;
|
||||||
private transient UnavailableException _unavailableEx;
|
private transient UnavailableException _unavailableEx;
|
||||||
public static final Map<String,String> NO_MAPPED_ROLES = Collections.emptyMap();
|
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;
|
_forcedPath = forcedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled()
|
||||||
|
{
|
||||||
|
return _enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled)
|
||||||
|
{
|
||||||
|
_enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public void doStart()
|
public void doStart()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
_unavailable=0;
|
_unavailable=0;
|
||||||
|
if (!_enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
super.doStart();
|
super.doStart();
|
||||||
|
|
|
@ -514,14 +514,13 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
if (enabled!=null)
|
if (enabled!=null)
|
||||||
{
|
{
|
||||||
boolean is_enabled = enabled.length()==0||Boolean.valueOf(enabled);
|
boolean is_enabled = enabled.length()==0||Boolean.valueOf(enabled);
|
||||||
// TODO handle enabled?
|
|
||||||
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.enabled");
|
Origin o = context.getMetaData().getOrigin(servlet_name+".servlet.enabled");
|
||||||
switch (o)
|
switch (o)
|
||||||
{
|
{
|
||||||
case NotSet:
|
case NotSet:
|
||||||
{
|
{
|
||||||
//hasn't been set yet, so set it
|
//hasn't been set yet, so set it
|
||||||
//TODO
|
holder.setEnabled(is_enabled);
|
||||||
context.getMetaData().setOrigin(servlet_name+".servlet.enabled", descriptor);
|
context.getMetaData().setOrigin(servlet_name+".servlet.enabled", descriptor);
|
||||||
break;
|
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
|
//was set in a web xml descriptor, only allow override from another web xml descriptor
|
||||||
if (!(descriptor instanceof FragmentDescriptor))
|
if (!(descriptor instanceof FragmentDescriptor))
|
||||||
{
|
{
|
||||||
//TODO
|
holder.setEnabled(is_enabled);
|
||||||
context.getMetaData().setOrigin(servlet_name+".servlet.enabled", descriptor);
|
context.getMetaData().setOrigin(servlet_name+".servlet.enabled", descriptor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -540,7 +539,8 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
case WebFragment:
|
case WebFragment:
|
||||||
{
|
{
|
||||||
//was set by another fragment, this fragment's value must match
|
//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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue