Search in sources :

Example 21 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class BeanProperties method deploy.

@Override
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    final Properties base = new Properties();
    base.putAll(SystemInstance.get().getProperties());
    base.putAll(appModule.getProperties());
    for (final EjbModule module : appModule.getEjbModules()) {
        final Properties overrides = new SuperProperties().caseInsensitive(true);
        overrides.putAll(base);
        overrides.putAll(module.getProperties());
        if (module.getOpenejbJar() == null) {
            module.setOpenejbJar(new OpenejbJar());
        }
        final OpenejbJar openejbJar = module.getOpenejbJar();
        final Map<String, EjbDeployment> deploymentMap = openejbJar.getDeploymentsByEjbName();
        for (final EnterpriseBean bean : module.getEjbJar().getEnterpriseBeans()) {
            final SuperProperties properties = new SuperProperties().caseInsensitive(true);
            properties.putAll(globalProperties);
            final String additionalKey = bean.getEjbName();
            if (additionalProperties.containsKey(additionalKey)) {
                for (final Map.Entry<Object, Object> entry : additionalProperties.get(additionalKey).entrySet()) {
                    properties.put(entry.getKey().toString(), entry.getValue().toString());
                }
            }
            final EjbDeployment deployment = deploymentMap.get(bean.getEjbName());
            if (deployment != null) {
                properties.putAll(deployment.getProperties());
                deployment.getProperties().clear();
            }
            final String id = bean.getEjbName() + ".";
            for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
                final String key = entry.getKey().toString();
                if (key.startsWith(id)) {
                    final String property = key.substring(id.length());
                    if (properties.containsKey(property)) {
                        log.debug("Overriding ejb " + bean.getEjbName() + " property " + property + "=" + entry.getValue());
                    } else {
                        log.debug("Adding ejb " + bean.getEjbName() + " property " + property + "=" + entry.getValue());
                    }
                    properties.put(property, entry.getValue());
                }
            }
            if (properties.size() > 0) {
                if (deployment == null) {
                    final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
                    ejbDeployment.getProperties().putAll(properties);
                } else {
                    deployment.getProperties().putAll(properties);
                }
            }
        }
    }
    // cleanup
    additionalProperties.clear();
    globalProperties.clear();
    return appModule;
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) Map(java.util.Map) HashMap(java.util.HashMap) SuperProperties(org.apache.openejb.util.SuperProperties)

Example 22 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class DebuggableVmHackery method deploy.

