Search in sources :

Example 1 with ResourceReferenceInfo

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

the class AutoConfigResourceRefsTest method testCaseInsensitive.

public void testCaseInsensitive() 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));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("DeFAultDataSource", "DataSource", null), ResourceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("YeLLowDataSource", "DataSource", null), ResourceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("PurpLEDataSource", "DataSource", null), ResourceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    final Map<String, ResourceReferenceInfo> refs = new HashMap<>();
    for (final ResourceReferenceInfo ref : beanInfo.jndiEnc.resourceRefs) {
        refs.put(ref.referenceName.replaceAll(".*/", ""), ref);
    }
    ResourceReferenceInfo info;
    info = refs.get("yellowDataSource");
    assertNotNull(info);
    assertEquals("YeLLowDataSource", info.resourceID);
    info = refs.get("orangeDataSource");
    assertNotNull(info);
    assertEquals("DeFAultDataSource", info.resourceID);
    info = refs.get("purpleDataSource");
    assertNotNull(info);
    assertEquals("PurpLEDataSource", info.resourceID);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) HashMap(java.util.HashMap) Resource(javax.annotation.Resource) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 2 with ResourceReferenceInfo

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

the class AutoConfigResourceRefsTest 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));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("defaultDataSource", "DataSource", null), ResourceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("yellowDataSource", "DataSource", null), ResourceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("PurpleDataSource", "DataSource", null), ResourceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    final Map<String, ResourceReferenceInfo> refs = new HashMap<>();
    for (final ResourceReferenceInfo ref : beanInfo.jndiEnc.resourceRefs) {
        refs.put(ref.referenceName.replaceAll(".*/", ""), ref);
    }
    ResourceReferenceInfo info;
    info = refs.get("yellowDataSource");
    assertNotNull(info);
    assertEquals("yellowDataSource", info.resourceID);
    info = refs.get("orangeDataSource");
    assertNotNull(info);
    assertEquals("defaultDataSource", info.resourceID);
    info = refs.get("purpleDataSource");
    assertNotNull(info);
    assertEquals("PurpleDataSource", info.resourceID);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) HashMap(java.util.HashMap) Resource(javax.annotation.Resource) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 3 with ResourceReferenceInfo

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

the class TomcatJndiBuilder method mergeJndi.

public void mergeJndi() throws OpenEJBException {
    final NamingResourcesImpl naming = standardContext.getNamingResources();
    final URI moduleUri = URLs.uri(webAppInfo.moduleId);
    for (final EnvEntryInfo ref : webAppInfo.jndiEnc.envEntries) {
        mergeRef(naming, ref);
    }
    for (final EjbReferenceInfo ref : webAppInfo.jndiEnc.ejbReferences) {
        mergeRef(naming, ref);
    }
    for (final EjbLocalReferenceInfo ref : webAppInfo.jndiEnc.ejbLocalReferences) {
        mergeRef(naming, ref);
    }
    for (final PersistenceContextReferenceInfo ref : webAppInfo.jndiEnc.persistenceContextRefs) {
        mergeRef(naming, ref, moduleUri);
    }
    for (final PersistenceUnitReferenceInfo ref : webAppInfo.jndiEnc.persistenceUnitRefs) {
        mergeRef(naming, ref, moduleUri);
    }
    for (final ResourceReferenceInfo ref : webAppInfo.jndiEnc.resourceRefs) {
        mergeRef(naming, ref);
    }
    for (final ResourceEnvReferenceInfo ref : webAppInfo.jndiEnc.resourceEnvRefs) {
        mergeRef(naming, ref);
    }
    for (final ServiceReferenceInfo ref : webAppInfo.jndiEnc.serviceRefs) {
        mergeRef(naming, ref);
    }
    final ContextTransaction contextTransaction = new ContextTransaction();
    contextTransaction.setProperty(Constants.FACTORY, UserTransactionFactory.class.getName());
    naming.setTransaction(contextTransaction);
}
Also used : ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) EjbReferenceInfo(org.apache.openejb.assembler.classic.EjbReferenceInfo) UserTransactionFactory(org.apache.tomee.common.UserTransactionFactory) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) EnvEntryInfo(org.apache.openejb.assembler.classic.EnvEntryInfo) EjbLocalReferenceInfo(org.apache.openejb.assembler.classic.EjbLocalReferenceInfo) ResourceEnvReferenceInfo(org.apache.openejb.assembler.classic.ResourceEnvReferenceInfo) ContextTransaction(org.apache.tomcat.util.descriptor.web.ContextTransaction) URI(java.net.URI) ServiceReferenceInfo(org.apache.openejb.assembler.classic.ServiceReferenceInfo) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo)

