org.springframework.boot.web.servlet.server.ServletWebServerFactory#org.apache.catalina.loader.WebappLoader源码实例Demo

下面列出了org.springframework.boot.web.servlet.server.ServletWebServerFactory#org.apache.catalina.loader.WebappLoader 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Tomcat8-Source-Read   文件: MBeanFactory.java
/**
 * Create a new Web Application Loader.
 *
 * @param parent MBean Name of the associated parent component
 * @return the object name of the created loader
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createWebappLoader(String parent)
    throws Exception {

    // Create a new WebappLoader instance
    WebappLoader loader = new WebappLoader();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Container container = getParentContainerFromParent(pname);
    if (container instanceof Context) {
        ((Context) container).setLoader(loader);
    }
    // FIXME add Loader.getObjectName
    //ObjectName oname = loader.getObjectName();
    ObjectName oname =
        MBeanUtils.createObjectName(pname.getDomain(), loader);
    return oname.toString();

}
 
源代码2 项目: micro-integrator   文件: Starter.java
public void startPeopleService() throws Exception {
    final File base = createBaseDirectory();
    log.info("Using base folder: " + base.getAbsolutePath());

    final Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    tomcat.setBaseDir(base.getAbsolutePath());

    Context context = tomcat.addContext("/", base.getAbsolutePath());
    Tomcat.addServlet(context, "CXFServlet", new CXFServlet());

    context.addServletMapping("/rest/*", "CXFServlet");
    context.addApplicationListener(ContextLoaderListener.class.getName());
    context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));

    context.addParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.addParameter("contextConfigLocation", AppConfig.class.getName());

    tomcat.start();
    tomcat.getServer().await();
}
 
源代码3 项目: micro-integrator   文件: Server.java
public static void main(final String[] args) throws Exception {
    final File base = createBaseDirectory();
    log.info("Using base folder: " + base.getAbsolutePath());

    final Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    tomcat.setBaseDir(base.getAbsolutePath());

    Context context = tomcat.addContext("/", base.getAbsolutePath());
    Tomcat.addServlet(context, "CXFServlet", new CXFServlet());

    context.addServletMapping("/rest/*", "CXFServlet");
    context.addApplicationListener(ContextLoaderListener.class.getName());
    context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));

    context.addParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.addParameter("contextConfigLocation", MusicConfig.class.getName());

    tomcat.start();
    tomcat.getServer().await();
}
 
源代码4 项目: Tomcat7.0.67   文件: MBeanFactory.java
/**
 * Create a new Web Application Loader.
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createWebappLoader(String parent)
    throws Exception {

    // Create a new WebappLoader instance
    WebappLoader loader = new WebappLoader();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ContainerBase containerBase = getParentContainerFromParent(pname);
    if (containerBase != null) {
        containerBase.setLoader(loader);
    } 
    // FIXME add Loader.getObjectName
    //ObjectName oname = loader.getObjectName();
    ObjectName oname = 
        MBeanUtils.createObjectName(pname.getDomain(), loader);
    return (oname.toString());
    
}
 
源代码5 项目: tomcatsrc   文件: MBeanFactory.java
/**
 * Create a new Web Application Loader.
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createWebappLoader(String parent)
    throws Exception {

    // Create a new WebappLoader instance
    WebappLoader loader = new WebappLoader();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ContainerBase containerBase = getParentContainerFromParent(pname);
    if (containerBase != null) {
        containerBase.setLoader(loader);
    } 
    // FIXME add Loader.getObjectName
    //ObjectName oname = loader.getObjectName();
    ObjectName oname = 
        MBeanUtils.createObjectName(pname.getDomain(), loader);
    return (oname.toString());
    
}
 
源代码6 项目: product-ei   文件: Starter.java
public void startPeopleService() throws Exception {
    final File base = createBaseDirectory();
    log.info("Using base folder: " + base.getAbsolutePath());

    final Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    tomcat.setBaseDir(base.getAbsolutePath());

    Context context = tomcat.addContext("/", base.getAbsolutePath());
    Tomcat.addServlet(context, "CXFServlet", new CXFServlet());

    context.addServletMapping("/rest/*", "CXFServlet");
    context.addApplicationListener(ContextLoaderListener.class.getName());
    context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));

    context.addParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.addParameter("contextConfigLocation", AppConfig.class.getName());

    tomcat.start();
    tomcat.getServer().await();
}
 
源代码7 项目: product-ei   文件: Server.java
public static void main(final String[] args) throws Exception {
    final File base = createBaseDirectory();
    log.info("Using base folder: " + base.getAbsolutePath());

    final Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    tomcat.setBaseDir( base.getAbsolutePath() );

    Context context = tomcat.addContext( "/", base.getAbsolutePath() );
    Tomcat.addServlet( context, "CXFServlet", new CXFServlet() );

    context.addServletMapping( "/rest/*", "CXFServlet" );
    context.addApplicationListener( ContextLoaderListener.class.getName() );
    context.setLoader( new WebappLoader( Thread.currentThread().getContextClassLoader() ) );

    context.addParameter( "contextClass", AnnotationConfigWebApplicationContext.class.getName() );
    context.addParameter( "contextConfigLocation", MusicConfig.class.getName() );

    tomcat.start();
    tomcat.getServer().await();
}
 
@Before
public void setUp() throws Exception {
    this.request = mock(Request.class, withSettings().useConstructor()); // useConstructor to instantiate fields
    this.response = mock(Response.class);

    final Context contextContainer = mock(Context.class);
    this.hostContainer = mock(Host.class);

    when(contextContainer.getParent()).thenReturn(hostContainer);
    when(contextContainer.getPath()).thenReturn("/");

    when(request.getRequestURI()).thenReturn("/requestURI"); // override for tests
    when(request.getMethod()).thenReturn("GET");
    when(request.getQueryString()).thenReturn(null);
    when(request.getContext()).thenReturn(contextContainer);

    doCallRealMethod().when(request).setNote(Mockito.anyString(), Mockito.anyObject());
    doCallRealMethod().when(request).removeNote(Mockito.anyString());
    when(request.getNote(Mockito.anyString())).thenCallRealMethod();

    when(contextContainer.getLoader()).thenReturn(new WebappLoader(Thread.currentThread().getContextClassLoader()));
}
 
源代码9 项目: glowroot   文件: JsfRenderIT.java
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    Context context =
            tomcat.addWebapp("", new File("src/test/resources").getAbsolutePath());

    WebappLoader webappLoader = new WebappLoader(RenderJsfInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    tomcat.start();

    doTest(port);

    tomcat.stop();
    tomcat.destroy();
}
 
源代码10 项目: glowroot   文件: GrailsIT.java
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    Context context =
            tomcat.addWebapp("", new File("src/test/resources").getAbsolutePath());

    WebappLoader webappLoader = new WebappLoader(RenderInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    // this is needed in order for Tomcat to find annotated classes
    VirtualDirContext resources = new VirtualDirContext();
    resources.setExtraResourcePaths("/WEB-INF/classes=target/test-classes");
    context.setResources(resources);

    tomcat.start();

    doTest(port);

    tomcat.stop();
    tomcat.destroy();
}
 
源代码11 项目: glowroot   文件: InvokeServletInTomcat.java
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    Context context =
            tomcat.addWebapp(contextPath, new File("src/test/resources").getAbsolutePath());

    WebappLoader webappLoader =
            new WebappLoader(InvokeServletInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    // this is needed in order for Tomcat to find annotated servlet
    VirtualDirContext resources = new VirtualDirContext();
    resources.setExtraResourcePaths("/WEB-INF/classes=target/test-classes");
    context.setResources(resources);

    tomcat.start();

    doTest(port);

    tomcat.stop();
    tomcat.destroy();
}
 
源代码12 项目: glowroot   文件: StrutsOneIT.java
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    Context context =
            tomcat.addWebapp("", new File("src/test/resources/struts1").getAbsolutePath());

    WebappLoader webappLoader =
            new WebappLoader(ExecuteActionInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    tomcat.start();

    AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + "/hello.do")
            .execute().get().getStatusCode();
    asyncHttpClient.close();
    if (statusCode != 200) {
        throw new IllegalStateException("Unexpected status code: " + statusCode);
    }

    tomcat.stop();
    tomcat.destroy();
}
 
源代码13 项目: glowroot   文件: InvokeJaxrsResourceInTomcat.java
public void executeApp(String webapp, String contextPath, String url) throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    Context context = tomcat.addWebapp(contextPath,
            new File("src/test/resources/" + webapp).getAbsolutePath());

    WebappLoader webappLoader =
            new WebappLoader(InvokeJaxrsResourceInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    tomcat.start();
    AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + contextPath + url)
            .execute().get().getStatusCode();
    asyncHttpClient.close();
    if (statusCode != 200) {
        throw new IllegalStateException("Unexpected status code: " + statusCode);
    }

    tomcat.stop();
    tomcat.destroy();
}
 
源代码14 项目: glowroot   文件: InvokeJaxwsWebServiceInTomcat.java
public void executeApp(String webapp, String contextPath, String url) throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    Context context = tomcat.addWebapp(contextPath,
            new File("src/test/resources/" + webapp).getAbsolutePath());

    WebappLoader webappLoader =
            new WebappLoader(InvokeJaxwsWebServiceInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    tomcat.start();

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(ForBothHelloAndRootService.class);
    factory.setAddress("http://localhost:" + port + contextPath + url);
    ForBothHelloAndRootService client = (ForBothHelloAndRootService) factory.create();
    client.echo("abc");

    checkForRequestThreads(webappLoader);
    tomcat.stop();
    tomcat.destroy();
}
 
源代码15 项目: glowroot   文件: InvokeJaxwsWebServiceInTomcat.java
private void checkForRequestThreads(WebappLoader webappLoader) throws Exception {
    Method getThreadsMethod = WebappClassLoaderBase.class.getDeclaredMethod("getThreads");
    getThreadsMethod.setAccessible(true);
    Method isRequestThreadMethod =
            WebappClassLoaderBase.class.getDeclaredMethod("isRequestThread", Thread.class);
    isRequestThreadMethod.setAccessible(true);
    ClassLoader webappClassLoader = webappLoader.getClassLoader();
    Thread[] threads = (Thread[]) getThreadsMethod.invoke(webappClassLoader);
    for (Thread thread : threads) {
        if (thread == null) {
            continue;
        }
        if ((boolean) isRequestThreadMethod.invoke(webappClassLoader, thread)) {
            StringBuilder sb = new StringBuilder();
            for (StackTraceElement element : thread.getStackTrace()) {
                sb.append(element);
                sb.append('\n');
            }
            logger.error("tomcat request thread \"{}\" is still active:\n{}", thread.getName(),
                    sb);
        }
    }
}
 
源代码16 项目: glowroot   文件: InvokeSpringControllerInTomcat.java
private void checkForRequestThreads(WebappLoader webappLoader) throws Exception {
    Method getThreadsMethod = WebappClassLoaderBase.class.getDeclaredMethod("getThreads");
    getThreadsMethod.setAccessible(true);
    Method isRequestThreadMethod =
            WebappClassLoaderBase.class.getDeclaredMethod("isRequestThread", Thread.class);
    isRequestThreadMethod.setAccessible(true);
    ClassLoader webappClassLoader = webappLoader.getClassLoader();
    Thread[] threads = (Thread[]) getThreadsMethod.invoke(webappClassLoader);
    for (Thread thread : threads) {
        if (thread == null) {
            continue;
        }
        if ((Boolean) isRequestThreadMethod.invoke(webappClassLoader, thread)) {
            StringBuilder sb = new StringBuilder();
            for (StackTraceElement element : thread.getStackTrace()) {
                sb.append(element);
                sb.append('\n');
            }
            logger.error("tomcat request thread \"{}\" is still active:\n{}", thread.getName(),
                    sb);
        }
    }
}
 
源代码17 项目: pinpoint   文件: WebappLoaderStartInterceptor.java
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    // target should be an instance of WebappLoader.
    if (target instanceof WebappLoader) {
        WebappLoader webappLoader = (WebappLoader)target;
        try {
            String contextKey = extractContextKey(webappLoader);
            List<String> loadedJarNames = extractLibJars(webappLoader);
            dispatchLibJars(contextKey, loadedJarNames);
        } catch (Exception e) {
            if (logger.isWarnEnabled()) {
                logger.warn(e.getMessage(), e);
            }
        }
    } else {
        logger.warn("Webapp loader is not an instance of org.apache.catalina.loader.WebappLoader. Found [{}]", target.getClass().toString());
    }
}
 
源代码18 项目: pinpoint   文件: WebappLoaderStartInterceptor.java
private String extractContextKey(WebappLoader webappLoader) {
    final String defaultContextName = "";
    try {
        Container container = extractContext(webappLoader);
        // WebappLoader's associated Container should be a Context.
        if (container instanceof Context) {
            Context context = (Context)container;
            String contextName = context.getName();
            Host host = (Host)container.getParent();
            Engine engine = (Engine)host.getParent();
            StringBuilder sb = new StringBuilder();
            sb.append(engine.getName()).append("/").append(host.getName());
            if (!contextName.startsWith("/")) {
                sb.append('/');
            }
            sb.append(contextName);
            return sb.toString();
        }
    } catch (Exception e) {
        // Same action for any and all exceptions.
        logger.warn("Error extracting context name.", e);
    }
    return defaultContextName;
}
 
源代码19 项目: pinpoint   文件: WebappLoaderStartInterceptor.java
private Container extractContext(WebappLoader webappLoader) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Method m;
    try {
        // Tomcat 6, 7 - org.apache.catalina.loader.getContainer() 
        m = webappLoader.getClass().getDeclaredMethod("getContainer");
    } catch (NoSuchMethodException e1) {
        try {
            // Tomcat 8 - org.apache.catalina.loader.getContainer()
            m = webappLoader.getClass().getDeclaredMethod("getContext");
        } catch (NoSuchMethodException e2) {
            logger.warn("Webapp loader does not have access to its container.");
            return null;
        }
    }
    Object container = m.invoke(webappLoader);
    if (container instanceof Container) {
        return (Container)container;
    }
    return null;
}
 
源代码20 项目: Tomcat8-Source-Read   文件: LoaderSF.java
/**
 * Is this an instance of the default <code>Loader</code> configuration,
 * with all-default properties?
 *
 * @param loader
 *            Loader to be tested
 * @return <code>true</code> if this is an instance of the default loader
 */
