Search in sources :

Example 1 with EjbJarInfo

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

the class EJBExtender method startEJBs.

private void startEJBs(final Bundle bundle) {
    try {
        //If there is another thread adding or removing then stop here
        Object o = processingMap.put(bundle, PROCESSING_OBJECT);
        if (o == REMOVING_OBJECT || o == PROCESSING_OBJECT) {
            return;
        }
        //If already running then avoid
        if (runningApps.get(bundle) != null)
            return;
        //Broken validation for persistence :(
        EjbModule ejbModule = new EjbModule(AriesFrameworkUtil.getClassLoaderForced(bundle), null, null, null);
        try {
            Field f = EjbModule.class.getDeclaredField("validation");
            f.setAccessible(true);
            f.set(ejbModule, new ValidationProofValidationContext(ejbModule));
        } catch (Exception e) {
        // Hmmm
        }
        addAltDDs(ejbModule, bundle);
        //We build our own because we can't trust anyone to get the classpath right otherwise!
        ejbModule.setFinder(new OSGiFinder(bundle));
        ConfigurationFactory configurationFactory = new ConfigurationFactory();
        EjbJarInfo ejbInfo = null;
        //Avoid yet another ClassLoading problem
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(new ClassLoader(OpenEjbVersion.class.getClassLoader()) {

                protected Class<?> findClass(String name) throws ClassNotFoundException {
                    for (Bundle b : bundle.getBundleContext().getBundles()) {
                        if (b.getSymbolicName().contains("jaxb-impl"))
                            return b.loadClass(name);
                    }
                    throw new ClassNotFoundException(name);
                }
            });
            ejbInfo = configurationFactory.configureApplication(ejbModule);
            //Another oddity here
            ejbInfo.validationInfo = null;
        } finally {
            Thread.currentThread().setContextClassLoader(cl);
        }
        processJPAMappings(ejbInfo);
        Assembler assembler = (Assembler) SystemInstance.get().getComponent(Assembler.class);
        RunningApplication app = null;
        try {
            SystemInstance.get().setProperty("openejb.geronimo", "true");
            cl = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(OpenEjbVersion.class.getClassLoader());
                app = new RunningApplication(assembler.createApplication(ejbInfo, new AppClassLoader(ejbModule.getClassLoader())), bundle, ejbInfo.enterpriseBeans);
            } finally {
                Thread.currentThread().setContextClassLoader(cl);
            }
        } finally {
            SystemInstance.get().getProperties().remove("openejb.geronimo");
        }
        runningApps.put(bundle, app);
        app.init();
    } catch (OpenEJBException oee) {
        // TODO Auto-generated catch block
        oee.printStackTrace();
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (processingMap.remove(bundle) == REMOVING_OBJECT) {
            stopEJBs(bundle);
        }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) OpenEjbVersion(org.apache.openejb.util.OpenEjbVersion) Bundle(org.osgi.framework.Bundle) EjbModule(org.apache.openejb.config.EjbModule) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) Field(java.lang.reflect.Field) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) NamingException(javax.naming.NamingException) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 2 with EjbJarInfo

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

the class ActivationConfigPropertyOverrideTest method testEjbNameOverrideSystem.

public void testEjbNameOverrideSystem() throws Exception {
    SystemInstance.reset();
    final Properties properties = SystemInstance.get().getProperties();
    properties.setProperty("Orange.activation.maxSessions", "20");
    properties.setProperty("Orange.activation.maxMessagesPerSessions", "100");
    properties.setProperty("Orange.activation.destinationType", "javax.jms.Queue");
    properties.setProperty("Orange.activation.destination", "OVERRIDDEN.QUEUE");
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    // just to make sure class name is not used
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Yellow", Orange.class));
    // just to make sure class name is not used
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Orange", Yellow.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
    assertEquals("7", orange.activationProperties.get("maxSessions"));
    assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
    assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
    assertEquals("20", yellow.activationProperties.get("maxSessions"));
    assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
    assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
}
Also used : TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 3 with EjbJarInfo

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

the class ActivationConfigPropertyOverrideTest method testEjbNameOverrideOpenejbJar.

public void testEjbNameOverrideOpenejbJar() throws Exception {
    SystemInstance.reset();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
        final OpenejbJar openejbJar = new OpenejbJar();
        final Properties properties = openejbJar.getProperties();
        properties.setProperty("mdb.activation.maxSessions", "20");
        properties.setProperty("mdb.activation.maxMessagesPerSessions", "100");
        properties.setProperty("mdb.activation.destinationType", "javax.jms.Queue");
        properties.setProperty("mdb.activation.destination", "OVERRIDDEN.QUEUE");
        final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
        assertEquals("20", orange.activationProperties.get("maxSessions"));
        assertEquals("100", orange.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
        assertEquals("OVERRIDDEN.QUEUE", orange.activationProperties.get("destination"));
        assertEquals("20", yellow.activationProperties.get("maxSessions"));
        assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
        assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
    }
    // Verify the openejb-jar level overrides do not affect other apps
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
        assertEquals("7", orange.activationProperties.get("maxSessions"));
        assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
        assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
        assertEquals("5", yellow.activationProperties.get("maxSessions"));
        assertEquals("10", yellow.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Topic", yellow.activationProperties.get("destinationType"));
        assertEquals("YELLOW.TOPIC", yellow.activationProperties.get("destination"));
    }
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 4 with EjbJarInfo

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

the class AltDDPrefixTest method testMultitplePrefixes.

public void testMultitplePrefixes() throws Exception {
    System.out.println("*** testMultitplePrefixes ***");
    final Assembler assmbler = new Assembler();
    SystemInstance.get().setProperty("openejb.altdd.prefix", "footest, test");
    DeploymentLoader.reloadAltDD();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddapp2");
    final File file = URLs.toFile(resource);
    final AppInfo appInfo = factory.configureApplication(file);
    assertNotNull(appInfo);
    assertEquals(1, appInfo.ejbJars.size());
    final EjbJarInfo ejbJar = appInfo.ejbJars.get(0);
    // was the footest.ejb-jar.xml picked up
    assertEquals("EjbJar.enterpriseBeans", 1, ejbJar.enterpriseBeans.size());
    assertEquals("EjbJar.interceptors.size()", 1, ejbJar.interceptors.size());
    // was the test.env-entries.properties picked up
    // 4 + ComponentName
    assertEquals("EjbJar.enterpriseBeans.get(0).jndiEnc.envEntries.size()", 5, ejbJar.enterpriseBeans.get(0).jndiEnc.envEntries.size());
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) URL(java.net.URL) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 5 with EjbJarInfo

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

the class DeploymentContextPropertiesTest method testModuleContextProperties.

public void testModuleContextProperties() 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();
        openejbJar.getProperties().setProperty("color", "orange");
        ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final EjbJarInfo moduleInfo = config.configureApplication(ejbModule);
        assertProperty(moduleInfo.properties, "color", "orange");
        assembler.createApplication(moduleInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final Properties properties = beanContext.getModuleContext().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) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

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