Search in sources :

Example 1 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory 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 ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class CdiDecoratorTest method setUp.

@Before
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 EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean("HelloOne", RedBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean("HelloTwo", RedBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean(OrangeBean.class));
    final Beans beans = new Beans();
    beans.addInterceptor(OrangeCdiInterceptor.class);
    beans.addDecorator(OrangeOneDecorator.class);
    beans.addDecorator(OrangeTwoDecorator.class);
    beans.addManagedClass(YellowBean.class);
    final EjbModule module = new EjbModule(ejbJar);
    module.setBeans(beans);
    assembler.createApplication(config.configureApplication(module));
    final Properties properties = new Properties(System.getProperties());
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    ctx = new InitialContext(properties);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) Beans(org.apache.openejb.jee.Beans) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Example 3 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class RedeployTest method test.

public void test() throws Exception {
    // create reference to openejb itests
    final File file = JarLocation.jarLocation(BasicStatelessBean.class);
    if (!file.exists()) {
        throw new Exception("File not found: " + file);
    }
    // These two objects pretty much encompas all the EJB Container
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    createAndDestroy(assembler, config, file);
    createAndDestroy(assembler, config, file);
    createAndDestroy(assembler, config, file);
}
Also used : ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) File(java.io.File) NamingException(javax.naming.NamingException)

Example 4 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class EjbRefTest method setUp.

protected void setUp() throws Exception {
    config = new ConfigurationFactory();
    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));
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    context = new InitialContext();
}
Also used : ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) InitialContext(javax.naming.InitialContext)

Example 5 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class EjbSecurityRoleRefTest method setUp.

protected void setUp() throws Exception {
    config = new ConfigurationFactory();
    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 Properties props = new Properties();
    props.setProperty(Context.SECURITY_PRINCIPAL, "jonathan");
    props.setProperty(Context.SECURITY_CREDENTIALS, "secret");
    props.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    context = new InitialContext(props);
}
Also used : ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext)

Aggregations

ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)98 Assembler (org.apache.openejb.assembler.classic.Assembler)83 EjbJar (org.apache.openejb.jee.EjbJar)75 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)56 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)56 StatelessBean (org.apache.openejb.jee.StatelessBean)44 InitialContext (javax.naming.InitialContext)40 Properties (java.util.Properties)35 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)29 EjbModule (org.apache.openejb.config.EjbModule)29 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)29 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)20 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)18 SingletonBean (org.apache.openejb.jee.SingletonBean)18 Context (javax.naming.Context)17 StatefulBean (org.apache.openejb.jee.StatefulBean)16 ServerFederation (org.apache.openejb.core.ServerFederation)15 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)14 AppModule (org.apache.openejb.config.AppModule)13 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13