protected boolean isDefaultLoader(Loader loader) {

    if (!(loader instanceof WebappLoader)) {
        return false;
    }
    WebappLoader wloader = (WebappLoader) loader;
    if ((wloader.getDelegate() != false)
            || !wloader.getLoaderClass().equals(
                    "org.apache.catalina.loader.WebappClassLoader")) {
        return false;
    }
    return true;
}
 
@Override
protected void prepareContext(Host host, ServletContextInitializer[] initializers) {
    if (host.getState() == LifecycleState.NEW) {
        super.prepareContext(host, initializers);
    } else {
        File documentRoot = getValidDocumentRoot();
        StandardContext context = new StandardContext();
        if (documentRoot != null) {
            context.setResources(new StandardRoot(context));
        }
        context.setName(getContextPath());
        context.setDisplayName(getDisplayName());
        context.setPath(getContextPath());
        File docBase = (documentRoot != null) ? documentRoot : createTempDir("tomcat-docbase");
        context.setDocBase(docBase.getAbsolutePath());
        context.addLifecycleListener(new Tomcat.FixContextListener());
        context.setParentClassLoader(Thread.currentThread().getContextClassLoader());
        resetDefaultLocaleMapping(context);
        addLocaleMappings(context);
        context.setUseRelativeRedirects(false);
        configureTldSkipPatterns(context);
        WebappLoader loader = new WebappLoader(context.getParentClassLoader());
        loader
            .setLoaderClass("com.alipay.sofa.ark.web.embed.tomcat.ArkTomcatEmbeddedWebappClassLoader");
        loader.setDelegate(true);
        context.setLoader(loader);
        if (isRegisterDefaultServlet()) {
            addDefaultServlet(context);
        }
        if (shouldRegisterJspServlet()) {
            addJspServlet(context);
            addJasperInitializer(context);
        }
        context.addLifecycleListener(new StaticResourceConfigurer(context));
        ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
        context.setParent(host);
        configureContext(context, initializersToUse);
        host.addChild(context);
    }
}
 