public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
        ejbJar.setRelationships(null);
        final List<String> removed = new ArrayList<>();
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            final String ejbName = bean.getEjbName();
            final EjbDeployment ejbDeployment = deployments.get(ejbName);
            pruneRefs(bean, ejbDeployment);
            // }
            if (!(bean instanceof MessageDrivenBean) && !(bean instanceof EntityBean)) {
                continue;
            }
            ejbJar.removeEnterpriseBean(ejbName);
            openejbJar.removeEjbDeployment(ejbDeployment);
            removed.add(ejbName);
            final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
            if (assemblyDescriptor != null) {
                for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
                    for (final Method method : copy(permission.getMethod())) {
                        if (method.getEjbName().equals(ejbName)) {
                            permission.getMethod().remove(method);
                        }
                    }
                    if (permission.getMethod().size() == 0) {
                        assemblyDescriptor.getMethodPermission().remove(permission);
                    }
                }
                for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
                    for (final Method method : copy(transaction.getMethod())) {
                        if (method.getEjbName().equals(ejbName)) {
                            transaction.getMethod().remove(method);
                        }
                    }
                    if (transaction.getMethod().size() == 0) {
                        assemblyDescriptor.getContainerTransaction().remove(transaction);
                    }
                }
                for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
                    if (binding.getEjbName().equals(ejbName)) {
                        assemblyDescriptor.getInterceptorBinding().remove(binding);
                    }
                }
            }
        }
        // Drop any ejb ref to with an ejb-link to a removed ejb
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            bean.getEjbLocalRefMap().keySet().removeAll(removed);
            bean.getEjbRefMap().keySet().removeAll(removed);
        }
        for (final Interceptor interceptor : ejbJar.getInterceptors()) {
            pruneRefs(interceptor, new EjbDeployment());
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) ArrayList(java.util.ArrayList) Method(org.apache.openejb.jee.Method) MethodPermission(org.apache.openejb.jee.MethodPermission) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) EntityBean(org.apache.openejb.jee.EntityBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 23 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class DeploymentLoader method addBeansXmls.

private void addBeansXmls(final AppModule appModule) {
    final List<URL> urls = appModule.getAdditionalLibraries();
    final URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
    final ArrayList<URL> xmls;
    try {
        xmls = Collections.list(loader.getResources("META-INF/beans.xml"));
    } catch (final IOException e) {
        return;
    }
    final CompositeBeans complete = new CompositeBeans();
    for (final URL url : xmls) {
        if (url == null) {
            continue;
        }
        mergeBeansXml(complete, url);
    }
    if (complete.getDiscoveryByUrl().isEmpty()) {
        return;
    }
    complete.removeDuplicates();
    ensureContainerUrls();
    final List<URL> scannableUrls = new ArrayList<>(this.containerUrls);
    SystemInstance.get().fireEvent(new EnhanceScannableUrlsEvent(scannableUrls));
    appModule.getScannableContainerUrls().addAll(scannableUrls);
    IAnnotationFinder finder;
    try {
        finder = FinderFactory.createFinder(appModule);
    } catch (final Exception e) {
        finder = new FinderFactory.ModuleLimitedFinder(new FinderFactory.OpenEJBAnnotationFinder(new WebappAggregatedArchive(appModule.getClassLoader(), appModule.getAltDDs(), xmls)));
    }
    appModule.setEarLibFinder(finder);
    final EjbModule ejbModule = new EjbModule(appModule.getClassLoader(), EAR_SCOPED_CDI_BEANS + appModule.getModuleId(), new EjbJar(), new OpenejbJar());
    ejbModule.setBeans(complete);
    ejbModule.setFinder(finder);
    ejbModule.setEjbJar(new EmptyEjbJar());
    appModule.getEjbModules().add(ejbModule);
}
Also used : CompositeBeans(org.apache.openejb.cdi.CompositeBeans) EnhanceScannableUrlsEvent(org.apache.openejb.config.event.EnhanceScannableUrlsEvent) IAnnotationFinder(org.apache.xbean.finder.IAnnotationFinder) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) OpenEJBException(org.apache.openejb.OpenEJBException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) URLClassLoader(java.net.URLClassLoader) EjbJar(org.apache.openejb.jee.EjbJar)

Example 24 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class OpenEjb2Conversion method convertEjbRefs.

