org.apache.catalina.startup.Tomcat.addServlet()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中org.apache.catalina.startup.Tomcat.addServlet()方法的一些代码示例,展示了Tomcat.addServlet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tomcat.addServlet()方法的具体详情如下:
包路径:org.apache.catalina.startup.Tomcat
类名称:Tomcat
方法名:addServlet

Tomcat.addServlet介绍

[英]Equivalent with . In general it is better/faster to use the method that takes a Servlet as param - this one can be used if the servlet is not commonly used, and want to avoid loading all deps. ( for example: jsp servlet ) You can customize the returned servlet, ex: wrapper.addInitParameter("name", "value");
[中]相当于。一般来说,使用将Servlet作为参数的方法更好/更快——如果Servlet不常用,并且希望避免加载所有DEP,可以使用这个方法。(例如:jsp servlet)您可以自定义返回的servlet,例如:wrapper。addInitParameter(“名称”、“值”);

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void initServer() throws Exception {
  this.tomcatServer = new Tomcat();
  this.tomcatServer.setBaseDir(baseDir);
  this.tomcatServer.setHostname(getHost());
  this.tomcatServer.setPort(getPort());
  ServletHttpHandlerAdapter servlet = initServletAdapter();
  File base = new File(System.getProperty("java.io.tmpdir"));
  Context rootContext = tomcatServer.addContext(this.contextPath, base.getAbsolutePath());
  Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet).setAsyncSupported(true);
  rootContext.addServletMappingDecoded(this.servletMapping, "httpHandlerServlet");
  if (wsListener != null) {
    rootContext.addApplicationListener(wsListener.getName());
  }
}

代码示例来源:origin: apache/incubator-dubbo

Tomcat.addServlet(context, "dispatcher", new DispatcherServlet());
context.addServletMapping("/*", "dispatcher");
ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());

代码示例来源:origin: spring-projects/spring-framework

@Override
public void deployConfig(WebApplicationContext wac, Filter... filters) {
  Assert.state(this.port != -1, "setup() was never called.");
  this.context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
  this.context.addApplicationListener(WsContextListener.class.getName());
  Tomcat.addServlet(this.context, "dispatcherServlet", new DispatcherServlet(wac)).setAsyncSupported(true);
  this.context.addServletMappingDecoded("/", "dispatcherServlet");
  for (Filter filter : filters) {
    FilterDef filterDef = new FilterDef();
    filterDef.setFilterName(filter.getClass().getName());
    filterDef.setFilter(filter);
    filterDef.setAsyncSupported("true");
    this.context.addFilterDef(filterDef);
    FilterMap filterMap = new FilterMap();
    filterMap.setFilterName(filter.getClass().getName());
    filterMap.addURLPattern("/*");
    filterMap.setDispatcher("REQUEST,FORWARD,INCLUDE,ASYNC");
    this.context.addFilterMap(filterMap);
  }
}

代码示例来源:origin: apache/incubator-dubbo

Tomcat.addServlet(context, "dispatcher", new DispatcherServlet());
context.addServletMapping("/*", "dispatcher");
ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());

代码示例来源:origin: org.springframework.boot/spring-boot

protected void prepareContext(Host host, TomcatHttpHandlerAdapter servlet) {
  File docBase = createTempDir("tomcat-docbase");
  TomcatEmbeddedContext context = new TomcatEmbeddedContext();
  context.setPath("");
  context.setDocBase(docBase.getAbsolutePath());
  context.addLifecycleListener(new Tomcat.FixContextListener());
  context.setParentClassLoader(ClassUtils.getDefaultClassLoader());
  skipAllTldScanning(context);
  WebappLoader loader = new WebappLoader(context.getParentClassLoader());
  loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName());
  loader.setDelegate(true);
  context.setLoader(loader);
  Tomcat.addServlet(context, "httpHandlerServlet", servlet).setAsyncSupported(true);
  context.addServletMappingDecoded("/", "httpHandlerServlet");
  host.addChild(context);
  configureContext(context);
}

代码示例来源:origin: AsyncHttpClient/async-http-client

