Search in sources :

Example 86 with ConfigurationFactory

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

the class FailoverTest method _testCleanShutdown.

public void _testCleanShutdown() throws Exception {
    agent = new TestAgent();
    try {
        // Properties initProps = System.getProperties();
        final Properties initProps = new Properties();
        initProps.setProperty("openejb.deployments.classpath.include", "");
        initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
        OpenEJB.init(initProps, new ServerFederation());
    } catch (Exception e) {
    }
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Target.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    SystemInstance.get().setComponent(DiscoveryAgent.class, agent);
    final ServerService red = server(Host.RED);
    final ServerService blue = server(Host.BLUE);
    final ServerService green = server(Host.GREEN);
    red.start();
    blue.start();
    green.start();
    final TargetRemote target = getBean(red);
    assertEquals(Host.RED, target.getHost());
    red.stop();
    assertEquals(Host.BLUE, target.getHost());
    blue.stop();
    assertEquals(Host.GREEN, target.getHost());
    green.stop();
    try {
        target.getHost();
        fail("EJBException should have been thrown");
    } catch (EJBException e) {
    // pass
    }
    red.start();
    assertEquals(Host.RED, target.getHost());
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) StatelessBean(org.apache.openejb.jee.StatelessBean) ServerService(org.apache.openejb.server.ServerService) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) EJBException(javax.ejb.EJBException) ServiceException(org.apache.openejb.server.ServiceException) EjbJar(org.apache.openejb.jee.EjbJar)

Example 87 with ConfigurationFactory

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

the class FailoverTest method testCrash.

public void testCrash() throws Exception {
    agent = new TestAgent();
    try {
        // Properties initProps = System.getProperties();
        final Properties initProps = new Properties();
        initProps.setProperty("openejb.deployments.classpath.include", "");
        initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
        OpenEJB.init(initProps, new ServerFederation());
    } catch (Exception e) {
    }
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Target.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    SystemInstance.get().setComponent(DiscoveryAgent.class, agent);
    final ServerService red = server(Host.RED);
    final ServerService blue = server(Host.BLUE);
    final ServerService green = server(Host.GREEN);
    red.start();
    blue.start();
    green.start();
    final TargetRemote target = getBean(red);
    assertEquals(Host.GREEN, target.kill(Host.RED, Host.BLUE).host);
    assertEquals(Host.GREEN, target.getHost());
    red.stop();
    blue.stop();
    green.stop();
    try {
        target.getHost();
        fail("EJBException should have been thrown");
    } catch (EJBException e) {
    // pass
    }
    red.start();
    assertEquals(Host.RED, target.getHost());
    red.stop();
    OpenEJB.destroy();
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) StatelessBean(org.apache.openejb.jee.StatelessBean) ServerService(org.apache.openejb.server.ServerService) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) EJBException(javax.ejb.EJBException) ServiceException(org.apache.openejb.server.ServiceException) EjbJar(org.apache.openejb.jee.EjbJar)

Example 88 with ConfigurationFactory

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

the class FullPoolFailoverTest method setup.

protected void setup(final int statelessPoolSize, final int connectionPoolSize) 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, "" + connectionPoolSize);
    EjbServer ejbServer = new EjbServer();
    ejbServer.init(new Properties());
    daemons.add(createServiceDaemon(connectionPoolSize, ejbServer, red));
    daemons.add(createServiceDaemon(connectionPoolSize, ejbServer, blue));
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    // containers
    StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("TimeOut", "100");
    statelessContainerInfo.properties.setProperty("PoolSize", "" + statelessPoolSize);
    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:sticky:";
    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");
    hold.clear();
    hits.clear();
}
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 89 with ConfigurationFactory

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

the class PropertiesPropogationTest method test.

