Search in sources :

Example 1 with Jndi

use of org.apache.openejb.jee.oejb2.Jndi in project tomee by apache.

the class JndiNameTest method testOpenejbJar2.

public void testOpenejbJar2() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final EjbModule ejbModule = new EjbModule(new EjbJar(), null);
    ejbModule.getEjbJar().addEnterpriseBean(new StatelessBean(FooBean.class));
    final OpenejbJarType v2 = new OpenejbJarType();
    final SessionBeanType ejbDeployment = new SessionBeanType();
    ejbDeployment.setEjbName("FooBean");
    ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("thename", "Local"));
    ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("anothername", "Remote"));
    ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("loldstyle", "LocalHome"));
    ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("roldstyle", "RemoteHome"));
    v2.getEnterpriseBeans().add(ejbDeployment);
    ejbModule.getAltDDs().put("openejb-jar.xml", v2);
    assembler.createApplication(config.configureApplication(ejbModule));
    final InitialContext initialContext = new InitialContext();
    assertName(initialContext, Orange.class, "thename");
    assertName(initialContext, Red.class, "anothername");
    assertName(initialContext, LHYellow.class, "loldstyle");
    assertName(initialContext, RHGreen.class, "roldstyle");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) OpenejbJarType(org.apache.openejb.jee.oejb2.OpenejbJarType) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) SessionBeanType(org.apache.openejb.jee.oejb2.SessionBeanType) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 2 with Jndi

use of org.apache.openejb.jee.oejb2.Jndi 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<String>();
        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 3 with Jndi

use of org.apache.openejb.jee.oejb2.Jndi in project tomee by apache.

the class MappedNameBuilder method deploy.

public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        if (openejbJar == null) {
            return appModule;
        }
        final Map<String, EjbDeployment> ejbDeployments = openejbJar.getDeploymentsByEjbName();
        for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
            final EjbDeployment ejbDeployment = ejbDeployments.get(enterpriseBean.getEjbName());
            if (ejbDeployment == null) {
                continue;
            }
            final String mappedName = enterpriseBean.getMappedName();
            if (mappedName != null && mappedName.length() > 0) {
                ejbDeployment.getJndi().add(new Jndi(mappedName, "Remote"));
            }
        }
    }
    return appModule;
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Jndi(org.apache.openejb.jee.oejb3.Jndi)

Example 4 with Jndi

use of org.apache.openejb.jee.oejb2.Jndi in project tomee by apache.

the class MappedNameBuilderTest method testShouldCreateJndiEntryForBeanWithMappedName.

public void testShouldCreateJndiEntryForBeanWithMappedName() throws Exception {
    AppModule appModule = new AppModule(new FakeClassLoader(), "");
    final EjbJar ejbJar = new EjbJar();
    final OpenejbJar openejbJar = new OpenejbJar();
    final SessionBean sessionBean = new SessionBean("SessionBean", "org.superbiz.SessionBean", SessionType.STATELESS);
    sessionBean.setMappedName("MappedName");
    ejbJar.addEnterpriseBean(sessionBean);
    final EjbDeployment ejbDeployment = new EjbDeployment("containerId", "deploymentId", "SessionBean");
    openejbJar.addEjbDeployment(ejbDeployment);
    appModule.getEjbModules().add(new EjbModule(ejbJar, openejbJar));
    appModule = new MappedNameBuilder().deploy(appModule);
    final EjbDeployment retrievedDeployment = appModule.getEjbModules().get(0).getOpenejbJar().getDeploymentsByEjbName().get("SessionBean");
    final List<Jndi> jndiList = retrievedDeployment.getJndi();
    assertNotNull(jndiList);
    assertEquals(1, jndiList.size());
    assertEquals("MappedName", jndiList.get(0).getName());
    assertEquals("Remote", jndiList.get(0).getInterface());
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Jndi(org.apache.openejb.jee.oejb3.Jndi) SessionBean(org.apache.openejb.jee.SessionBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 5 with Jndi

use of org.apache.openejb.jee.oejb2.Jndi in project tomee by apache.

the class JndiNameTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    ejbModule.getEjbJar().addEnterpriseBean(new StatelessBean(FooBean.class));
    final EjbDeployment ejbDeployment = new EjbDeployment(null, "FooBean", "FooBean");
    ejbDeployment.getJndi().add(new Jndi("thename", "Local"));
    ejbDeployment.getJndi().add(new Jndi("anothername", "Remote"));
    ejbDeployment.getJndi().add(new Jndi("loldstyle", "LocalHome"));
    ejbDeployment.getJndi().add(new Jndi("roldstyle", "RemoteHome"));
    ejbModule.getOpenejbJar().addEjbDeployment(ejbDeployment);
    assembler.createApplication(config.configureApplication(ejbModule));
    final InitialContext initialContext = new InitialContext();
    assertName(initialContext, Orange.class, "thename");
    assertName(initialContext, Red.class, "anothername");
    assertName(initialContext, LHYellow.class, "loldstyle");
    assertName(initialContext, RHGreen.class, "roldstyle");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Jndi(org.apache.openejb.jee.oejb3.Jndi) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)5 Jndi (org.apache.openejb.jee.oejb3.Jndi)4 EjbJar (org.apache.openejb.jee.EjbJar)3 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)3 InitialContext (javax.naming.InitialContext)2 Assembler (org.apache.openejb.assembler.classic.Assembler)2 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)2 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)2 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)2 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)2 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)2 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)2 StatelessBean (org.apache.openejb.jee.StatelessBean)2 SessionBeanType (org.apache.openejb.jee.oejb2.SessionBeanType)2 TreeSet (java.util.TreeSet)1 JndiNameInfo (org.apache.openejb.assembler.classic.JndiNameInfo)1 EjbRef (org.apache.openejb.jee.EjbRef)1 SessionBean (org.apache.openejb.jee.SessionBean)1 EjbLocalRefType (org.apache.openejb.jee.oejb2.EjbLocalRefType)1 EjbRefType (org.apache.openejb.jee.oejb2.EjbRefType)1