Search in sources :

Example 46 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo 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 47 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class HttpRequestImpl method getSession.

public HttpSession getSession(boolean create) {
    if (session == null && create) {
        // default is infinite *here* only
        long timeout = -1;
        if (contextPath != null) {
            // TODO: webapp should be contextual, would need to normalize jaxws, jaxrs, servlet, jsf...before but would be better
            final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
            if (assembler != null) {
                for (final AppInfo info : assembler.getDeployedApplications()) {
                    for (final WebAppInfo webApp : info.webApps) {
                        if (webApp.contextRoot.replace("/", "").equals(contextPath.replace("/", ""))) {
                            timeout = webApp.sessionTimeout;
                        }
                    }
                }
            }
        }
        final HttpSessionImpl impl = new HttpSessionImpl(contextPath, timeout) {

            @Override
            public void invalidate() {
                super.invalidate();
                HttpRequestImpl.this.session = null;
            }
        };
        session = impl;
        if (begin != null) {
            begin.sessionCreated(new HttpSessionEvent(session));
            session = new SessionInvalidateListener(session, begin);
        }
        // can call req.getSession() so do it after affectation + do it after cdi init
        impl.callListeners();
        final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
        final SessionManager.SessionWrapper previous = sessionManager.newSession(begin, end, session, application);
        if (previous != null) {
            session = previous.session;
        }
    }
    return session;
}
Also used : WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) SessionManager(org.apache.openejb.server.httpd.session.SessionManager) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) Assembler(org.apache.openejb.assembler.classic.Assembler) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 48 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class WsService method undeploy.

public void undeploy(@Observes final AssemblerBeforeApplicationDestroyed event) {
    final AppInfo appInfo = event.getApp();
    if (deployedApplications.remove(appInfo) != null) {
        for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
            final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
            for (final PortInfo port : ejbJar.portInfos) {
                ports.put(port.serviceLink, port);
            }
            for (final EnterpriseBeanInfo enterpriseBean : ejbJar.enterpriseBeans) {
                if (enterpriseBean instanceof StatelessBeanInfo || enterpriseBean instanceof SingletonBeanInfo) {
                    final PortInfo portInfo = ports.get(enterpriseBean.ejbName);
                    if (portInfo == null) {
                        continue;
                    }
                    final BeanContext beanContext = containerSystem.getBeanContext(enterpriseBean.ejbDeploymentId);
                    if (beanContext == null) {
                        continue;
                    }
                    // remove wsdl addresses from global registry
                    final String address = ejbAddresses.remove(enterpriseBean.ejbDeploymentId);
                    addressesForApp(appInfo.appId).remove(new EndpointInfo(address, portInfo.wsdlPort, beanContext.getBeanClass().getName()));
                    if (address != null) {
                        portAddressRegistry.removePort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.seiInterfaceName);
                    }
                    // remove container from web server
                    final String location = ejbLocations.get(enterpriseBean.ejbDeploymentId);
                    if (this.wsRegistry != null && location != null) {
                        this.wsRegistry.removeWsContainer(location, ejbJar.moduleId);
                    }
                    // destroy webservice container
                    destroyEjbWsContainer(enterpriseBean.ejbDeploymentId);
                    ejbLocations.remove(enterpriseBean.ejbDeploymentId);
                }
            }
        }
        for (final WebAppInfo webApp : appInfo.webApps) {
            deployedWebApps.remove(webApp);
            final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
            for (final PortInfo port : webApp.portInfos) {
                ports.put(port.serviceLink, port);
            }
            for (final ServletInfo servlet : webApp.servlets) {
                if (servlet.servletClass == null) {
                    continue;
                }
                PortInfo portInfo = ports.remove(servlet.servletClass);
                if (portInfo == null) {
                    portInfo = ports.remove(servlet.servletName);
                    if (portInfo == null) {
                        continue;
                    }
                }
                // remove wsdl addresses from global registry
                final String address = servletAddresses.remove(webApp.moduleId + "." + servlet.servletName);
                if (address != null) {
                    portAddressRegistry.removePort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.seiInterfaceName);
                }
                // clear servlet's reference to the webservice container
                if (this.wsRegistry != null) {
                    try {
                        this.wsRegistry.clearWsContainer(webApp.contextRoot, host(webApp), servlet, webApp.moduleId);
                    } catch (final IllegalArgumentException ignored) {
                    // no-op
                    }
                }
                // destroy webservice container
                destroyPojoWsContainer(portInfo.serviceLink);
            }
            addressesByApplication.remove(webApp.moduleId);
        }
        addressesByApplication.remove(appInfo.appId);
    }
}
Also used : StatelessBeanInfo(org.apache.openejb.assembler.classic.StatelessBeanInfo) SingletonBeanInfo(org.apache.openejb.assembler.classic.SingletonBeanInfo) TreeMap(java.util.TreeMap) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) PortInfo(org.apache.openejb.assembler.classic.PortInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) BeanContext(org.apache.openejb.BeanContext) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 49 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class RESTService method undeploy.

public void undeploy(@Observes final AssemblerBeforeApplicationDestroyed event) {
    final AppInfo app = event.getApp();
    final boolean removed = deployedApplications.remove(app);
    if (removed) {
        for (final WebAppInfo webApp : app.webApps) {
            final List<DeployedService> toRemove = new ArrayList<>();
            for (final DeployedService service : services) {
                if (service.isInWebApp(app.appId, webApp)) {
                    undeployRestObject(app.appId, service.address);
                    toRemove.add(service);
                }
            }
            services.removeAll(toRemove);
            deployedWebApps.remove(webApp);
        }
    }
}
Also used : WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ArrayList(java.util.ArrayList) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 50 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo 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)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)106 File (java.io.File)50 Assembler (org.apache.openejb.assembler.classic.Assembler)46 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 OpenEJBException (org.apache.openejb.OpenEJBException)15 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)13 EjbJar (org.apache.openejb.jee.EjbJar)13 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13 Properties (java.util.Properties)10 EjbModule (org.apache.openejb.config.EjbModule)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8 URL (java.net.URL)8 InitialContext (javax.naming.InitialContext)8