public final void convertEjbRefs(final EjbJar ejbJar, final OpenejbJar openejbJar, final OpenejbJarType openejbJarType) {
    openejbJar.getProperties().putAll(openejbJarType.getProperties());
    final Map<String, EnterpriseBean> ejbs = ejbJar.getEnterpriseBeansByEjbName();
    final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
    for (final org.apache.openejb.jee.oejb2.EnterpriseBean enterpriseBean : openejbJarType.getEnterpriseBeans()) {
        final EnterpriseBean ejb = ejbs.get(enterpriseBean.getEjbName());
        if (ejb == null) {
            // todo warn no such ejb in the ejb-jar.xml
            continue;
        }
        final Map<String, EjbRef> ejbRefs = ejb.getEjbRefMap();
        final EjbDeployment deployment = deployments.get(enterpriseBean.getEjbName());
        if (deployment == null) {
            // todo warn no such ejb in the ejb-jar.xml
            continue;
        }
        // Add WS Security
        if (enterpriseBean instanceof SessionBeanType) {
            final SessionBeanType sessionBean = (SessionBeanType) enterpriseBean;
            final WebServiceSecurityType webServiceSecurityType = sessionBean.getWebServiceSecurity();
            if (webServiceSecurityType != null) {
                if (webServiceSecurityType.getRealmName() != null) {
                    deployment.addProperty("webservice.security.realm", webServiceSecurityType.getRealmName());
                }
                if (webServiceSecurityType.getSecurityRealmName() != null) {
                    deployment.addProperty("webservice.security.securityRealm", webServiceSecurityType.getSecurityRealmName());
                }
                if (webServiceSecurityType.getTransportGuarantee() != null) {
                    deployment.addProperty("webservice.security.transportGarantee", webServiceSecurityType.getTransportGuarantee().value());
                } else {
                    deployment.addProperty("webservice.security.transportGarantee", "NONE");
                }
                if (webServiceSecurityType.getAuthMethod() != null) {
                    deployment.addProperty("webservice.security.authMethod", webServiceSecurityType.getAuthMethod().value());
                } else {
                    deployment.addProperty("webservice.security.authMethod", "NONE");
                }
                deployment.getProperties().putAll(webServiceSecurityType.getProperties());
            }
            if (sessionBean.getWebServiceAddress() != null) {
                deployment.getProperties().put("openejb.webservice.deployment.address", sessionBean.getWebServiceAddress());
            }
        }
        deployment.getProperties().putAll(enterpriseBean.getProperties());
        for (final String name : enterpriseBean.getLocalJndiName()) {
            deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(name, "LocalHome"));
        }
        for (final String name : enterpriseBean.getJndiName()) {
            deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(name, "RemoteHome"));
        }
        for (final Jndi jndi : enterpriseBean.getJndi()) {
            deployment.getJndi().add(new org.apache.openejb.jee.oejb3.Jndi(jndi.getName(), jndi.getInterface()));
        }
        final Set<String> ejbLinks = new TreeSet<>();
        for (final EjbLink ejbLink : deployment.getEjbLink()) {
            ejbLinks.add(ejbLink.getEjbRefName());
        }
        for (final EjbRefType refType : enterpriseBean.getEjbRef()) {
            final String refName = refType.getRefName();
            if (ejbLinks.contains(refName)) {
                // don't overwrite refs that have been already set
                continue;
            }
            final String nsCorbaloc = refType.getNsCorbaloc();
            if (nsCorbaloc != null) {
                final EjbRef ref = ejbRefs.get(refName);
                if (ref != null) {
                    ref.setMappedName("jndi:" + nsCorbaloc);
                }
            } else if (refType.getEjbLink() != null) {
                final EjbRef ref = ejbRefs.get(refName);
                if (ref != null) {
                    ref.setEjbLink(refType.getEjbLink());
                }
            } else {
                final PatternType pattern = refType.getPattern();
                addEjbLink(deployment, refName, pattern);
            }
        }
        for (final EjbLocalRefType refType : enterpriseBean.getEjbLocalRef()) {
            final String refName = refType.getRefName();
            if (ejbLinks.contains(refName)) {
                // don't overwrite refs that have been already set
                continue;
            }
            if (refType.getEjbLink() != null) {
                final EjbRef ref = ejbRefs.get(refName);
                if (ref != null) {
                    ref.setEjbLink(refType.getEjbLink());
                }
            } else {
                final PatternType pattern = refType.getPattern();
                addEjbLink(deployment, refName, pattern);
            }
        }
    }
}
Also used : PatternType(org.apache.openejb.jee.oejb2.PatternType) WebServiceSecurityType(org.apache.openejb.jee.oejb2.WebServiceSecurityType) EjbRefType(org.apache.openejb.jee.oejb2.EjbRefType) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbLocalRefType(org.apache.openejb.jee.oejb2.EjbLocalRefType) Jndi(org.apache.openejb.jee.oejb2.Jndi) EjbLink(org.apache.openejb.jee.oejb3.EjbLink) TreeSet(java.util.TreeSet) EjbRef(org.apache.openejb.jee.EjbRef) SessionBeanType(org.apache.openejb.jee.oejb2.SessionBeanType) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment)

Example 25 with OpenejbJar

use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.

the class DeploymentContextPropertiesTest method testBeanContextProperties.

public void testBeanContextProperties() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        // Setup the descriptor information
        final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
        deployment.getProperties().put("color", "orange");
        assembler.createApplication(config.configureApplication(ejbModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final Properties properties = beanContext.getProperties();
    assertProperty(properties, "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)65 EjbJar (org.apache.openejb.jee.EjbJar)52 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)37 EjbModule (org.apache.openejb.config.EjbModule)30 Properties (java.util.Properties)20 StatelessBean (org.apache.openejb.jee.StatelessBean)19 Assembler (org.apache.openejb.assembler.classic.Assembler)18 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)16 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)12 ContainerSystem (org.apache.openejb.spi.ContainerSystem)12 SingletonBean (org.apache.openejb.jee.SingletonBean)11 Module (org.apache.openejb.testing.Module)11 AppModule (org.apache.openejb.config.AppModule)8 PojoDeployment (org.apache.openejb.jee.oejb3.PojoDeployment)8 InitialContext (javax.naming.InitialContext)7 OpenEJBException (org.apache.openejb.OpenEJBException)7 Resources (org.apache.openejb.config.sys.Resources)7 Service (org.apache.openejb.config.sys.Service)7 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)7 File (java.io.File)6