Example 4 with ResourceReferenceInfo

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

the class JndiEncInfoBuilder method buildResourceRefInfos.

private void buildResourceRefInfos(final JndiConsumer item, final JndiEncInfo moduleJndiEnc, final JndiEncInfo compJndiEnc) {
    for (final ResourceRef res : item.getResourceRef()) {
        final ResourceReferenceInfo info;
        if (res instanceof ContextRef) {
            info = new ContextReferenceInfo();
        } else {
            info = new ResourceReferenceInfo();
        }
        if (res.getResAuth() != null) {
            info.referenceAuth = res.getResAuth().toString();
        } else {
            info.referenceAuth = ResAuth.CONTAINER.toString();
        }
        info.referenceName = res.getResRefName();
        info.referenceType = res.getResType();
        info.resourceID = res.getMappedName();
        info.location = buildLocationInfo(res);
        info.targets.addAll(buildInjectionInfos(res));
        insert(info, appInfo.globalJndiEnc.resourceRefs, appInfo.appJndiEnc.resourceRefs, moduleJndiEnc.resourceRefs, compJndiEnc.resourceRefs);
    }
}
Also used : ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) ContextReferenceInfo(org.apache.openejb.assembler.classic.ContextReferenceInfo) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) PersistenceContextRef(org.apache.openejb.jee.PersistenceContextRef) ResourceRef(org.apache.openejb.jee.ResourceRef)

Example 5 with ResourceReferenceInfo

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

the class XmlOverridesTest method test.

