Search in sources :

Example 1 with Wrapper

use of org.apache.catalina.Wrapper in project uavstack by uavorg.

the class SpringBootTomcatPlusIT method onDeployUAVApp.

public void onDeployUAVApp(Object... args) {
    if (UAVServer.ServerVendor.SPRINGBOOT != UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR)) {
        return;
    }
    Tomcat tomcat = (Tomcat) args[0];
    String mofRoot = (String) args[1];
    // add uavApp
    StandardContext context = new StandardContext();
    context.setName("com.creditease.uav");
    context.setPath("/com.creditease.uav");
    context.setDocBase(mofRoot + "/com.creditease.uav");
    context.addLifecycleListener(new Tomcat.FixContextListener());
    tomcat.getHost().addChild(context);
    // add default servlet
    Wrapper servlet = context.createWrapper();
    servlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
    servlet.setName("default");
    context.addChild(servlet);
    servlet.setOverridable(true);
    context.addServletMapping("/", "default");
    // init webapp classloader
    context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
    context.setDelegate(true);
    // after tomcat8, skip jarscan
    Object obj = ReflectionHelper.newInstance("org.apache.tomcat.util.scan.StandardJarScanner", Thread.currentThread().getContextClassLoader());
    if (obj != null) {
        ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanAllFiles", new Class<?>[] { Boolean.class }, new Object[] { false }, Thread.currentThread().getContextClassLoader());
        ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanClassPath", new Class<?>[] { Boolean.class }, new Object[] { false }, Thread.currentThread().getContextClassLoader());
        ReflectionHelper.invoke("org.apache.tomcat.util.scan.StandardJarScanner", obj, "setScanAllDirectories", new Class<?>[] { Boolean.class }, new Object[] { false }, Thread.currentThread().getContextClassLoader());
        context.setJarScanner((JarScanner) obj);
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) Tomcat(org.apache.catalina.startup.Tomcat) StandardContext(org.apache.catalina.core.StandardContext) WebappLoader(org.apache.catalina.loader.WebappLoader)

Example 2 with Wrapper

use of org.apache.catalina.Wrapper in project cxf by apache.

the class AbstractTomcatServer method run.

protected void run() {
    server = new Tomcat();
    server.setPort(port);
    try {
        final File base = createTemporaryDirectory();
        server.setBaseDir(base.getAbsolutePath());
        if (resourcePath == null) {
            final Context context = server.addContext("/", base.getAbsolutePath());
            final Wrapper cxfServlet = Tomcat.addServlet(context, "cxfServlet", new CXFNonSpringJaxrsServlet());
            cxfServlet.addInitParameter(CXFNonSpringJaxrsServlet.TRANSPORT_ID, SseHttpTransportFactory.TRANSPORT_ID);
            cxfServlet.addInitParameter("jaxrs.serviceClasses", BookStore.class.getName());
            cxfServlet.addInitParameter("jaxrs.providers", JacksonJsonProvider.class.getName());
            cxfServlet.setAsyncSupported(true);
            context.addServletMapping("/rest/*", "cxfServlet");
        } else {
            server.getHost().setAppBase(base.getAbsolutePath());
            server.getHost().setAutoDeploy(true);
            server.getHost().setDeployOnStartup(true);
            server.addWebapp(contextPath, getClass().getResource(resourcePath).toURI().getPath().toString());
        }
        server.start();
    } catch (final Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Context(org.apache.catalina.Context) Wrapper(org.apache.catalina.Wrapper) BookStore(org.apache.cxf.systest.jaxrs.sse.BookStore) Tomcat(org.apache.catalina.startup.Tomcat) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) File(java.io.File) IOException(java.io.IOException) CXFNonSpringJaxrsServlet(org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet)

Example 3 with Wrapper

use of org.apache.catalina.Wrapper in project nutzboot by nutzam.

the class TomcatStarter method addServlet.

private void addServlet(WebServletFace webServlet) {
    log.debugf("[NutzBoot] add servlet name=%s pathSpec=%s", webServlet.getName(), webServlet.getPathSpec());
    Wrapper servlet = tomcatContext.createWrapper();
    servlet.setName(webServlet.getName());
    servlet.setServletClass(webServlet.getServlet().getClass().getName());
    servlet.setServlet(webServlet.getServlet());
    for (Map.Entry<String, String> entry : webServlet.getInitParameters().entrySet()) {
        servlet.addInitParameter(entry.getKey(), entry.getValue());
    }
    servlet.setOverridable(true);
    this.tomcatContext.addChild(servlet);
    addServletMapping(webServlet.getPathSpec(), webServlet.getName());
}
Also used : Wrapper(org.apache.catalina.Wrapper) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) Map(java.util.Map)

Example 4 with Wrapper

use of org.apache.catalina.Wrapper in project nutzboot by nutzam.

the class TomcatStarter method addDefaultServlet.

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");
}
Also used : Wrapper(org.apache.catalina.Wrapper)

Example 5 with Wrapper

use of org.apache.catalina.Wrapper in project microservice-starter-tomcat by ERS-HCL.

the class App method main.

public static void main(String[] args) throws LifecycleException {
    Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    Context ctx = tomcat.addContext("/", new File(".").getAbsolutePath());
    Wrapper servletWrapper = Tomcat.addServlet(ctx, "rnd.web.service.rest.App", "org.glassfish.jersey.servlet.ServletContainer");
    servletWrapper.addInitParameter("javax.ws.rs.Application", "rnd.web.service.rest.AppConfig");
    ctx.addServletMappingDecoded("/*", "rnd.web.service.rest.App");
    tomcat.start();
    tomcat.getServer().await();
}
Also used : Context(org.apache.catalina.Context) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) File(java.io.File)

Aggregations

Wrapper (org.apache.catalina.Wrapper)200 Context (org.apache.catalina.Context)118 Tomcat (org.apache.catalina.startup.Tomcat)111 Test (org.junit.Test)69 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)62 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)53 AsyncContext (jakarta.servlet.AsyncContext)47 AsyncContext (javax.servlet.AsyncContext)30 TesterAccessLogValve (org.apache.catalina.valves.TesterAccessLogValve)29 ServletRequestWrapper (jakarta.servlet.ServletRequestWrapper)28 ServletResponseWrapper (jakarta.servlet.ServletResponseWrapper)28 IOException (java.io.IOException)28 TesterContext (org.apache.tomcat.unittest.TesterContext)28 File (java.io.File)25 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)24 ServletResponseWrapper (javax.servlet.ServletResponseWrapper)24 Container (org.apache.catalina.Container)22 StandardWrapper (org.apache.catalina.core.StandardWrapper)21 HashMap (java.util.HashMap)13 StandardContext (org.apache.catalina.core.StandardContext)12