Search in sources :

Example 6 with StatelessSessionContainerInfo

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

the class InjectionTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.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));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "10");
    statelessContainerInfo.properties.setProperty("MaxSize", "0");
    statelessContainerInfo.properties.setProperty("StrictPooling", "false");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final StatelessBean bean = new StatelessBean(WidgetBean.class);
    bean.addBusinessLocal(Widget.class.getName());
    bean.addBusinessRemote(RemoteWidget.class.getName());
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    bean.getEnvEntry().add(new EnvEntry(name("myString"), "java.lang.String", "2"));
    bean.getEnvEntry().add(new EnvEntry(name("myDouble"), "java.lang.Double", "3.0"));
    bean.getEnvEntry().add(new EnvEntry(name("myLong"), "java.lang.Long", "4"));
    bean.getEnvEntry().add(new EnvEntry(name("myFloat"), "java.lang.Float", "5"));
    bean.getEnvEntry().add(new EnvEntry(name("myInteger"), "java.lang.Integer", "6"));
    bean.getEnvEntry().add(new EnvEntry(name("myShort"), "java.lang.Short", "7"));
    bean.getEnvEntry().add(new EnvEntry(name("myBoolean"), "java.lang.Boolean", "false"));
    bean.getEnvEntry().add(new EnvEntry(name("myByte"), "java.lang.Byte", "8"));
    bean.getEnvEntry().add(new EnvEntry(name("myCharacter"), "java.lang.Character", "9"));
    bean.getEnvEntry().add(new EnvEntry(name("myClass"), "java.lang.Class", Widget.class.getName()));
    bean.getEnvEntry().add(new EnvEntry(name("myTimeUnit"), TimeUnit.class.getName(), "HOURS"));
    final EnvEntry entry = new EnvEntry("injectedBoolean", (String) null, "true");
    entry.getInjectionTarget().add((new InjectionTarget(WidgetBean.class.getName(), "injectedBoolean")));
    bean.getEnvEntry().add(entry);
    final ResourceEnvRef resourceEnvRef = new ResourceEnvRef("injectedContext", (String) null);
    resourceEnvRef.getInjectionTarget().add((new InjectionTarget(WidgetBean.class.getName(), "injectedContext")));
    bean.getResourceEnvRef().add(resourceEnvRef);
    assembler.createApplication(config.configureApplication(ejbJar));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) InjectionTarget(org.apache.openejb.jee.InjectionTarget) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) ResourceEnvRef(org.apache.openejb.jee.ResourceEnvRef) EjbJar(org.apache.openejb.jee.EjbJar) EnvEntry(org.apache.openejb.jee.EnvEntry)

Example 7 with StatelessSessionContainerInfo

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

the class JndiNameTest method testOpenejbJar2.

public void testOpenejbJar2() 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));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final EjbModule ejbModule = new EjbModule(new EjbJar(), null);
    ejbModule.getEjbJar().addEnterpriseBean(new StatelessBean(FooBean.class));
    final OpenejbJarType v2 = new OpenejbJarType();
    final SessionBeanType ejbDeployment = new SessionBeanType();
    ejbDeployment.setEjbName("FooBean");
    ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("thename", "Local"));
    ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("anothername", "Remote"));
    ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("loldstyle", "LocalHome"));
    ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("roldstyle", "RemoteHome"));
    v2.getEnterpriseBeans().add(ejbDeployment);
    ejbModule.getAltDDs().put("openejb-jar.xml", v2);
    assembler.createApplication(config.configureApplication(ejbModule));
    final InitialContext initialContext = new InitialContext();
    assertName(initialContext, Orange.class, "thename");
    assertName(initialContext, Red.class, "anothername");
    assertName(initialContext, LHYellow.class, "loldstyle");
    assertName(initialContext, RHGreen.class, "roldstyle");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) OpenejbJarType(org.apache.openejb.jee.oejb2.OpenejbJarType) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) SessionBeanType(org.apache.openejb.jee.oejb2.SessionBeanType) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 8 with StatelessSessionContainerInfo

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

