Search in sources :

Example 41 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class JaxWsInvocationTest method buildTestApp.

public EjbModule buildTestApp() {
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));
    bean.setServiceEndpoint(EchoServiceEndpoint.class.getName());
    return new EjbModule(this.getClass().getClassLoader(), this.getClass().getSimpleName(), "test", ejbJar, null);
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) EjbJar(org.apache.openejb.jee.EjbJar)

Example 42 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class StatelessConstructorInjectionTest 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);
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class));
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    bean.getEnvEntry().add(new EnvEntry("count", Integer.class.getName(), "10"));
    assembler.createApplication(config.configureApplication(new EjbModule(ejbJar).withCdi()));
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) EjbModule(org.apache.openejb.config.EjbModule) 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) 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) EnvEntry(org.apache.openejb.jee.EnvEntry)

Example 43 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class ScheduleTest method testSchedule.

public void testSchedule() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.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));
    final EjbJar ejbJar = new EjbJar();
    // Configure schedule by deployment plan
    final StatelessBean subBeanA = new StatelessBean(SubBeanA.class);
    final Timer subBeanATimer = new Timer();
    subBeanATimer.setTimeoutMethod(new NamedMethod("subBeanA", "javax.ejb.Timer"));
    final TimerSchedule timerScheduleA = new TimerSchedule();
    timerScheduleA.setSecond("2");
    timerScheduleA.setMinute("*");
    timerScheduleA.setHour("*");
    subBeanATimer.setSchedule(timerScheduleA);
    subBeanATimer.setInfo("SubBeanAInfo");
    subBeanA.getTimer().add(subBeanATimer);
    ejbJar.addEnterpriseBean(subBeanA);
    // Configure schedule by annotation
    final StatelessBean subBeanB = new StatelessBean(SubBeanB.class);
    ejbJar.addEnterpriseBean(subBeanB);
    // Override aroundTimeout annotation by deployment plan
    final StatelessBean subBeanC = new StatelessBean(SubBeanC.class);
    final Timer subBeanCTimer = new Timer();
    subBeanCTimer.setTimeoutMethod(new NamedMethod("subBeanC", "javax.ejb.Timer"));
    final TimerSchedule timerScheduleC = new TimerSchedule();
    timerScheduleC.setSecond("2");
    timerScheduleC.setMinute("*");
    timerScheduleC.setHour("*");
    subBeanCTimer.setSchedule(timerScheduleC);
    subBeanCTimer.setInfo("SubBeanCInfo");
    subBeanC.getTimer().add(subBeanCTimer);
    ejbJar.addEnterpriseBean(subBeanC);
    final StatefulBean subBeanM = new StatefulBean(SubBeanM.class);
    ejbJar.addEnterpriseBean(subBeanM);
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    countDownLatch.await(1L, TimeUnit.MINUTES);
    // A better way for validation ?
    int beforeAroundInvocationCount = 0;
    int afterAroundInvocationCount = 0;
    int timeoutInvocationCount = 0;
    final int size;
    synchronized (result) {
        size = result.size();
        for (final Call call : result) {
            switch(call) {
                case BEAN_BEFORE_AROUNDTIMEOUT:
                    beforeAroundInvocationCount++;
                    break;
                case BEAN_AFTER_AROUNDTIMEOUT:
                    afterAroundInvocationCount++;
                    break;
                case TIMEOUT:
                    timeoutInvocationCount++;
                    break;
            }
        }
    }
    assertEquals(3, beforeAroundInvocationCount);
    assertEquals(3, afterAroundInvocationCount);
    assertEquals(3, timeoutInvocationCount);
    assertEquals(9, size);
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) NamedMethod(org.apache.openejb.jee.NamedMethod) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TimerSchedule(org.apache.openejb.jee.TimerSchedule) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Timer(org.apache.openejb.jee.Timer) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 44 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class DynamicEJBImplTest method app.

@Module
public EjbJar app() throws Exception {
    final EjbJar ejbJar = new EjbJar("dynamic");
    ejbJar.addEnterpriseBean(new SingletonBean(UtilBean.class));
    ejbJar.addEnterpriseBean(new SingletonBean(DynamicCustomProxy.class));
    ejbJar.addEnterpriseBean(new StatelessBean(UserDAO.class));
    ejbJar.addEnterpriseBean(new StatelessBean(UserDAOChild.class));
    return ejbJar;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar) Module(org.apache.openejb.testing.Module)

Example 45 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class StatelessInvocationStatsTest method testInvocation.

/**
 * @throws Exception On error
 */
@Test
public void testInvocation() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, OpenEJBInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("AccessTimeout", "0");
    statelessContainerInfo.properties.setProperty("MaxSize", "2");
    statelessContainerInfo.properties.setProperty("MinSize", "0");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    statelessContainerInfo.properties.setProperty("IdleTimeout", "0");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    CounterBean.instances.set(0);
    final EjbJar ejbJar = new EjbJar("StatsInvocModule");
    ejbJar.addEnterpriseBean(new StatelessBean(CounterBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final javax.naming.Context context = new InitialContext();
    final CounterBean bean = (CounterBean) context.lookup("CounterBeanLocalBean");
    // Invoke
    bean.waitSecs();
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final ObjectName invocationsName = new ObjectName("openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,EJBModule=StatsInvocModule,StatelessSessionBean=CounterBean," + "j2eeType=Invocations,name=CounterBean");
    // Grab the mbeanInfo and check the expected attributes exist and have the correct return types and parameters
    final MBeanInfo invocationsMBeanInfo = server.getMBeanInfo(invocationsName);
    for (final MBeanAttributeInfo info : invocationsMBeanInfo.getAttributes()) {
        // System.out.println("//" + info.getName() + " " + server.getAttribute(invocationsName, info.getName()));
        if (info.getName().equals("waitSecs().GeometricMean") || info.getName().equals("waitSecs().Max") || info.getName().equals("waitSecs().Mean") || info.getName().equals("waitSecs().Min") || info.getName().equals("waitSecs().Percentile01") || info.getName().equals("waitSecs().Percentile10") || info.getName().equals("waitSecs().Percentile25") || info.getName().equals("waitSecs().Percentile50") || info.getName().equals("waitSecs().Percentile75") || info.getName().equals("waitSecs().Percentile90") || info.getName().equals("waitSecs().Percentile99") || info.getName().equals("waitSecs().Sum")) {
            final Double actual = (Double) (server.getAttribute(invocationsName, info.getName()));
            Assert.assertTrue("Expected: " + actual + " >= 999", actual >= 999);
        }
    }
    ejbJar.removeEnterpriseBean("StatsInvocModule");
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) MBeanInfo(javax.management.MBeanInfo) OpenEJBInitialContextFactory(org.apache.openejb.core.OpenEJBInitialContextFactory) InitialContext(javax.naming.InitialContext) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) 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) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) Test(org.junit.Test)

Aggregations

EjbJar (org.apache.openejb.jee.EjbJar)242 StatelessBean (org.apache.openejb.jee.StatelessBean)117 Assembler (org.apache.openejb.assembler.classic.Assembler)88 EjbModule (org.apache.openejb.config.EjbModule)81 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)76 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)60 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)60 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)50 Properties (java.util.Properties)49 InitialContext (javax.naming.InitialContext)43 SingletonBean (org.apache.openejb.jee.SingletonBean)42 AppModule (org.apache.openejb.config.AppModule)40 StatefulBean (org.apache.openejb.jee.StatefulBean)33 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)31 Module (org.apache.openejb.testing.Module)30 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)27 Test (org.junit.Test)26 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)25 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)24 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)21