Search in sources :

Example 26 with EjbJarInfo

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

the class UberInterfaceTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    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 StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    assertEquals(asList(Everything.class.getName()), beanInfo.businessLocal);
    assertEquals(asList(Everything.class.getName()), beanInfo.businessRemote);
    assertEquals(Everything.class.getName(), beanInfo.serviceEndpoint);
    assembler.createApplication(ejbJarInfo);
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext deployment = containerSystem.getBeanContext(beanInfo.ejbDeploymentId);
    assertEquals(asList(Everything.class), deployment.getBusinessLocalInterfaces());
    assertEquals(asList(Everything.class), deployment.getBusinessRemoteInterfaces());
    assertEquals(Everything.class, deployment.getServiceEndpointInterface());
    final InitialContext context = new InitialContext();
    final Everything local = (Everything) context.lookup("SuperBeanLocal");
    final Everything remote = (Everything) context.lookup("SuperBeanRemote");
    final Reference reference = new Reference("test");
    assertEquals(reference, local.echo(reference));
    // pass by reference
    assertSame(reference, local.echo(reference));
    assertEquals(reference, remote.echo(reference));
    // pass by value
    assertNotSame(reference, remote.echo(reference));
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) 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 27 with EjbJarInfo

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

Example 28 with EjbJarInfo

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

the class StatelessInterceptorTest method setUp.

public void setUp() throws Exception {
    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.createContainer(config.configureService(StatelessSessionContainerInfo.class));
    final EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
    assertNotNull(ejbJar);
    assembler.createApplication(ejbJar);
    final Properties properties = new Properties(System.getProperties());
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    ctx = new InitialContext(properties);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) InitialContext(javax.naming.InitialContext)

Example 29 with EjbJarInfo

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

the class CdiScanner method init.

