当前位置: 首页>>代码示例>>Java>>正文


Java ServletMapping.getPathSpecs方法代码示例

本文整理汇总了Java中org.eclipse.jetty.servlet.ServletMapping.getPathSpecs方法的典型用法代码示例。如果您正苦于以下问题:Java ServletMapping.getPathSpecs方法的具体用法?Java ServletMapping.getPathSpecs怎么用?Java ServletMapping.getPathSpecs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.servlet.ServletMapping的用法示例。


在下文中一共展示了ServletMapping.getPathSpecs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeServlet

import org.eclipse.jetty.servlet.ServletMapping; //导入方法依赖的package包/类
/**
 * Removes the previously registered servlet from the specified path
 * 
 * @param pathSpec
 *            the path spec to remove
 * @throws WebServerException
 *             if an error occurs
 */
public synchronized static void removeServlet(String pathSpec) throws WebServerException {
	if (contexts != null) {
		try {
			ServletHandler handler = contexts.getServletHandler();
			List<ServletMapping> mappings = new ArrayList<>();

			for (ServletMapping mapping : handler.getServletMappings()) {
				List<String> pathSpecs = new ArrayList<>();
				for (String path : mapping.getPathSpecs()) {
					if (!pathSpec.equals(path)) {
						pathSpecs.add(path);
					}
				}
				if (!pathSpecs.isEmpty()) {
					mapping.setPathSpecs(pathSpecs.toArray(new String[pathSpecs.size()]));
					mappings.add(mapping);
				}
			}

			handler.setServletMappings(mappings.toArray(new ServletMapping[mappings.size()]));
		} catch (Exception e) {
			throw new WebServerException(e);
		}
	}
}
 
开发者ID:sfera-labs,项目名称:sfera,代码行数:34,代码来源:WebServer.java

示例2: getResource

import org.eclipse.jetty.servlet.ServletMapping; //导入方法依赖的package包/类
@Override
public final Resource getResource(String pathInContext) {
	ServletContextHandler.Context context = (ServletContextHandler.Context) getServletContext();
	ServletContextHandler contextHandler = (ServletContextHandler) context.getContextHandler();
	
	for (ServletMapping mapping: contextHandler.getServletHandler().getServletMappings()) {
		if (mapping.getServletName().equals(getServletName())) {
			for (String pathSpec: mapping.getPathSpecs()) {
				String relativePath = null;
				if (pathSpec.endsWith("/*")) {
					pathSpec = StringUtils.substringBeforeLast(pathSpec, "/*");
					if (pathInContext.startsWith(pathSpec + "/")) 
						relativePath = pathInContext.substring(pathSpec.length());
				} else if (pathSpec.startsWith("*.")) {
					pathSpec = StringUtils.stripStart(pathSpec, "*");
					if (pathInContext.endsWith(pathSpec))
						relativePath = pathInContext;
				} else if (pathSpec.equals(pathInContext)) {
					relativePath = pathInContext;
				}
				if (relativePath != null) {
					relativePath = StringUtils.stripStart(relativePath, "/");
					Resource resource = Resource.newResource(loadResource(relativePath));
					if (resource != null && resource.exists())
						return resource;
				}
			}
		}
	}
	
	return null;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:33,代码来源:AssetServlet.java

示例3: unregisterHandler

import org.eclipse.jetty.servlet.ServletMapping; //导入方法依赖的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


注:本文中的org.eclipse.jetty.servlet.ServletMapping.getPathSpecs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。