}
@Override
public void unregisterHandler(ServletHolder servlet) {
synchronized(lock) {
ServletHandler servletHandler = rootContextHandler.getServletHandler();
ServletHolder[] curServlets = servletHandler.getServlets();
List<ServletHolder> newServlets = new ArrayList<>();
newServlets.addAll(Arrays.asList(curServlets));
if(!newServlets.remove(servlet)) {
throw new IllegalArgumentException("Servlet not registered");
}
List<ServletMapping> newMappings = new ArrayList<>();
newMappings.addAll(Arrays.asList(servletHandler.getServletMappings()));
for(Iterator<ServletMapping> it = newMappings.iterator(); it.hasNext(); ) {
ServletMapping m = it.next();
if(servlet.getName().equals(m.getServletName())) {
for(String path : m.getPathSpecs()) {
registeredPaths.remove(path);
}
it.remove();
break;
}
}
servletHandler.setServlets(newServlets.toArray(new ServletHolder[newServlets.size()]));
servletHandler.setServletMappings(newMappings.toArray(new ServletMapping[newMappings.size()]));
if(!servlet.isStopped()) {
try {
servlet.stop();
}