Search in sources :

Example 1 with CxfRSService

use of org.apache.openejb.server.cxf.rs.CxfRSService in project tomee by apache.

the class ReloadingLoaderTest method tomcatClassLoaderParentShouldntBeNulAfterAStopStartOtherwiseReloadIsBroken.

@Test
public void tomcatClassLoaderParentShouldntBeNulAfterAStopStartOtherwiseReloadIsBroken() throws Exception {
    final CxfRSService server = new CxfRSService();
    try {
        server.init(new Properties());
        server.start();
        server.afterApplicationCreated(new AssemblerAfterApplicationCreated(info, context, Collections.<BeanContext>emptyList()));
        {
            final ClassLoader beforeLoader = SystemInstance.get().getComponent(ContainerSystem.class).getWebContext("test").getClassLoader();
            assertSame(loader, beforeLoader);
            assertNotNull(beforeLoader);
            assertNotNull(Reflections.get(beforeLoader, "parent"));
        }
        loader.internalStop();
        server.undeploy(new AssemblerBeforeApplicationDestroyed(info, context));
        {
            final URLClassLoader afterLoader = URLClassLoader.class.cast(SystemInstance.get().getComponent(ContainerSystem.class).getWebContext("test").getClassLoader());
            assertSame(loader, afterLoader);
            assertNotNull(afterLoader);
            assertEquals(0, afterLoader.getURLs().length);
            assertEquals(LifecycleState.STOPPED, loader.getState());
        }
        final StandardRoot resources = new StandardRoot();
        loader.setResources(resources);
        resources.setContext(new StandardContext() {

            @Override
            public String getDocBase() {
                final File file = new File("target/foo");
                file.mkdirs();
                return file.getAbsolutePath();
            }

            @Override
            public String getMBeanKeyProperties() {
                return "foo";
            }

            {
            }
        });
        resources.start();
        loader.start();
        // TomcatWebAppBuilder ill catch start event from StandardContext and force a classloader
        // Reflections.set(loader, "parent", ParentClassLoaderFinder.Helper.get());
        parentInstance.set(ParentClassLoaderFinder.Helper.get());
        server.afterApplicationCreated(new AssemblerAfterApplicationCreated(info, context, Collections.<BeanContext>emptyList()));
        {
            final ClassLoader afterLoader = SystemInstance.get().getComponent(ContainerSystem.class).getWebContext("test").getClassLoader();
            assertSame(loader, afterLoader);
            assertNotNull(afterLoader);
            assertNotNull(Reflections.get(afterLoader, "parent"));
        }
        server.undeploy(new AssemblerBeforeApplicationDestroyed(info, context));
    } finally {
        server.stop();
    }
}
Also used : CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) ContainerSystem(org.apache.openejb.spi.ContainerSystem) StandardRoot(org.apache.catalina.webresources.StandardRoot) AssemblerBeforeApplicationDestroyed(org.apache.openejb.assembler.classic.event.AssemblerBeforeApplicationDestroyed) Properties(java.util.Properties) BeanContext(org.apache.openejb.BeanContext) URLClassLoader(java.net.URLClassLoader) StandardContext(org.apache.catalina.core.StandardContext) AssemblerAfterApplicationCreated(org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) URLClassLoader(java.net.URLClassLoader) CxfRSService(org.apache.openejb.server.cxf.rs.CxfRSService) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1 Properties (java.util.Properties)1 StandardContext (org.apache.catalina.core.StandardContext)1 StandardRoot (org.apache.catalina.webresources.StandardRoot)1 BeanContext (org.apache.openejb.BeanContext)1 AssemblerAfterApplicationCreated (org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated)1 AssemblerBeforeApplicationDestroyed (org.apache.openejb.assembler.classic.event.AssemblerBeforeApplicationDestroyed)1 CoreContainerSystem (org.apache.openejb.core.CoreContainerSystem)1 CxfRSService (org.apache.openejb.server.cxf.rs.CxfRSService)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1 TomEEWebappClassLoader (org.apache.tomee.catalina.TomEEWebappClassLoader)1 Test (org.junit.Test)1