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