Context ctx = tomcat.addContext("", path);
Tomcat.addServlet(ctx, "webdav", new WebdavServlet() {
 @Override
 public void init(ServletConfig config) throws ServletException {

代码示例来源:origin: OryxProject/oryx

Tomcat.addServlet(context, "Jersey", "org.glassfish.jersey.servlet.ServletContainer");
wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName());

代码示例来源:origin: AsyncHttpClient/async-http-client

Context ctx = tomcat.addContext("", path);
Wrapper wrapper = Tomcat.addServlet(ctx, "webdav", new HttpServlet() {

代码示例来源:origin: org.apache.airavata/airavata-embedded-tomcat

/**
 * Add an existing Servlet to the context with no class.forName or
 * initialisation.
 *
 * @param contextPath Context to add Servlet to
 * @param servletName Servlet name (used in mappings)
 * @param servlet     The Servlet to add
 * @return The wrapper for the servlet
 */
public Wrapper addServlet(String contextPath,
             String servletName,
             Servlet servlet) {
  return tomcat.addServlet(contextPath, servletName, servlet);
}

代码示例来源:origin: spring-projects/spring-restdocs

@Override
protected void before() throws LifecycleException {
  this.tomcat = new Tomcat();
  this.tomcat.getConnector().setPort(0);
  Context context = this.tomcat.addContext("/", null);
  this.tomcat.addServlet("/", "test", new TestServlet());
  context.addServletMappingDecoded("/", "test");
  this.tomcat.addServlet("/", "set-cookie", new CookiesServlet());
  context.addServletMappingDecoded("/set-cookie", "set-cookie");
  this.tomcat.start();
  this.port = this.tomcat.getConnector().getLocalPort();
}

代码示例来源:origin: spring-projects/spring-integration

public TomcatWebSocketTestServer(Class<?>... serverConfigs) {
  this.tomcatServer = new Tomcat();
  this.tomcatServer.setPort(0);
  this.tomcatServer.setBaseDir(createTempDir());
  this.serverContext = new AnnotationConfigWebApplicationContext();
  this.serverContext.register(serverConfigs);
  Context context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
  context.addApplicationListener(WsContextListener.class.getName());
  Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(this.serverContext))
      .setAsyncSupported(true);
  context.addServletMappingDecoded("/", "dispatcherServlet");
}

代码示例来源:origin: myrrix/myrrix-recommender

private static Wrapper addServlet(Context context, Servlet servlet, String path) {
 String name = servlet.getClass().getSimpleName();
 Wrapper servletWrapper = Tomcat.addServlet(context, name, servlet);
 servletWrapper.setLoadOnStartup(1);
 context.addServletMapping(path, name);
 return servletWrapper;
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9

/**
 * Add an existing Servlet to the context with no class.forName or
 * initialisation.
 * @param contextPath   Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servlet       The Servlet to add
 * @return The wrapper for the servlet
 */
public Wrapper addServlet(String contextPath, 
    String servletName, 
    Servlet servlet) {
  Container ctx = getHost().findChild(contextPath);
  return addServlet((Context) ctx, servletName, servlet);
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

/**
 * Add an existing Servlet to the context with no class.forName or
 * initialisation.
 * @param contextPath   Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servlet       The Servlet to add
 * @return The wrapper for the servlet
 */
public Wrapper addServlet(String contextPath,
    String servletName,
    Servlet servlet) {
  Container ctx = getHost().findChild(contextPath);
  return addServlet((Context) ctx, servletName, servlet);
}

代码示例来源:origin: codefollower/Tomcat-Research

/**
 * Add an existing Servlet to the context with no class.forName or
 * initialisation.
 * @param contextPath   Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servlet       The Servlet to add
 * @return The wrapper for the servlet
 */
public Wrapper addServlet(String contextPath,
    String servletName,
    Servlet servlet) {
  Container ctx = getHost().findChild(contextPath);
  return addServlet((Context) ctx, servletName, servlet);
}

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

/**
 * Add an existing Servlet to the context with no class.forName or
 * initialisation.
 * @param contextPath   Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servlet       The Servlet to add
 * @return The wrapper for the servlet
 */
public Wrapper addServlet(String contextPath, 
    String servletName, 
    Servlet servlet) {
  Container ctx = getHost().findChild(contextPath);
  return addServlet((Context) ctx, servletName, servlet);
}

代码示例来源:origin: org.apache.geronimo.ext.tomcat/catalina

/**
 * Add an existing Servlet to the context with no class.forName or
 * initialisation.
 * @param contextPath   Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servlet       The Servlet to add
 * @return The wrapper for the servlet
 */
public Wrapper addServlet(String contextPath, 
    String servletName, 
    Servlet servlet) {
  Container ctx = getHost().findChild(contextPath);
  return addServlet((Context) ctx, servletName, servlet);
}

代码示例来源:origin: fabric8io/shootout-docker-maven

public static void main(String[] args) throws LifecycleException, SQLException {
  Tomcat tomcat = new Tomcat();
  tomcat.setPort(8080);
  File base = new File(System.getProperty("java.io.tmpdir"));
  Context rootCtx = tomcat.addContext("/", base.getAbsolutePath());
  Tomcat.addServlet(rootCtx, "log", new LogService());
  rootCtx.addServletMapping("/*", "log");
  tomcat.start();
  tomcat.getServer().await();
}

代码示例来源:origin: hantsy/spring-reactive-sample

@Bean
public Tomcat embededTomcatServer(ApplicationContext context) throws Exception {
  HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build(); 
  // Tomcat and Jetty (also see notes below)
  Servlet servlet = new TomcatHttpHandlerAdapter(handler);
  Tomcat tomcatServer = new Tomcat();
  tomcatServer.setHostname("localhost");
  tomcatServer.setPort(this.port);
  Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
  Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
  rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
  return tomcatServer;
}

代码示例来源:origin: poutsma/web-function-sample

public void startTomcatServer() throws LifecycleException {
  RouterFunction<?> route = routingFunction();
  HttpHandler httpHandler = toHttpHandler(route);
  Tomcat tomcatServer = new Tomcat();
  tomcatServer.setHostname(HOST);
  tomcatServer.setPort(PORT);
  Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
  ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
  Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
  rootContext.addServletMapping("/", "httpHandlerServlet");
  tomcatServer.start();
}

相关文章