Search in sources :

Example 1 with StatelessBeanInfo

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

the class WsService method deployApp.

private void deployApp(final AppInfo appInfo, final Collection<BeanContext> ejbs) {
    final Collection<BeanContext> alreadyDeployed = deployedApplications.get(appInfo);
    final Map<String, WebAppInfo> webContextByEjb = new HashMap<>();
    for (final WebAppInfo webApp : appInfo.webApps) {
        for (final String ejb : webApp.ejbWebServices) {
            webContextByEjb.put(ejb, webApp);
        }
    }
    final Map<String, String> contextData = new HashMap<>();
    contextData.put("appId", appInfo.path);
    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
        final Map<String, PortInfo> ports = new TreeMap<>();
        for (final PortInfo port : ejbJar.portInfos) {
            ports.put(port.serviceLink, port);
        }
        URL moduleBaseUrl = null;
        if (ejbJar.path != null) {
            try {
                moduleBaseUrl = new File(ejbJar.path).toURI().toURL();
            } catch (final MalformedURLException e) {
                logger.error("Invalid ejb jar location " + ejbJar.path, e);
            }
        }
        StringTemplate deploymentIdTemplate = this.wsAddressTemplate;
        if (ejbJar.properties.containsKey(WS_ADDRESS_FORMAT)) {
            final String format = ejbJar.properties.getProperty(WS_ADDRESS_FORMAT);
            logger.info("Using " + WS_ADDRESS_FORMAT + " '" + format + "'");
            deploymentIdTemplate = new StringTemplate(format);
        }
        contextData.put("ejbJarId", ejbJar.moduleName);
        final String host = host(ejbJar, appInfo);
        for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
            if (bean instanceof StatelessBeanInfo || bean instanceof SingletonBeanInfo) {
                final BeanContext beanContext = containerSystem.getBeanContext(bean.ejbDeploymentId);
                if (beanContext == null || (ejbs != null && !ejbs.contains(beanContext))) {
                    continue;
                }
                final PortInfo portInfo = ports.get(bean.ejbName);
                if (portInfo == null || alreadyDeployed.contains(beanContext))
                    continue;
                final ClassLoader old = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(beanContext.getClassLoader());
                try {
                    final PortData port = WsBuilder.toPortData(portInfo, beanContext.getInjections(), moduleBaseUrl, beanContext.getClassLoader());
                    final HttpListener container = createEjbWsContainer(moduleBaseUrl, port, beanContext, new ServiceConfiguration(beanContext.getProperties(), appInfo.services));
                    // generate a location if one was not assigned
                    String location = port.getLocation();
                    if (location == null) {
                        location = autoAssignWsLocation(bean, port, contextData, deploymentIdTemplate);
                    }
                    if (!location.startsWith("/"))
                        location = "/" + location;
                    ejbLocations.put(bean.ejbDeploymentId, location);
                    final ClassLoader classLoader = beanContext.getClassLoader();
                    if (wsRegistry != null) {
                        String auth = authMethod;
                        String realm = realmName;
                        String transport = transportGuarantee;
                        if ("BASIC".equals(portInfo.authMethod) || "DIGEST".equals(portInfo.authMethod) || "CLIENT-CERT".equals(portInfo.authMethod)) {
                            auth = portInfo.authMethod;
                            realm = portInfo.realmName;
                            transport = portInfo.transportGuarantee;
                        }
                        final WebAppInfo webAppInfo = webContextByEjb.get(bean.ejbClass);
                        String context = webAppInfo != null ? webAppInfo.contextRoot : null;
                        String moduleId = webAppInfo != null ? webAppInfo.moduleId : null;
                        if (context == null && !OLD_WEBSERVICE_DEPLOYMENT) {
                            context = ejbJar.moduleName;
                        }
                        final List<String> addresses = wsRegistry.addWsContainer(container, classLoader, context, host, location, realm, transport, auth, moduleId);
                        alreadyDeployed.add(beanContext);
                        // one of the registered addresses to be the canonical address
                        final String address = HttpUtil.selectSingleAddress(addresses);
                        if (address != null) {
                            // register wsdl location
                            portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
                            setWsdl(container, address);
                            logger.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Ejb(id=" + portInfo.portId + ")");
                            ejbAddresses.put(bean.ejbDeploymentId, address);
                            addressesForApp(appInfo.appId).add(new EndpointInfo(address, port.getWsdlService(), beanContext.getBeanClass().getName()));
                        }
                    }
                } catch (final Throwable e) {
                    logger.error("Error deploying JAX-WS Web Service for EJB " + beanContext.getDeploymentID(), e);
                } finally {
                    Thread.currentThread().setContextClassLoader(old);
                }
            }
        }
    }
    if (ejbs == null || appInfo.webAppAlone) {
        for (final WebAppInfo webApp : appInfo.webApps) {
            afterApplicationCreated(appInfo, webApp);
        }
    }