public void test() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(AnnotatedBean.class));
    bean.getEjbLocalRef().add(new EjbLocalRef(name("annotatedLocal"), "BarBean"));
    bean.getEnvEntry().add(new EnvEntry(name("striing"), "java.lang.Integer", "2"));
    bean.getEnvEntry().add(new EnvEntry(name("doouble"), "java.lang.String", "two"));
    bean.getEnvEntry().add(new EnvEntry(name("loong"), "java.lang.String", "three"));
    bean.getEnvEntry().add(new EnvEntry(name("flooat"), "java.lang.String", "four"));
    bean.getEnvEntry().add(new EnvEntry(name("inteeger"), "java.lang.String", "five"));
    bean.getEnvEntry().add(new EnvEntry(name("shoort"), "java.lang.String", "six"));
    bean.getEnvEntry().add(new EnvEntry(name("booolean"), "java.lang.String", "seven"));
    bean.getEnvEntry().add(new EnvEntry(name("byyte"), "java.lang.String", "eight"));
    bean.getEnvEntry().add(new EnvEntry(name("chaaracter"), "java.lang.String", "nine"));
    final EnvEntry lookupEntry = new EnvEntry(name("lookup"), "java.lang.String", null);
    lookupEntry.setLookupName("java:app/AppName");
    bean.getEnvEntry().add(lookupEntry);
    bean.getResourceRef().add(new ResourceRef(name("daataSource"), DataSource.class.getName(), ResAuth.CONTAINER, ResSharingScope.SHAREABLE));
    bean.getPersistenceUnitRef().add(new PersistenceUnitRef(name("emf"), "yellow"));
    bean.getPersistenceContextRef().add(new PersistenceContextRef(name("em"), "yellow", PersistenceContextType.TRANSACTION, new ArrayList(Arrays.asList(new Property("zzzz", "AAAA")))));
    final org.apache.openejb.jee.jpa.unit.PersistenceUnit persistenceUnit = new org.apache.openejb.jee.jpa.unit.PersistenceUnit("yellow");
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "app");
    app.getEjbModules().add(new EjbModule(ejbJar));
    app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
    final AppInfo appInfo = config.configureApplication(app);
    final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    final JndiEncInfo enc = beanInfo.jndiEnc;
    assertEquals("Enc.ejbLocalReferences.size()", 1, enc.ejbLocalReferences.size());
    assertEquals("Enc.ejbLocalReferences.get(0).link", "BarBean", enc.ejbLocalReferences.get(0).link);
    assertEquals("Enc.ejbReferences.size()", 0, enc.ejbReferences.size());
    // 10 + ComponentName
    assertEquals("Enc.envEntries.size()", 11, enc.envEntries.size());
    final Map<String, EnvEntryInfo> entries = map(enc.envEntries);
    assertEnvEntry(entries, name("striing"), "java.lang.Integer", "2");
    assertEnvEntry(entries, name("doouble"), "java.lang.String", "two");
    assertEnvEntry(entries, name("loong"), "java.lang.String", "three");
    assertEnvEntry(entries, name("flooat"), "java.lang.String", "four");
    assertEnvEntry(entries, name("inteeger"), "java.lang.String", "five");
    assertEnvEntry(entries, name("shoort"), "java.lang.String", "six");
    assertEnvEntry(entries, name("booolean"), "java.lang.String", "seven");
    assertEnvEntry(entries, name("byyte"), "java.lang.String", "eight");
    assertEnvEntry(entries, name("chaaracter"), "java.lang.String", "nine");
    assertEnvEntryLookup(entries, name("lookup"), "java.lang.String", "java:app/AppName");
    assertEquals("Enc.persistenceContextRefs.size()", 1, enc.persistenceContextRefs.size());
    final PersistenceContextReferenceInfo context = enc.persistenceContextRefs.get(0);
    assertEquals("Context.extended", false, context.extended);
    assertEquals("Context.persistenceUnitName", "yellow", context.persistenceUnitName);
    assertEquals("Context.properties.size()", 1, context.properties.size());
    assertEquals("Context.properties.getProperty(\"zzzz\")", "AAAA", context.properties.getProperty("zzzz"));
    assertEquals("Enc.persistenceUnitRefs.size()", 1, enc.persistenceUnitRefs.size());
    final PersistenceUnitReferenceInfo unit = enc.persistenceUnitRefs.get(0);
    assertEquals("Unit.persistenceUnitName", "yellow", unit.persistenceUnitName);
    assertEquals("Enc.resourceRefs.size()", 1, enc.resourceRefs.size());
    final ResourceReferenceInfo resource = enc.resourceRefs.get(0);
    assertEquals("Resource.referenceAuth", "CONTAINER", resource.referenceAuth);
}
Also used : PersistenceContextRef(org.apache.openejb.jee.PersistenceContextRef) ArrayList(java.util.ArrayList) PersistenceUnitReferenceInfo(org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) PersistenceUnit(javax.persistence.PersistenceUnit) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) Property(org.apache.openejb.jee.Property) PersistenceUnitRef(org.apache.openejb.jee.PersistenceUnitRef) EjbJar(org.apache.openejb.jee.EjbJar) EnvEntry(org.apache.openejb.jee.EnvEntry) EjbLocalRef(org.apache.openejb.jee.EjbLocalRef) PersistenceContextReferenceInfo(org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo) JndiEncInfo(org.apache.openejb.assembler.classic.JndiEncInfo) StatefulBean(org.apache.openejb.jee.StatefulBean) EnvEntryInfo(org.apache.openejb.assembler.classic.EnvEntryInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Persistence(org.apache.openejb.jee.jpa.unit.Persistence) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ResourceRef(org.apache.openejb.jee.ResourceRef) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Aggregations

ResourceReferenceInfo (org.apache.openejb.assembler.classic.ResourceReferenceInfo)5 Assembler (org.apache.openejb.assembler.classic.Assembler)3 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)3 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)3 PersistenceContextReferenceInfo (org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo)3 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)3 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)3 EjbJar (org.apache.openejb.jee.EjbJar)3 HashMap (java.util.HashMap)2 Resource (javax.annotation.Resource)2 EnvEntryInfo (org.apache.openejb.assembler.classic.EnvEntryInfo)2 PersistenceUnitReferenceInfo (org.apache.openejb.assembler.classic.PersistenceUnitReferenceInfo)2 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)2 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)2 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)2 PersistenceContextRef (org.apache.openejb.jee.PersistenceContextRef)2 ResourceRef (org.apache.openejb.jee.ResourceRef)2 StatelessBean (org.apache.openejb.jee.StatelessBean)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1