Search in sources :

Example 11 with StatelessSessionContainerInfo

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

the class ConfigureServiceTest method testConfigureServiceAddedPropertyViaURI_Unencoded.

public void testConfigureServiceAddedPropertyViaURI_Unencoded() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    final Container container = (Container) factory.toConfigDeclaration("MyContainer", "new://Container?type=STATELESS&provider=org.acme#CheddarContainer");
    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("Yummy Cheese", 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)

Example 12 with StatelessSessionContainerInfo

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

the class ConfigureServiceTest method testConfigureService.

public void testConfigureService() throws Exception {
    final ConfigurationFactory factory = new ConfigurationFactory();
    // We should be able to create a default definition
    final StatelessSessionContainerInfo defaultStatelessContainer = factory.configureService(StatelessSessionContainerInfo.class);
    assertNotNull(defaultStatelessContainer);
    assertNotNull(defaultStatelessContainer.id);
    assertNotNull(defaultStatelessContainer.className);
    assertNotNull(defaultStatelessContainer.constructorArgs);
    assertNotNull(defaultStatelessContainer.properties);
    // We should be able to create one of these with a different name
    final Container container = new Container("My Stateless Container");
    final StatelessSessionContainerInfo myStatelessContainer = factory.configureService(container, StatelessSessionContainerInfo.class);
    assertNotNull(myStatelessContainer);
    assertEquals("My Stateless Container", myStatelessContainer.id);
    assertEquals(defaultStatelessContainer.className, myStatelessContainer.className);
    assertNotNull(myStatelessContainer.constructorArgs);
    assertNotNull(myStatelessContainer.properties);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Container(org.apache.openejb.config.sys.Container)

Example 13 with StatelessSessionContainerInfo

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

the class MultithreadTest method setUp.

@Before
public void setUp() throws Exception {
    final int poolSize = 10;
    System.setProperty("openejb.client.connectionpool.size", "" + (poolSize * 2));
    final EjbServer ejbServer = new EjbServer();
    final KeepAliveServer keepAliveServer = new KeepAliveServer(ejbServer, false);
    final Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    final ServicePool pool = new ServicePool(keepAliveServer, (poolSize * 2));
    this.serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    final int port = serviceDaemon.getPort();
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "100");
    statelessContainerInfo.properties.setProperty("PoolSize", "" + poolSize);
    statelessContainerInfo.properties.setProperty("MinSize", "2");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final StatelessBean bean = new StatelessBean(CounterBean.class);
    bean.addBusinessLocal(Counter.class.getName());
    bean.addBusinessRemote(RemoteCounter.class.getName());
    bean.addPostConstruct("init");
    bean.addPreDestroy("destroy");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    CounterBean.instances.set(0);
    assembler.createApplication(config.configureApplication(ejbJar));
    final Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
    final Context context = new InitialContext(props);
    counter = (Counter) context.lookup("CounterBeanRemote");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ServicePool(org.apache.openejb.server.ServicePool) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Example 14 with StatelessSessionContainerInfo

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

the class StaticFailoverTest method testStatelessBeanTimeout.

public void testStatelessBeanTimeout() throws Exception {
    Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    System.setProperty(org.apache.openejb.client.SocketConnectionFactory.PROPERTY_POOL_SIZE, "" + 20);
    EjbServer ejbServer = new EjbServer();
    ejbServer.init(new Properties());
    daemons.add(createServiceDaemon(20, ejbServer, red));
    daemons.add(createServiceDaemon(20, ejbServer, blue));
    ConfigurationFactory config = new ConfigurationFactory();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    // containers
    StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "100");
    statelessContainerInfo.properties.setProperty("PoolSize", "" + 10);
    statelessContainerInfo.properties.setProperty("MinSize", "2");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    StatelessBean bean = new StatelessBean(CounterBean.class);
    bean.addBusinessLocal(Counter.class.getName());
    bean.addBusinessRemote(RemoteCounter.class.getName());
    bean.addPostConstruct("init");
    bean.addPreDestroy("destroy");
    EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(bean);
    CounterBean.instances.set(0);
    assembler.createApplication(config.configureApplication(ejbJar));
    String failoverURI = "failover:roundrobin:";
    failoverURI += "ejbd://127.0.0.1:" + daemons.get(0).getPort() + "?red,";
    failoverURI += "ejbd://127.0.0.1:" + daemons.get(1).getPort() + "?blue";
    Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", failoverURI);
    Context context = new InitialContext(props);
    counter = (Counter) context.lookup("CounterBeanRemote");
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
    System.out.println(counter.hit());
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 15 with StatelessSessionContainerInfo

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

the class ModuleNameInjectionTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    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);
    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.setModuleName("myEjbModule");
    ejbJar.addEnterpriseBean(bean);
    EnvEntry entry;
    entry = new EnvEntry("moduleName", (String) null, null);
    entry.setLookupName("java:module/ModuleName");
    entry.getInjectionTarget().add((new InjectionTarget(WidgetBean.class.getName(), "moduleName")));
    bean.getEnvEntry().add(entry);
    entry = new EnvEntry("appName", (String) null, null);
    entry.setLookupName("java:app/AppName");
    entry.getInjectionTarget().add((new InjectionTarget(WidgetBean.class.getName(), "appName")));
    bean.getEnvEntry().add(entry);
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app", new Application("myApp"), false);
    app.getEjbModules().add(new EjbModule(ejbJar));
    assembler.createApplication(config.configureApplication(app));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) 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) Application(org.apache.openejb.jee.Application) EjbJar(org.apache.openejb.jee.EjbJar) EnvEntry(org.apache.openejb.jee.EnvEntry)

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