Search in sources :

Example 16 with AppContext

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

the class Container method deploy.

public AppContext deploy(final String name, final File file, final boolean overrideName) throws OpenEJBException, IOException, NamingException {
    final AppContext context;
    final AppInfo appInfo;
    if (WebAppDeployer.Helper.isWebApp(file)) {
        String contextRoot = file.getName();
        if (overrideName) {
            contextRoot = name;
        }
        appInfo = SystemInstance.get().getComponent(WebAppDeployer.class).deploy(null, contextRoot, file);
        if (appInfo != null) {
            context = SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(appInfo.appId);
        } else {
            context = null;
        }
    } else {
        appInfo = configurationFactory.configureApplication(file);
        if (overrideName) {
            appInfo.appId = name;
            for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
                if (file.getName().equals(ejbJar.moduleName)) {
                    ejbJar.moduleName = name;
                    ejbJar.moduleId = name;
                }
                for (final EnterpriseBeanInfo ejb : ejbJar.enterpriseBeans) {
                    if (BeanContext.Comp.openejbCompName(file.getName()).equals(ejb.ejbName)) {
                        ejb.ejbName = BeanContext.Comp.openejbCompName(name);
                    }
                }
            }
            for (final WebAppInfo webApp : appInfo.webApps) {
                if (sameApplication(file, webApp)) {
                    webApp.moduleId = name;
                    webApp.contextRoot = lastPart(name, webApp.contextRoot);
                    if ("ROOT".equals(webApp.contextRoot)) {
                        webApp.contextRoot = "";
                    }
                }
            }
        }
        context = assembler.createApplication(appInfo);
    }
    moduleIds.put(name, null != appInfo ? appInfo.path : null);
    infos.put(name, appInfo);
    appContexts.put(name, context);
    return context;
}
Also used : EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppContext(org.apache.openejb.AppContext) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 17 with AppContext

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

the class RESTService method start.

@Override
public void start() throws ServiceException {
    SystemInstance.get().setComponent(RESTService.class, this);
    beforeStart();
    containerSystem = (CoreContainerSystem) SystemInstance.get().getComponent(ContainerSystem.class);
    assembler = SystemInstance.get().getComponent(Assembler.class);
    if (assembler != null) {
        SystemInstance.get().addObserver(this);
        for (final AppInfo appInfo : assembler.getDeployedApplications()) {
            final AppContext appContext = containerSystem.getAppContext(appInfo.appId);
            afterApplicationCreated(new AssemblerAfterApplicationCreated(appInfo, appContext, null));
        }
    }
}
Also used : AppContext(org.apache.openejb.AppContext) AssemblerAfterApplicationCreated(org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated) Assembler(org.apache.openejb.assembler.classic.Assembler) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 18 with AppContext

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

the class DeploymentIndexTest method setUp.

@Before
public void setUp() throws SystemException {
    method = Method.class.getMethods()[0];
    beanContext = new BeanContext("aDeploymentId", null, new ModuleContext("", null, "", new AppContext("", SystemInstance.get(), null, null, null, false), null, null), DeploymentIndexTest.class, null, null, null, null, null, null, null, null, null, null, false, false);
    deploymentIndex = new DeploymentIndex(new BeanContext[] { beanContext, beanContext });
}
Also used : BeanContext(org.apache.openejb.BeanContext) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext) Before(org.junit.Before)

Example 19 with AppContext

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

the class BasicClusterableRequestHandlerTest method setUp.

@Override
protected void setUp() throws Exception {
    requestHandler = new BasicClusterableRequestHandler();
    request = (ClusterableRequest) mock(ClusterableRequest.class);
    response = (ClusterableResponse) mock(ClusterableResponse.class);
    clusteredContainer = (ClusteredRPCContainer) mock(ClusteredRPCContainer.class);
    beanContext = new BeanContext("aDeploymentId", null, new ModuleContext("", null, "", new AppContext("", SystemInstance.get(), null, null, null, false), null, null), BasicClusterableRequestHandlerTest.class, null, null, null, null, null, null, null, null, null, null, false, false);
}
Also used : BeanContext(org.apache.openejb.BeanContext) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext)

Example 20 with AppContext

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

the class ContextualJndiReference method findPrefix.

private String findPrefix() {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    for (final AppContext appContext : containerSystem.getAppContexts()) {
        if (appContext.getClassLoader().equals(loader)) {
            return appContext.getId();
        }
        for (final WebContext web : appContext.getWebContexts()) {
            if (web.getClassLoader().equals(loader)) {
                return appContext.getId();
            }
        }
    }
    if (1 == containerSystem.getAppContexts().size()) {
        return containerSystem.getAppContexts().iterator().next().getId();
    }
    return null;
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext)

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