本文整理汇总了Java中org.eclipse.jetty.servlet.ServletHandler.getServlets方法的典型用法代码示例。如果您正苦于以下问题:Java ServletHandler.getServlets方法的具体用法?Java ServletHandler.getServlets怎么用?Java ServletHandler.getServlets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.servlet.ServletHandler
的用法示例。
在下文中一共展示了ServletHandler.getServlets方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeServlet
import org.eclipse.jetty.servlet.ServletHandler; //导入方法依赖的package包/类
/**
* Removes the previously registered servlets of the specified class
*
* @param servlet
* the servlet class
* @throws WebServerException
* if an error occurs
*/
public synchronized static void removeServlet(Class<? extends Servlet> servlet) throws WebServerException {
if (contexts != null) {
ServletHandler handler = contexts.getServletHandler();
if (handler != null) {
for (ServletHolder sh : handler.getServlets()) {
Servlet s;
try {
s = sh.getServlet();
} catch (ServletException e) {
throw new WebServerException(e);
}
if (servlet.isInstance(s)) {
removeServlet(sh);
}
}
}
}
}
示例2: unregisterHandler
import org.eclipse.jetty.servlet.ServletHandler; //导入方法依赖的package包/类
@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();
}
catch(Exception e) {
throw new HttpConductorException(e);
}
}
}
}
示例3: undeployServlet
import org.eclipse.jetty.servlet.ServletHandler; //导入方法依赖的package包/类
public synchronized void undeployServlet(HttpServlet servlet)
{
try
{
// there is no removeServlet method so we need to do it manually
ServletHandler handler = servletHandler.getServletHandler();
// first collect servlets we want to keep
List<ServletHolder> servlets = new ArrayList<ServletHolder>();
String nameToRemove = null;
for( ServletHolder holder : handler.getServlets() )
{
if (holder.getServlet() != servlet)
servlets.add(holder);
else
nameToRemove = holder.getName();
}
if (nameToRemove == null)
return;
// also update servlet path mappings
List<ServletMapping> mappings = new ArrayList<ServletMapping>();
for (ServletMapping mapping : handler.getServletMappings())
{
if (!nameToRemove.contains(mapping.getServletName()))
mappings.add(mapping);
}
// set the new configuration
handler.setServletMappings( mappings.toArray(new ServletMapping[0]) );
handler.setServlets( servlets.toArray(new ServletHolder[0]) );
}
catch (ServletException e)
{
log.error("Error while undeploying servlet", e);
}
}