源代码22 项目: Tomcat7.0.67   文件: Embedded.java
/**
 * Create and return a class loader manager that can be customized, and
 * then attached to a Context, before it is started.
 *
 * @param parent ClassLoader that will be the parent of the one
 *  created by this Loader
 */
public Loader createLoader(ClassLoader parent) {

    if( log.isDebugEnabled() )
        log.debug("Creating Loader with parent class loader '" +
                   parent + "'");

    WebappLoader loader = new WebappLoader(parent);
    return (loader);

}
 
源代码23 项目: uavstack   文件: SpringBootTomcatPlusIT.java
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);      
    }        
}
 
源代码24 项目: tomcatsrc   文件: Embedded.java
/**
 * Create and return a class loader manager that can be customized, and
 * then attached to a Context, before it is started.
 *
 * @param parent ClassLoader that will be the parent of the one
 *  created by this Loader
 */
public Loader createLoader(ClassLoader parent) {

    if( log.isDebugEnabled() )
        log.debug("Creating Loader with parent class loader '" +
                   parent + "'");

    WebappLoader loader = new WebappLoader(parent);
    return (loader);

}
 
源代码25 项目: glowroot   文件: StrutsTwoIT.java
@Override
public void executeApp() throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    String subdir;
    try {
        Class.forName("org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter");
        subdir = "struts2.5";
    } catch (ClassNotFoundException e) {
        subdir = "struts2";
    }
    Context context = tomcat.addWebapp("",
            new File("src/test/resources/" + subdir).getAbsolutePath());

    WebappLoader webappLoader =
            new WebappLoader(ExecuteActionInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    tomcat.start();

    AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    int statusCode =
            asyncHttpClient.prepareGet("http://localhost:" + port + "/hello.action")
                    .execute().get().getStatusCode();
    asyncHttpClient.close();
    if (statusCode != 200) {
        throw new IllegalStateException("Unexpected status code: " + statusCode);
    }

    tomcat.stop();
    tomcat.destroy();
}
 
