本文整理汇总了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);
}
}
}
示例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;
}
示例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);
}
}
}
}