// else called because of ear case where new ejbs are deployed in webapps
}
Also used : MalformedURLException(java.net.MalformedURLException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SingletonBeanInfo(org.apache.openejb.assembler.classic.SingletonBeanInfo) URL(java.net.URL) PortInfo(org.apache.openejb.assembler.classic.PortInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) PortData(org.apache.openejb.core.webservices.PortData) StringTemplate(org.apache.openejb.util.StringTemplate) HttpListener(org.apache.openejb.server.httpd.HttpListener) StatelessBeanInfo(org.apache.openejb.assembler.classic.StatelessBeanInfo) TreeMap(java.util.TreeMap) BeanContext(org.apache.openejb.BeanContext) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) File(java.io.File)

Example 2 with StatelessBeanInfo

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

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

the class EjbJarInfoBuilder method initSessionBean.

private EnterpriseBeanInfo initSessionBean(final SessionBean s, final EjbJarInfo ejbJar, final Map m) throws OpenEJBException {
    EnterpriseBeanInfo bean;
    if (s.getSessionType() == SessionType.STATEFUL) {
        bean = new StatefulBeanInfo();
        bean.passivable = s.getPassivationCapable() == null || s.getPassivationCapable();
        final StatefulBeanInfo stateful = (StatefulBeanInfo) bean;
        copyCallbacks(s.getPostActivate(), stateful.postActivate);
        copyCallbacks(s.getPrePassivate(), stateful.prePassivate);
        copyCallbacks(s.getAfterBegin(), stateful.afterBegin);
        copyCallbacks(s.getBeforeCompletion(), stateful.beforeCompletion);
        copyCallbacks(s.getAfterCompletion(), stateful.afterCompletion);
        for (final InitMethod initMethod : s.getInitMethod()) {
            final InitMethodInfo init = new InitMethodInfo();
            init.beanMethod = toInfo(initMethod.getBeanMethod());
            init.createMethod = toInfo(initMethod.getCreateMethod());
            stateful.initMethods.add(init);
        }
        for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
            final RemoveMethodInfo remove = new RemoveMethodInfo();
            remove.beanMethod = toInfo(removeMethod.getBeanMethod());
            remove.retainIfException = removeMethod.getRetainIfException();
            stateful.removeMethods.add(remove);
        }
        copyConcurrentMethods(s, ejbJar, m);
    } else if (s.getSessionType() == SessionType.MANAGED) {
        bean = new ManagedBeanInfo();
        final ManagedBeanInfo managed = (ManagedBeanInfo) bean;
        // this way we support managed beans in ejb-jar.xml (not in the spec but can be useful)
        managed.hidden = !(s instanceof ManagedBean) || ((ManagedBean) s).isHidden();
        copyCallbacks(s.getPostActivate(), managed.postActivate);
        copyCallbacks(s.getPrePassivate(), managed.prePassivate);
        for (final RemoveMethod removeMethod : s.getRemoveMethod()) {
            final RemoveMethodInfo remove = new RemoveMethodInfo();
            remove.beanMethod = toInfo(removeMethod.getBeanMethod());
            remove.retainIfException = removeMethod.getRetainIfException();
            managed.removeMethods.add(remove);
        }
    } else if (s.getSessionType() == SessionType.SINGLETON) {
        bean = new SingletonBeanInfo();
        final ConcurrencyManagementType type = s.getConcurrencyManagementType();
        bean.concurrencyType = type != null ? type.toString() : ConcurrencyManagementType.CONTAINER.toString();
        bean.loadOnStartup = s.getInitOnStartup();
        copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
        copySchedules(s.getTimer(), bean.methodScheduleInfos);
        // See JndiEncInfoBuilder.buildDependsOnRefs for processing of DependsOn
        // bean.dependsOn.addAll(s.getDependsOn());
        copyConcurrentMethods(s, ejbJar, m);
    } else {
        bean = new StatelessBeanInfo();
        copySchedules(s.getTimer(), bean.methodScheduleInfos);
    }
    if (s.getSessionType() != SessionType.STATEFUL) {
        copyCallbacks(s.getAroundTimeout(), bean.aroundTimeout);
    }
    bean.localbean = s.getLocalBean() != null;
    bean.timeoutMethod = toInfo(s.getTimeoutMethod());
    copyCallbacks(s.getAroundInvoke(), bean.aroundInvoke);
    copyCallbacks(s.getPostConstruct(), bean.postConstruct);
    copyCallbacks(s.getPreDestroy(), bean.preDestroy);
    copyAsynchronous(s.getAsyncMethod(), bean.asynchronous);
    bean.asynchronousClasses.addAll(s.getAsynchronousClasses());
    final EjbDeployment d = (EjbDeployment) m.get(s.getEjbName());
    if (d == null) {
        throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + s.getEjbName() + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();
    final Icon icon = s.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = s.getDescription();
    bean.displayName = s.getDisplayName();
    bean.ejbClass = s.getEjbClass();
    bean.ejbName = s.getEjbName();
    bean.home = s.getHome();
    bean.remote = s.getRemote();
    bean.localHome = s.getLocalHome();
    bean.local = s.getLocal();
    bean.proxy = s.getProxy();
    bean.parents.addAll(s.getParents());
    bean.businessLocal.addAll(s.getBusinessLocal());
    bean.businessRemote.addAll(s.getBusinessRemote());
    final TransactionType txType = s.getTransactionType();
    bean.transactionType = txType != null ? txType.toString() : TransactionType.CONTAINER.toString();
    bean.serviceEndpoint = s.getServiceEndpoint();
    bean.properties.putAll(d.getProperties());
    bean.statefulTimeout = toInfo(s.getStatefulTimeout());
    bean.restService = s.isRestService() && !(s instanceof StatefulBean);
    return bean;
}
Also used : InitMethod(org.apache.openejb.jee.InitMethod) InitMethodInfo(org.apache.openejb.assembler.classic.InitMethodInfo) OpenEJBException(org.apache.openejb.OpenEJBException) TransactionType(org.apache.openejb.jee.TransactionType) ConcurrencyManagementType(org.apache.openejb.jee.ConcurrencyManagementType) StatefulBean(org.apache.openejb.jee.StatefulBean) RemoveMethodInfo(org.apache.openejb.assembler.classic.RemoveMethodInfo) StatelessBeanInfo(org.apache.openejb.assembler.classic.StatelessBeanInfo) ManagedBeanInfo(org.apache.openejb.assembler.classic.ManagedBeanInfo) SingletonBeanInfo(org.apache.openejb.assembler.classic.SingletonBeanInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) StatefulBeanInfo(org.apache.openejb.assembler.classic.StatefulBeanInfo) RemoveMethod(org.apache.openejb.jee.RemoveMethod) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Icon(org.apache.openejb.jee.Icon) ManagedBean(org.apache.openejb.jee.ManagedBean)

Aggregations

EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)3 SingletonBeanInfo (org.apache.openejb.assembler.classic.SingletonBeanInfo)3 StatelessBeanInfo (org.apache.openejb.assembler.classic.StatelessBeanInfo)3 TreeMap (java.util.TreeMap)2 BeanContext (org.apache.openejb.BeanContext)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 PortInfo (org.apache.openejb.assembler.classic.PortInfo)2 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 AppInfo (org.apache.openejb.assembler.classic.AppInfo)1 InitMethodInfo (org.apache.openejb.assembler.classic.InitMethodInfo)1 ManagedBeanInfo (org.apache.openejb.assembler.classic.ManagedBeanInfo)1 RemoveMethodInfo (org.apache.openejb.assembler.classic.RemoveMethodInfo)1 ServletInfo (org.apache.openejb.assembler.classic.ServletInfo)1 StatefulBeanInfo (org.apache.openejb.assembler.classic.StatefulBeanInfo)1