public void test() throws Exception {
    EjbServer ejbServer = new EjbServer();
    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());
    ServicePool pool = new ServicePool(ejbServer, 10);
    ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    ConfigurationFactory config = new ConfigurationFactory();
    EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    EjbJar ejbJar = ejbModule.getEjbJar();
    OpenejbJar openejbJar = ejbModule.getOpenejbJar();
    StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
    deployment.getProperties().put("color", "orange");
    deployment.getProperties().put("openejb.client.color", "red");
    EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
    EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    assertTrue(beanInfo.properties.containsKey("color"));
    assertTrue(beanInfo.properties.containsKey("openejb.client.color"));
    assertEquals("orange", beanInfo.properties.get("color"));
    assertEquals("red", beanInfo.properties.get("openejb.client.color"));
    assembler.createApplication(ejbJarInfo);
    ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
    BeanContext info = cs.getBeanContext("WidgetBean");
    assertNotNull(info);
    assertTrue(info.getProperties().containsKey("color"));
    assertTrue(info.getProperties().containsKey("openejb.client.color"));
    assertEquals("orange", info.getProperties().get("color"));
    assertEquals("red", info.getProperties().get("openejb.client.color"));
    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);
    Context context = new InitialContext(props);
    Widget remote = (Widget) context.lookup("WidgetBeanRemote");
    InvocationHandler handler = ProxyManager.getInvocationHandler(remote);
    EJBObjectHandler objectHandler = EJBObjectHandler.class.cast(handler);
    Properties properties = objectHandler.getEjb().getProperties();
    // Should only contain "openejb.client.*" properties
    assertFalse(properties.containsKey("color"));
    // The openejb.client.color property should have been propogated
    assertTrue(properties.containsKey("openejb.client.color"));
    assertEquals("red", properties.getProperty("openejb.client.color"));
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitialContext(javax.naming.InitialContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) ServerFederation(org.apache.openejb.core.ServerFederation) EJBObjectHandler(org.apache.openejb.client.EJBObjectHandler) ServicePool(org.apache.openejb.server.ServicePool) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InvocationHandler(org.apache.openejb.client.proxy.InvocationHandler) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 90 with ConfigurationFactory

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

the class Server2ServerEjbRefTest method test.

public void test() throws Exception {
    final Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    final ServiceDaemon blue = server();
    final ServiceDaemon orange = server();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final JndiProvider jndiProvider = new JndiProvider("orange");
    final Properties p = jndiProvider.getProperties();
    p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
    p.setProperty(Context.PROVIDER_URL, "ejbd://localhost:" + orange.getPort());
    final JndiContextInfo contextInfo = config.configureService(jndiProvider, JndiContextInfo.class);
    assembler.createExternalContext(contextInfo);
    {
        // Create the "Orange" bean
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(OrangeBean.class));
        assembler.createApplication(config.configureApplication(ejbJar));
        // Lets look it up the normal way to be sure it can work
        final InitialContext initialContext = new InitialContext(jndiProvider.getProperties());
        final OrangeRemote orangeBeanRemote = (OrangeRemote) initialContext.lookup("OrangeBeanRemote");
        assertNotNull(orangeBeanRemote);
    }
    {
        // Create the "Blue" bean
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(BlueBean.class));
        assembler.createApplication(config.configureApplication(ejbJar));
        // Lets look it up the normal way to be sure it can work
        final Properties properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
        properties.setProperty(Context.PROVIDER_URL, "ejbd://localhost:" + blue.getPort());
        final InitialContext initialContext = new InitialContext(properties);
        final BlueRemote blueBeanRemote = (BlueRemote) initialContext.lookup("BlueBeanRemote");
        assertNotNull(blueBeanRemote);
        blueBeanRemote.hasOrangeRemote();
    }
    blue.stop();
    orange.stop();
    OpenEJB.destroy();
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) JndiProvider(org.apache.openejb.config.sys.JndiProvider) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) JndiContextInfo(org.apache.openejb.assembler.classic.JndiContextInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) RemoteInitialContextFactory(org.apache.openejb.client.RemoteInitialContextFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

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