Search in sources :

Example 41 with AppContext

use of org.apache.openejb.AppContext in project tomee by apache.

the class ReloadingLoaderTest method initContext.

@Before
public void initContext() throws LifecycleException {
    final OpenEjbConfiguration configuration = new OpenEjbConfiguration();
    configuration.facilities = new FacilitiesInfo();
    final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
    SystemInstance.get().setComponent(OpenEjbConfiguration.class, configuration);
    SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
    SystemInstance.get().setComponent(WebAppEnricher.class, new WebAppEnricher() {

        @Override
        public URL[] enrichment(final ClassLoader webappClassLaoder) {
            return new URL[0];
        }
    });
    parentInstance = new AtomicReference<>(ParentClassLoaderFinder.Helper.get());
    loader = new TomEEWebappClassLoader(parentInstance.get()) {

        @Override
        public ClassLoader getInternalParent() {
            return parentInstance.get();
        }

        @Override
        protected void clearReferences() {
        // no-op: this test should be reworked to support it but in real life a loader is not stopped/started
        }
    };
    loader.init();
    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();
    info = new AppInfo();
    info.appId = "test";
    context = new AppContext(info.appId, SystemInstance.get(), loader, new IvmContext(), new IvmContext(), true);
    containerSystem.addAppContext(context);
    final WebContext webDeployment = new WebContext(context);
    webDeployment.setId(context.getId());
    webDeployment.setClassLoader(loader);
    containerSystem.addWebContext(webDeployment);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) StandardRoot(org.apache.catalina.webresources.StandardRoot) IvmJndiFactory(org.apache.openejb.core.ivm.naming.IvmJndiFactory) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) CoreContainerSystem(org.apache.openejb.core.CoreContainerSystem) WebAppEnricher(org.apache.openejb.classloader.WebAppEnricher) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) AppInfo(org.apache.openejb.assembler.classic.AppInfo) FacilitiesInfo(org.apache.openejb.assembler.classic.FacilitiesInfo) StandardContext(org.apache.catalina.core.StandardContext) TomEEWebappClassLoader(org.apache.tomee.catalina.TomEEWebappClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) Before(org.junit.Before)

Example 42 with AppContext

use of org.apache.openejb.AppContext in project tomee by apache.

the class WsService method start.

@Override
public void start() throws ServiceException {
    wsRegistry = SystemInstance.get().getComponent(WsRegistry.class);
    if (wsRegistry == null && SystemInstance.get().getComponent(HttpListenerRegistry.class) != null) {
        wsRegistry = new OpenEJBHttpWsRegistry();
    }
    if (portAddressRegistry == null) {
        portAddressRegistry = new PortAddressRegistryImpl();
        SystemInstance.get().setComponent(PortAddressRegistry.class, portAddressRegistry);
    }
    containerSystem = (CoreContainerSystem) SystemInstance.get().getComponent(ContainerSystem.class);
    portAddressRegistry = SystemInstance.get().getComponent(PortAddressRegistry.class);
    assembler = SystemInstance.get().getComponent(Assembler.class);
    SystemInstance.get().setComponent(WsService.class, this);
    if (assembler != null) {
        SystemInstance.get().addObserver(this);
        for (final AppInfo appInfo : assembler.getDeployedApplications()) {
            final AppContext appContext = containerSystem.getAppContext(appInfo.appId);
            deploy(new AssemblerAfterApplicationCreated(appInfo, appContext, null));
        }
    }
}
Also used : AppContext(org.apache.openejb.AppContext) PortAddressRegistryImpl(org.apache.openejb.core.webservices.PortAddressRegistryImpl) AssemblerAfterApplicationCreated(org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated) Assembler(org.apache.openejb.assembler.classic.Assembler) PortAddressRegistry(org.apache.openejb.core.webservices.PortAddressRegistry) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 43 with AppContext

use of org.apache.openejb.AppContext in project tomee by apache.

the class TomcatWebAppBuilder method getWebBeansContext.

private WebBeansContext getWebBeansContext(final ContextInfo contextInfo) {
    final AppContext appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId);
    if (appContext == null) {
        return null;
    }
    WebBeansContext webBeansContext = appContext.getWebBeansContext();
    if (webBeansContext == null) {
        return null;
    }
    for (final WebContext web : appContext.getWebContexts()) {
        final String stdName = removeFirstSlashAndWar(contextInfo.standardContext.getName());
        if (stdName == null) {
            continue;
        }
        final String name = removeFirstSlashAndWar(web.getContextRoot());
        if (stdName.equals(name)) {
            webBeansContext = web.getWebbeansContext();
            if (Contexts.getHostname(contextInfo.standardContext).equals(web.getHost())) {
                break;
            }
        // else loop hoping to find a better matching
        }
    }
    if (webBeansContext == null) {
        webBeansContext = appContext.getWebBeansContext();
    }
    return webBeansContext;
}
Also used : WebBeansContext(org.apache.webbeans.config.WebBeansContext) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext)

Example 44 with AppContext

use of org.apache.openejb.AppContext in project tomee by apache.

the class ServletContextHandler method invoke.

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    // ITE are handled by Proxys
    final Request request = OpenEJBSecurityListener.requests.get();
    if (request != null) {
        return method.invoke(request.getServletContext(), args);
    }
    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    final ServletContext c = contexts.get(contextClassLoader);
    if (c != null) {
        return method.invoke(c, args);
    }
    // can be a not container thread so clean it up
    OpenEJBSecurityListener.requests.remove();
    for (final AppContext a : SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts()) {
        for (final WebContext w : a.getWebContexts()) {
            if (w.getClassLoader() == contextClassLoader) {
                // not in CXF so == should be fine
                return method.invoke(w.getServletContext(), args);
            }
        }
    }
    throw new IllegalStateException("Didnt find a web context for " + contextClassLoader);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) Request(org.apache.catalina.connector.Request) ServletContext(javax.servlet.ServletContext)

Aggregations

AppContext (org.apache.openejb.AppContext)44 BeanContext (org.apache.openejb.BeanContext)23 WebContext (org.apache.openejb.core.WebContext)17 ContainerSystem (org.apache.openejb.spi.ContainerSystem)16 ModuleContext (org.apache.openejb.ModuleContext)11 Context (javax.naming.Context)9 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)9 Assembler (org.apache.openejb.assembler.classic.Assembler)9 ArrayList (java.util.ArrayList)8 WebBeansContext (org.apache.webbeans.config.WebBeansContext)8 InitialContext (javax.naming.InitialContext)7 NamingException (javax.naming.NamingException)7 ServletContext (javax.servlet.ServletContext)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Properties (java.util.Properties)6 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)6 OpenEJBException (org.apache.openejb.OpenEJBException)5 AppInfo (org.apache.openejb.assembler.classic.AppInfo)5 ThreadContext (org.apache.openejb.core.ThreadContext)5