@Override
public void init(final Object object) {
    if (!StartupObject.class.isInstance(object)) {
        return;
    }
    containerLoader = ParentClassLoaderFinder.Helper.get();
    final StartupObject startupObject = StartupObject.class.cast(object);
    final AppInfo appInfo = startupObject.getAppInfo();
    final ClassLoader classLoader = startupObject.getClassLoader();
    final ClassLoaderComparator comparator;
    if (classLoader instanceof ClassLoaderComparator) {
        comparator = (ClassLoaderComparator) classLoader;
    } else {
        comparator = new DefaultClassLoaderComparator(classLoader);
    }
    final WebBeansContext webBeansContext = startupObject.getWebBeansContext();
    final InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();
    // app beans
    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
        final BeansInfo beans = ejbJar.beans;
        if (beans == null || "false".equalsIgnoreCase(ejbJar.properties.getProperty("openejb.cdi.activated"))) {
            continue;
        }
        if (startupObject.isFromWebApp()) {
            // deploy only the related ejbmodule
            if (!ejbJar.moduleId.equals(startupObject.getWebContext().getId())) {
                continue;
            }
        } else if (ejbJar.webapp && !appInfo.webAppAlone) {
            continue;
        }
        if (appInfo.webAppAlone || !ejbJar.webapp) {
            // "manual" extension to avoid to add it through SPI mecanism
            classes.addAll(asList(TRANSACTIONAL_INTERCEPTORS));
            for (final Class<?> interceptor : TRANSACTIONAL_INTERCEPTORS) {
                interceptorsManager.addEnabledInterceptorClass(interceptor);
            }
        }
        // here for ears we need to skip classes in the parent classloader
        final ClassLoader scl = ClassLoader.getSystemClassLoader();
        final boolean filterByClassLoader = "true".equals(ejbJar.properties.getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, SystemInstance.get().getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, "true")));
        final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
        final boolean openejb = OpenEJBBeanInfoService.class.isInstance(beanArchiveService);
        final Map<BeansInfo.BDAInfo, BeanArchiveService.BeanArchiveInformation> infoByBda = new HashMap<>();
        for (final BeansInfo.BDAInfo bda : beans.bdas) {
            if (bda.uri != null) {
                try {
                    beansXml.add(bda.uri.toURL());
                } catch (final MalformedURLException e) {
                // no-op
                }
            }
            infoByBda.put(bda, handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda));
        }
        for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
            // infoByBda.put() not needed since we know it means annotated
            handleBda(startupObject, classLoader, comparator, beans, scl, filterByClassLoader, beanArchiveService, openejb, bda);
        }
        if (startupObject.getBeanContexts() != null) {
            for (final BeanContext bc : startupObject.getBeanContexts()) {
                final String name = bc.getBeanClass().getName();
                if (BeanContext.Comp.class.getName().equals(name)) {
                    continue;
                }
                boolean cdi = false;
                for (final BeansInfo.BDAInfo bda : beans.bdas) {
                    final BeanArchiveService.BeanArchiveInformation info = infoByBda.get(bda);
                    if (info.getBeanDiscoveryMode() == BeanArchiveService.BeanDiscoveryMode.NONE) {
                        continue;
                    }
                    if (bda.managedClasses.contains(name)) {
                        classes.add(load(name, classLoader));
                        cdi = true;
                        break;
                    }
                }
                if (!cdi) {
                    for (final BeansInfo.BDAInfo bda : beans.noDescriptorBdas) {
                        if (bda.managedClasses.contains(name)) {
                            classes.add(load(name, classLoader));
                            break;
                        }
                    }
                }
            }
        }
        if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.cdi.debug", "false"))) {
            final Logger logger = Logger.getInstance(LogCategory.OPENEJB, CdiScanner.class.getName());
            logger.info("CDI beans for " + startupObject.getAppInfo().appId + (startupObject.getWebContext() != null ? " webcontext = " + startupObject.getWebContext().getContextRoot() : ""));
            final List<String> names = new ArrayList<>(classes.size());
            for (final Class<?> c : classes) {
                names.add(c.getName());
            }
            Collections.sort(names);
            for (final String c : names) {
                logger.info("    " + c);
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ClassLoaderComparator(org.apache.openejb.util.classloader.ClassLoaderComparator) DefaultClassLoaderComparator(org.apache.openejb.util.classloader.DefaultClassLoaderComparator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Logger(org.apache.openejb.util.Logger) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeansInfo(org.apache.openejb.assembler.classic.BeansInfo) DefaultClassLoaderComparator(org.apache.openejb.util.classloader.DefaultClassLoaderComparator) BeanArchiveService(org.apache.webbeans.spi.BeanArchiveService) AppInfo(org.apache.openejb.assembler.classic.AppInfo) BeanContext(org.apache.openejb.BeanContext) InterceptorsManager(org.apache.webbeans.intercept.InterceptorsManager) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 30 with EjbJarInfo

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

the class Deploy method print.

private static void print(final AppInfo appInfo) {
    System.out.println("App(id=" + appInfo.path + ")");
    for (final EjbJarInfo info : appInfo.ejbJars) {
        System.out.println("    EjbJar(id=" + info.moduleName + ", path=" + info.path + ")");
        for (final EnterpriseBeanInfo beanInfo : info.enterpriseBeans) {
            System.out.println("        Ejb(ejb-name=" + beanInfo.ejbName + ", id=" + beanInfo.ejbDeploymentId + ")");
            for (final String name : beanInfo.jndiNames) {
                System.out.println("            Jndi(name=" + name + ")");
            }
            System.out.println("");
        }
        for (final InterceptorInfo interceptorInfo : info.interceptors) {
            System.out.println("        Interceptor(class=" + interceptorInfo.clazz + ")");
        }
        System.out.println("");
    }
    for (final ClientInfo clientInfo : appInfo.clients) {
        System.out.println("    Client(main-class=" + clientInfo.mainClass + ", id=" + clientInfo.moduleId + ", path=" + clientInfo.path + ")");
        System.out.println("");
    }
    for (final ConnectorInfo connectorInfo : appInfo.connectors) {
        System.out.println("    Connector(id=" + connectorInfo.moduleId + ", path=" + connectorInfo.path + ")");
        System.out.println("");
    }
    for (final WebAppInfo webAppInfo : appInfo.webApps) {
        System.out.println("    WebApp(context-root=" + webAppInfo.contextRoot + ", id=" + webAppInfo.moduleId + ", path=" + webAppInfo.path + ")");
        System.out.println("");
    }
    for (final PersistenceUnitInfo persistenceUnitInfo : appInfo.persistenceUnits) {
        System.out.println("    PersistenceUnit(name=" + persistenceUnitInfo.name + ", provider=" + persistenceUnitInfo.provider + ")");
        System.out.println("");
    }
}
Also used : EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ConnectorInfo(org.apache.openejb.assembler.classic.ConnectorInfo) InterceptorInfo(org.apache.openejb.assembler.classic.InterceptorInfo) ClientInfo(org.apache.openejb.assembler.classic.ClientInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Aggregations

EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)52 Assembler (org.apache.openejb.assembler.classic.Assembler)34 EjbJar (org.apache.openejb.jee.EjbJar)26 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)21 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)21 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)17 AppInfo (org.apache.openejb.assembler.classic.AppInfo)16 HashMap (java.util.HashMap)14 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)14 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)13 BeanContext (org.apache.openejb.BeanContext)11 File (java.io.File)10 Properties (java.util.Properties)10 InitialContext (javax.naming.InitialContext)10 StatelessBean (org.apache.openejb.jee.StatelessBean)10 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)9 ArrayList (java.util.ArrayList)8 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)8 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)8 Test (org.junit.Test)8