org.apache.catalina.Wrapper.setServletClass()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(202)

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

Wrapper.setServletClass介绍

[英]Sets the class object from which this servlet will be instantiated.
[中]设置将从中实例化此servlet的类对象。

代码示例

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

private void addJspServlet(Context context) {
  Wrapper jspServlet = context.createWrapper();
  jspServlet.setName("jsp");
  jspServlet.setServletClass(getJsp().getClassName());
  jspServlet.addInitParameter("fork", "false");
  getJsp().getInitParameters().forEach(jspServlet::addInitParameter);
  jspServlet.setLoadOnStartup(3);
  context.addChild(jspServlet);
  context.addServletMappingDecoded("*.jsp", "jsp");
  context.addServletMappingDecoded("*.jspx", "jsp");
}

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

private void addDefaultServlet(Context context) {
  Wrapper defaultServlet = context.createWrapper();
  defaultServlet.setName("default");
  defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
  defaultServlet.addInitParameter("debug", "0");
  defaultServlet.addInitParameter("listings", "false");
  defaultServlet.setLoadOnStartup(1);
  // Otherwise the default location of a Spring DispatcherServlet cannot be set
  defaultServlet.setOverridable(true);
  context.addChild(defaultServlet);
  context.addServletMappingDecoded("/", "default");
}

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

@Override
  protected void initInternal() throws LifecycleException {
    super.initInternal();
    final Wrapper servlet = createWrapper();
    servlet.setName(ServerServlet.class.getSimpleName());
    servlet.setServletClass(ServerServlet.class.getName());
    addChild(servlet);
    addServletMappingDecoded(MAPPING, ServerServlet.class.getSimpleName());
  }
}

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

private void ensureMyFacesDontLooseFacesContext(final StandardContext standardContext) {
  for (final Container w : standardContext.findChildren()) {
    if (!Wrapper.class.isInstance(w)) {
      continue;
    }
    final Wrapper wrapper = Wrapper.class.cast(w);
    if ("FacesServlet".equals(wrapper.getName()) && "javax.faces.webapp.FacesServlet".equals(wrapper.getServletClass())) {
      final ClassLoader loader = standardContext.getLoader().getClassLoader();
      try {
        if (Files.toFile(loader.getResource("javax/faces/webapp/FacesServlet.class")).getName().startsWith("myfaces")) {
          loader.loadClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet");
          wrapper.setServletClass("org.apache.tomee.myfaces.TomEEWorkaroundFacesServlet");
          break;
        }
      } catch (final Throwable t) {
        // not there, not a big deal in most of cases
      }
    }
  }
}

代码示例来源:origin: org.apache.tomee/livereload-tomee

@Override
protected void initInternal() throws LifecycleException {
  super.initInternal();
  {// fake/not really desired "/*" servlet to ensure in context valve we match the request and got to WS filter
    final Wrapper servlet = createWrapper();
    servlet.setName(DefaultServlet.class.getSimpleName());
    servlet.setServletClass(DefaultServlet.class.getName());
    addChild(servlet);
    addServletMappingDecoded("/*", DefaultServlet.class.getSimpleName());
  }
  {// the js injected in the page
    final Wrapper servlet = createWrapper();
    servlet.setName(LiveReloadJs.class.getSimpleName());
    servlet.setServletClass(LiveReloadJs.class.getName());
    addChild(servlet);
    addServletMappingDecoded("/livereload.js", LiveReloadJs.class.getSimpleName());
  }
}

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

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx,
                 String servletName,
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  return sw;
}

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

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx, 
                 String servletName, 
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  
  return sw;
}

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

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx,
                 String servletName,
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  return sw;
}

代码示例来源:origin: org.apache.catalina/com.springsource.org.apache.catalina

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx, 
                 String servletName, 
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  
  return sw;
}

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

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx, 
                 String servletName, 
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  
  return sw;
}

代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx,
                 String servletName,
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  return sw;
}

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

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx, 
                 String servletName, 
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  
  return sw;
}

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

/**
 * Static version of {@link #addServlet(String, String, String)}
 * @param ctx           Context to add Servlet to
 * @param servletName   Servlet name (used in mappings)
 * @param servletClass  The class to be used for the Servlet
 * @return The wrapper for the servlet
 */
public static Wrapper addServlet(Context ctx, 
                 String servletName, 
                 String servletClass) {
  // will do class for name and set init params
  Wrapper sw = ctx.createWrapper();
  sw.setServletClass(servletClass);
  sw.setName(servletName);
  ctx.addChild(sw);
  
  return sw;
}

代码示例来源:origin: chrismattmann/lucene-geo-gazetteer

