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


Java ServletMapping类代码示例

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


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

示例1: delete

import org.eclipse.jetty.servlet.ServletMapping; //导入依赖的package包/类
@Override
public void delete(String path)
{
  ServletMapping mapping = handler.getServletMapping(path);
  ServletMapping[] mappings = new ServletMapping [handler.getServletMappings().length - 1];
  ServletHolder[] servlets = new ServletHolder [handler.getServlets().length - 1];
  int mLength = 0, sLength = 0;
  
  for (ServletMapping m : handler.getServletMappings()) {
    if (!m.equals(mapping)) {
      mappings[mLength++] = m;
    }
  }
  
  for (ServletHolder s : handler.getServlets()) {
    if (!s.equals(handler.getServlet(mapping.getServletName()))) {
      servlets[sLength++] = s;
    }
  }
  
  handler.setServletMappings(mappings);
  handler.setServlets(servlets);
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:24,代码来源:HTTPServer.java

示例2: 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

示例3: 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

示例4: addJspServlet

import org.eclipse.jetty.servlet.ServletMapping; //导入依赖的package包/类
/**
 * Add Jetty's {@code JspServlet} to the given {@link WebAppContext}.
 * @param context the jetty {@link WebAppContext}
 */
protected final void addJspServlet(WebAppContext context) {
	Assert.notNull(context, "Context must not be null");
	ServletHolder holder = new ServletHolder();
	holder.setName("jsp");
	holder.setClassName(getJspServlet().getClassName());
	holder.setInitParameter("fork", "false");
	holder.setInitParameters(getJspServlet().getInitParameters());
	holder.setInitOrder(3);
	context.getServletHandler().addServlet(holder);
	ServletMapping mapping = new ServletMapping();
	mapping.setServletName("jsp");
	mapping.setPathSpecs(new String[] { "*.jsp", "*.jspx" });
	context.getServletHandler().addServletMapping(mapping);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:JettyEmbeddedServletContainerFactory.java

示例5: 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

示例6: start

import org.eclipse.jetty.servlet.ServletMapping; //导入依赖的package包/类
@Override public void start() throws ServerException {
    logger.info("start server, host: {}, port: {}", host, port);
    try {
        for (ServletMapping servletMapping : servletContextHandler.getServletHandler().getServletMappings()) {
            logger.info("jetty servlet mappings: {} register by {}", servletMapping.getPathSpecs(), servletMapping.getServletName());
        }
        server.start();
    } catch (Exception e) {
        throw new JettyServerException(e.getMessage(), e);
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:12,代码来源:JettyServer.java

示例7: deployServlet

import org.eclipse.jetty.servlet.ServletMapping; //导入依赖的package包/类
public synchronized void deployServlet(HttpServlet servlet, Map<String, String> initParams, String... paths)
{
    ServletHolder holder = new ServletHolder(servlet);
    if (initParams != null)
        holder.setInitParameters(initParams);
    
    ServletMapping mapping = new ServletMapping();
    mapping.setServletName(holder.getName());
    mapping.setPathSpecs(paths);
    
    servletHandler.getServletHandler().addServlet(holder);
    servletHandler.getServletHandler().addServletMapping(mapping);
    log.debug("Servlet deployed " + mapping.toString());
}
 
开发者ID:sensiasoft,项目名称:sensorhub,代码行数:15,代码来源:HttpServer.java

示例8: undeployServlet

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

示例9: updateServlets

import org.eclipse.jetty.servlet.ServletMapping; //导入依赖的package包/类
private void updateServlets() {
  if (handler != null) {
    final Holder[] snapshot = servlets.toArray(new Holder[servlets.size()]);
    final ServletHolder[] holders = new ServletHolder[snapshot.length];
    final ServletMapping[] mappings = new ServletMapping[snapshot.length];
    for (int i = 0; i < snapshot.length; ++i) {
      holders[i] = snapshot[i].holder;
      mappings[i] = snapshot[i].mapping;
    }
    handler.setServlets(holders);
    handler.setServletMappings(mappings);
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:14,代码来源:WebServer.java

示例10: Holder

import org.eclipse.jetty.servlet.ServletMapping; //导入依赖的package包/类
private Holder(@NotNull String pathSpec, @NotNull Servlet servlet) {
  path = pathSpec;
  holder = new ServletHolder(servlet);
  mapping = new ServletMapping();
  mapping.setServletName(holder.getName());
  mapping.setPathSpec(pathSpec);
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:8,代码来源:WebServer.java


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