Search in sources :

Example 56 with ConfigurationFactory

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

the class JavaLookupTest method test.

public void test() throws Exception {
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final InitialContext context = new InitialContext();
    assertTrue(context.lookup("java:openejb/TransactionManager") instanceof TransactionManager);
    assertTrue(context.lookup("java:comp/TransactionManager") instanceof TransactionManager);
    assertTrue(context.lookup("java:comp/UserTransaction") instanceof UserTransaction);
    assertTrue(context.lookup("java:comp/TransactionSynchronizationRegistry") instanceof TransactionSynchronizationRegistry);
}
Also used : UserTransaction(javax.transaction.UserTransaction) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) InitialContext(javax.naming.InitialContext)

Example 57 with ConfigurationFactory

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

the class JavaLookupTest method testLinking.

public void testLinking() throws Exception {
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final InitialContext context = new InitialContext();
    final Context javaContext = (Context) context.lookup("java:");
    javaContext.bind("java:TransactionManager", new JndiUrlReference("java:comp/TransactionManager"));
    javaContext.bind("java:TransactionManagerLink", new LinkRef("java:comp/TransactionManager"));
    assertTrue(context.lookup("java:TransactionManager") instanceof TransactionManager);
    assertTrue(context.lookup("java:TransactionManagerLink") instanceof TransactionManager);
    new InitialContext().bind("java:foo", new LinkRef("java:comp/TransactionManager"));
    assertTrue(context.lookup("java:foo") instanceof TransactionManager);
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) TransactionManager(javax.transaction.TransactionManager) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) InitialContext(javax.naming.InitialContext) LinkRef(javax.naming.LinkRef)

Example 58 with ConfigurationFactory

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

the class OpenejbLookupTest method testLocalInitialContext.

public void testLocalInitialContext() throws Exception {
    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 StatelessBean(FooBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    Context context = new InitialContext(properties);
    // This is still the jvm InitialContext delegating to the openejbURLContextFactory
    assertTrue(context instanceof InitialContext);
    assertOpenejbUrlLookups(context);
    // Now we have effectively unwrapped the InitalContext, openejb: lookups should still work.
    context = (Context) context.lookup("");
    assertTrue(context instanceof IvmContext);
    assertOpenejbUrlLookups(context);
    // Test that an EJB can lookup items from openejb:
    final FooLocal fooLocal = (FooLocal) context.lookup("FooBeanLocal");
    fooLocal.test();
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) 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)

Example 59 with ConfigurationFactory

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

the class ManagedBeanTest method setUp.

@Override
protected void setUp() 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();
    ejbJar.addEnterpriseBean(new ManagedBean(MyBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
}
Also used : TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) ManagedBean(org.apache.openejb.jee.ManagedBean) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 60 with ConfigurationFactory

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

the class CustomMdbContainerTest 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.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // Setup the descriptor information
    EmailBean.lifecycle.clear();
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
    final Connector connector = new Connector("email-ra");
    final ResourceAdapter adapter = new ResourceAdapter(EmailResourceAdapter.class);
    connector.setResourceAdapter(adapter);
    final InboundResourceadapter inbound = adapter.setInboundResourceAdapter(new InboundResourceadapter());
    final MessageAdapter messageAdapter = inbound.setMessageAdapter(new MessageAdapter());
    final MessageListener listener = messageAdapter.addMessageListener(new MessageListener(EmailConsumer.class, EmailAccountInfo.class));
    listener.getActivationSpec().addRequiredConfigProperty("address");
    app.getConnectorModules().add(new ConnectorModule(connector));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(EmailBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final InitialContext initialContext = new InitialContext();
    final EmailResourceAdapter ra = (EmailResourceAdapter) initialContext.lookup("java:openejb/Resource/email-raRA");
    final Properties headers = new Properties();
    headers.put("To", "dblevins@apache.org");
    headers.put("From", "dblevins@visi.com");
    headers.put("Subject", "Hello");
    ra.deliverEmail(headers, "How's it going?");
    final Stack<Lifecycle> lifecycle = EmailBean.lifecycle;
    final List expected = Arrays.asList(Lifecycle.values());
    Assert.assertEquals(Join.join("\n", expected), Join.join("\n", lifecycle));
}
Also used : Connector(org.apache.openejb.jee.Connector) AppModule(org.apache.openejb.config.AppModule) MessageListener(org.apache.openejb.jee.MessageListener) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Properties(java.util.Properties) ConnectorModule(org.apache.openejb.config.ConnectorModule) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) List(java.util.List) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) MessageAdapter(org.apache.openejb.jee.MessageAdapter) InitialContext(javax.naming.InitialContext) AppInfo(org.apache.openejb.assembler.classic.AppInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) Assembler(org.apache.openejb.assembler.classic.Assembler)

Aggregations

ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)100 Assembler (org.apache.openejb.assembler.classic.Assembler)84 EjbJar (org.apache.openejb.jee.EjbJar)76 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)57 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)57 StatelessBean (org.apache.openejb.jee.StatelessBean)44 InitialContext (javax.naming.InitialContext)41 Properties (java.util.Properties)37 EjbModule (org.apache.openejb.config.EjbModule)30 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)29 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)29 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)21 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 AppModule (org.apache.openejb.config.AppModule)15 ServerFederation (org.apache.openejb.core.ServerFederation)15 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)14 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13