源代码26 项目: glowroot   文件: InvokeSpringControllerInTomcat.java
public void executeApp(String webapp, String contextPath, RunnableWithPort runnable)
        throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    Context context = tomcat.addWebapp(contextPath,
            new File("src/test/resources/" + webapp).getAbsolutePath());

    WebappLoader webappLoader =
            new WebappLoader(InvokeSpringControllerInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    tomcat.start();

    runnable.run(port);

    // spring still does a bit of work after the response is concluded,
    // see org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(),
    // so give a bit of time here, otherwise end up with sporadic test failures due to
    // ERROR logged by org.apache.catalina.loader.WebappClassLoaderBase, e.g.
    // "The web application [] is still processing a request that has yet to finish"
    MILLISECONDS.sleep(200);
    checkForRequestThreads(webappLoader);
    tomcat.stop();
    tomcat.destroy();
}
 
源代码27 项目: pinpoint   文件: WebappLoaderStartInterceptor.java
private List<String> extractLibJars(WebappLoader webappLoader) {
    ClassLoader classLoader = webappLoader.getClassLoader();
    if (classLoader instanceof URLClassLoader) {
        URLClassLoader webappClassLoader = (URLClassLoader)classLoader;
        URL[] urls = webappClassLoader.getURLs();
        return extractLibJarNamesFromURLs(urls);
    } else {
        logger.warn("Webapp class loader is not an instance of URLClassLoader. Found [{}]", classLoader.getClass().toString());
        return Collections.emptyList();
    } 
}
 
