當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletHandler.setServlets方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.servlet.ServletHandler.setServlets方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletHandler.setServlets方法的具體用法?Java ServletHandler.setServlets怎麽用?Java ServletHandler.setServlets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.servlet.ServletHandler的用法示例。


在下文中一共展示了ServletHandler.setServlets方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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);
            }
        }
    }
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:39,代碼來源:HttpConductorImpl.java

示例2: 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);
    }       
}
 
開發者ID:sensiasoft,項目名稱:sensorhub,代碼行數:39,代碼來源:HttpServer.java

示例3: removeServlet

import org.eclipse.jetty.servlet.ServletHandler; //導入方法依賴的package包/類
/**
 * Removes the previously registered servlet holder
 * 
 * @param servlet
 *            the servlet holder
 * @throws WebServerException
 *             if an error occurs
 */
public synchronized static void removeServlet(ServletHolder servlet) throws WebServerException {
	if (contexts != null) {
		try {
			ServletHandler handler = contexts.getServletHandler();
			List<ServletHolder> servlets = new ArrayList<>();
			List<ServletMapping> mappings = new ArrayList<>();

			for (ServletHolder sh : handler.getServlets()) {
				if (servlet != sh) {
					servlets.add(sh);
				}
			}

			for (ServletMapping mapping : handler.getServletMappings()) {
				if (!mapping.getServletName().equals(servlet.getName())) {
					mappings.add(mapping);
				} else {
					if (logger.isDebugEnabled()) {
						for (String path : mapping.getPathSpecs()) {
							logger.debug("Removed servlet for path {}", path);
						}
					}
				}
			}

			handler.setServletMappings(mappings.toArray(new ServletMapping[mappings.size()]));
			handler.setServlets(servlets.toArray(new ServletHolder[servlets.size()]));
		} catch (Exception e) {
			throw new WebServerException(e);
		}
	}
}
 
開發者ID:sfera-labs,項目名稱:sfera,代碼行數:41,代碼來源:WebServer.java


注:本文中的org.eclipse.jetty.servlet.ServletHandler.setServlets方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。