the class DependsOnTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
    final StatelessSessionContainerInfo statelessContainer = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainer.properties.setProperty("MinSize", "1");
    statelessContainer.properties.setProperty("MaxSize", "1");
    assembler.createContainer(statelessContainer);
    actualConstruct.clear();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Two.class));
    ejbJar.addEnterpriseBean(new SingletonBean(One.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Four.class));
    ejbJar.addEnterpriseBean(new StatelessBean(Three.class));
    // startup and trigger @PostConstruct
    assembler.createApplication(config.configureApplication(ejbJar));
    assertEquals(expected(four, three, two, one), actualConstruct);
    actualDestroy.clear();
    // startup and trigger @PreDestroy
    for (final AppInfo appInfo : assembler.getDeployedApplications()) {
        assembler.destroyApplication(appInfo.path);
    }
    assertEquals(expected(one, two, three, four), actualDestroy);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) AppInfo(org.apache.openejb.assembler.classic.AppInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) 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) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 9 with StatelessSessionContainerInfo

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

the class ConfigureServiceTest method testConfigureService2.

public void testConfigureService2() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    // We should be able to create one of these with a different name
    final Container container = new Container("MyContainer", "STATELESS", "org.acme#CheddarContainer");
    final StatelessSessionContainerInfo myStatelessContainer = factory.configureService(container, StatelessSessionContainerInfo.class);
    assertNotNull(myStatelessContainer);
    assertEquals("MyContainer", myStatelessContainer.id);
    assertEquals("org.acme.SuperContainer", myStatelessContainer.className);
    assertNotNull(myStatelessContainer.constructorArgs);
    assertNotNull(myStatelessContainer.properties);
    assertNotNull(myStatelessContainer.properties.getProperty("myProperty"));
    assertEquals("Yummy Cheese", myStatelessContainer.properties.getProperty("myProperty"));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Container(org.apache.openejb.config.sys.Container)

Example 10 with StatelessSessionContainerInfo

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

the class ConfigureServiceTest method testConfigureServiceAddedPropertyViaURI2.

public void testConfigureServiceAddedPropertyViaURI2() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URI uri = new URI("new://Container?type=STATELESS&provider=org.acme%23CheddarContainer&myProperty=Queso");
    final Container container = (Container) factory.toConfigDeclaration("MyContainer", uri);
    container.getProperties().setProperty("anotherProperty", "Cheese is good");
    final StatelessSessionContainerInfo myStatelessContainer = factory.configureService(container, StatelessSessionContainerInfo.class);
    assertNotNull(myStatelessContainer);
    assertEquals("MyContainer", myStatelessContainer.id);
    assertEquals("org.acme.SuperContainer", myStatelessContainer.className);
    assertNotNull(myStatelessContainer.constructorArgs);
    assertNotNull(myStatelessContainer.properties);
    assertNotNull(myStatelessContainer.properties.getProperty("myProperty"));
    assertEquals("Queso", myStatelessContainer.properties.getProperty("myProperty"));
    assertNotNull(myStatelessContainer.properties.getProperty("anotherProperty"));
    assertEquals("Cheese is good", myStatelessContainer.properties.getProperty("anotherProperty"));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Container(org.apache.openejb.config.sys.Container) URI(java.net.URI)

Aggregations

StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)23 Assembler (org.apache.openejb.assembler.classic.Assembler)16 EjbJar (org.apache.openejb.jee.EjbJar)16 StatelessBean (org.apache.openejb.jee.StatelessBean)16 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)13 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)13 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)12 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)10 InitialContext (javax.naming.InitialContext)9 Container (org.apache.openejb.config.sys.Container)7 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)6 Properties (java.util.Properties)4 Context (javax.naming.Context)4 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)4 ObjectName (javax.management.ObjectName)3 ServerFederation (org.apache.openejb.core.ServerFederation)3 EnvEntry (org.apache.openejb.jee.EnvEntry)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)2