源代码28 项目: tomee   文件: TomcatWebAppBuilder.java
private void initContextLoader(final StandardContext standardContext) {
    final Loader standardContextLoader = standardContext.getLoader();
    if (standardContextLoader != null
            && (
            (!TomEEWebappLoader.class.equals(standardContextLoader.getClass())
                && !WebappLoader.class.equals(standardContextLoader.getClass()))
                    || (WebappLoader.class.equals(standardContextLoader.getClass())
                            && !WebappLoader.class.cast(standardContextLoader).getLoaderClass().startsWith("org.apache.tom")))
            ) {
        // custom loader, we don't know it
        // and since we don't have a full delegate pattern for our lazy stop loader
        // simply skip lazy stop loader - normally sides effect will be an early shutdown for ears and some particular features
        // only affecting the app if the classes were not laoded at all
        return;
    }

    if (standardContextLoader != null && TomEEWebappLoader.class.isInstance(standardContextLoader)) {
        standardContextLoader.setContext(standardContext);
        return; // no need to replace the loader
    }

    // we just want to wrap it to lazy stop it (afterstop)
    // to avoid classnotfound in @PreDestoy or destroyApplication()
    final TomEEWebappLoader loader = new TomEEWebappLoader();
    loader.setDelegate(standardContext.getDelegate());
    loader.setLoaderClass(TomEEWebappClassLoader.class.getName());

    final Loader lazyStopLoader = new LazyStopLoader(loader);
    standardContext.setLoader(lazyStopLoader);
}
 