public static void launchService(int port, String indexPath)
    throws IOException, LifecycleException {
  Tomcat server = new Tomcat();
  Context context = server.addContext("/", new File(".").getAbsolutePath());
  System.setProperty(INDEX_PATH_PROP, indexPath);
  Wrapper servlet = context.createWrapper();
  servlet.setName("CXFNonSpringJaxrs");
  servlet.setServletClass(CXFNonSpringJaxrsServlet.class.getName());
  servlet.addInitParameter("jaxrs.serviceClasses", SearchResource.class.getName() + " " + HealthCheckAPI.class.getName());
  servlet.setLoadOnStartup(1);
  context.addChild(servlet);
  context.addServletMapping("/api/*", "CXFNonSpringJaxrs");
  System.out.println("Starting Embedded Tomcat on port : " + port );
  server.setPort(port);
  server.start();
  server.getServer().await();
}

代码示例来源:origin: net.disy.legato/legato-testing

@Override
public void addServletWithMapping(
  final String contextPath,
  final String servletClassName,
  final String servletMapping) {
 final Context context = getContext(contextPath);
 final Wrapper wrapper = context.createWrapper();
 wrapper.setName(servletClassName);
 wrapper.setServletClass(servletClassName);
 context.addChild(wrapper);
 context.addServletMapping(contextPath + servletMapping, servletClassName);
}

代码示例来源:origin: apache/tomcat-maven-plugin

private void createStaticContext( final Tomcat container, Context context, Host host )
{
  if ( staticContextDocbase != null )
  {
    Context staticContext = container.addContext( staticContextPath, staticContextDocbase );
    staticContext.setPrivileged( true );
    Wrapper servlet = context.createWrapper();
    servlet.setServletClass( DefaultServlet.class.getName() );
    servlet.setName( "staticContent" );
    staticContext.addChild( servlet );
    staticContext.addServletMapping( "/", "staticContent" );
    // see https://issues.apache.org/jira/browse/MTOMCAT-238
    //host.addChild( staticContext );
  }
}

代码示例来源:origin: com.tomitribe.tribestream/tribestream-container

public ProgrammaticContext addServlet(final String name, final Class<?> type, final String mapping, final String... initParams) {
  final Wrapper wrapper = createWrapper();
  wrapper.setServletClass(type.getName());
  wrapper.setName(name);
  if (initParams != null && initParams.length > 0) {
    for (int i = 0; i < initParams.length; i+=2) {
      wrapper.addInitParameter(initParams[i], initParams[i+1]);
    }
  }
  wrapper.setLoadOnStartup(1); // otherwise we would miss reposgitry integration at least
  addChild(wrapper);
  addServletMapping(mapping, wrapper.getName(), false);
  return this;
}

代码示例来源:origin: apache/tomcat-maven-plugin

private void createStaticContext( final Embedded container, Context context, Host host )
{
  if ( staticContextDocbase != null )
  {
    Context staticContext = container.createContext( staticContextPath, staticContextDocbase );
    staticContext.setPrivileged( true );
    Wrapper servlet = context.createWrapper();
    servlet.setServletClass( DefaultServlet.class.getName() );
    servlet.setName( "staticContent" );
    staticContext.addChild( servlet );
    staticContext.addServletMapping( "/", "staticContent" );
    host.addChild( staticContext );
  }
}

代码示例来源:origin: apache/tomcat-maven-plugin

private void createStaticContext( final Tomcat container, Context context, Host host )
{
  if ( staticContextDocbase != null )
  {
    Context staticContext = container.addContext( staticContextPath, staticContextDocbase );
    Tomcat.initWebappDefaults(staticContext);
    staticContext.setPrivileged( true );
    Wrapper servlet = context.createWrapper();
    servlet.setServletClass( DefaultServlet.class.getName() );
    servlet.setName( "staticContent" );
    staticContext.addChild( servlet );
    staticContext.addServletMapping( "/", "staticContent" );
    // see https://issues.apache.org/jira/browse/MTOMCAT-238
    //host.addChild( staticContext );
  }
}

代码示例来源:origin: nutzam/nutzboot

private void addDefaultServlet() {
  Wrapper defaultServlet = this.tomcatContext.createWrapper();
  defaultServlet.setName("default");
  defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
  defaultServlet.addInitParameter("debug", "0");
  defaultServlet.addInitParameter("listings", "false");
  defaultServlet.setLoadOnStartup(1);
  defaultServlet.setOverridable(true);
  this.tomcatContext.addChild(defaultServlet);
  addServletMapping("/", "default");
}

相关文章