public static void main(String... args) throws Exception {
	Registry.disableRegistry();

	tomcatBase.mkdir();
	docBase.mkdir();
	serverBase.mkdir();

	Tomcat tomcat = new Tomcat();
	tomcat.setBaseDir(serverBase.getAbsolutePath());
	Connector connector = new Connector(Http11NioProtocol.class.getName());
	connector.setThrowOnFailure(true);
	connector.setPort(8080);
	tomcat.getService().addConnector(connector);
	tomcat.setConnector(connector);
	tomcat.getHost().setAutoDeploy(false);

	TomcatEmbeddedContext context = new TomcatEmbeddedContext();
	context.setResources(new LoaderHidingResourceRoot(context));
	context.setName("ROOT");
	context.setDisplayName("sample-tomcat-context");
	context.setPath("");
	context.setDocBase(docBase.getAbsolutePath());
	context.addLifecycleListener(new Tomcat.FixContextListener());
	context.setParentClassLoader(Thread.currentThread().getContextClassLoader());
	context.addLocaleEncodingMappingParameter(Locale.ENGLISH.toString(), DEFAULT_CHARSET.displayName());
	context.addLocaleEncodingMappingParameter(Locale.FRENCH.toString(), DEFAULT_CHARSET.displayName());
	context.setUseRelativeRedirects(false);
	try {
		context.setCreateUploadTargets(true);
	}
	catch (NoSuchMethodError ex) {
		// Tomcat is < 8.5.39. Continue.
	}
	StandardJarScanFilter filter = new StandardJarScanFilter();
	filter.setTldSkip(collectionToDelimitedString(TldSkipPatterns.DEFAULT, ",", "", ""));
	context.getJarScanner().setJarScanFilter(filter);
	WebappLoader loader = new WebappLoader(context.getParentClassLoader());
	loader.setLoaderClass(TomcatEmbeddedWebappClassLoader.class.getName());
	loader.setDelegate(true);
	context.setLoader(loader);

	Wrapper helloServlet = context.createWrapper();
	String servletName = HelloFromTomcatServlet.class.getSimpleName();
	helloServlet.setName(servletName);
	helloServlet.setServletClass(HelloFromTomcatServlet.class.getName());
	helloServlet.setLoadOnStartup(1);
	helloServlet.setOverridable(true);
	context.addChild(helloServlet);
	context.addServletMappingDecoded("/", servletName);

	tomcat.getHost().addChild(context);
	tomcat.getHost().setAutoDeploy(false);
	TomcatWebServer server = new TomcatWebServer(tomcat);
	server.start();
}
 
@Override
protected void postProcessContext(Context context) {
    ((WebappLoader) context.getLoader())
        .setLoaderClass("com.alipay.sofa.ark.web.embed.tomcat.ArkTomcatEmbeddedWebappClassLoader");
}