Search in sources :

Example 6 with ServerFederation

use of org.apache.openejb.core.ServerFederation 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 7 with ServerFederation

use of org.apache.openejb.core.ServerFederation in project tomee by apache.

the class AuthTest method test.

public void test() throws Exception {
    EjbServer ejbServer = new EjbServer();
    Properties initProps = new Properties();
    initProps.put(DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY, Boolean.toString(false));
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    ServiceDaemon serviceDaemon = new ServiceDaemon(ejbServer, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    try {
        // good creds
        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);
        // reusing LoginModule from AuthentWithRequestTest since it is more specific
        props.put("openejb.authentication.realmName", "LM");
        props.put(Context.SECURITY_PRINCIPAL, "foo");
        props.put(Context.SECURITY_CREDENTIALS, "bar");
        new InitialContext(props);
        try {
            props.put(Context.SECURITY_PRINCIPAL, "alfred");
            props.put(Context.SECURITY_CREDENTIALS, "doesnotexist");
            new InitialContext(props);
        } catch (javax.naming.AuthenticationException e) {
        // pass -- user does not exist
        }
    } catch (NamingException e) {
        throw e;
    } finally {
        serviceDaemon.stop();
        OpenEJB.destroy();
    }
}
Also used : ServerFederation(org.apache.openejb.core.ServerFederation) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) EjbServer(org.apache.openejb.server.ejbd.EjbServer) NamingException(javax.naming.NamingException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

Example 8 with ServerFederation

use of org.apache.openejb.core.ServerFederation in project tomee by apache.

the class JndiTest method test.

public void test() throws Exception {
    EjbServer ejbServer = new EjbServer();
    Properties initProps = new Properties();
    initProps.put(DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY, Boolean.toString(false));
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    ServiceDaemon serviceDaemon = new ServiceDaemon(ejbServer, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    ConfigurationFactory config = new ConfigurationFactory();
    EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean("Orange", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Apple", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Peach", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Pear", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Plum", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Orange", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Apple", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Peach", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Pear", Fruit.class));
    ejbJar.addEnterpriseBean(new StatelessBean("ejb/Plum", Fruit.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    try {
        // good creds
        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);
        assertNameClassPair(context.list(""));
        assertNameClassPair(context.list("ejb"));
        assertBindings(context.listBindings(""));
        assertBindings(context.listBindings("ejb"));
    } finally {
        serviceDaemon.stop();
        OpenEJB.destroy();
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ServerFederation(org.apache.openejb.core.ServerFederation) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) EjbServer(org.apache.openejb.server.ejbd.EjbServer) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EjbJar(org.apache.openejb.jee.EjbJar)

Example 9 with ServerFederation

use of org.apache.openejb.core.ServerFederation 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 10 with ServerFederation

use of org.apache.openejb.core.ServerFederation in project tomee by apache.

the class UberInterfaceTest method test.

public void test() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    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(ejbServer, 10);
    final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    final int port = serviceDaemon.getPort();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    assertEquals(asList(Everything.class.getName()), beanInfo.businessLocal);
    assertEquals(asList(Everything.class.getName()), beanInfo.businessRemote);
    assembler.createApplication(ejbJarInfo);
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext deployment = containerSystem.getBeanContext(beanInfo.ejbDeploymentId);
    assertEquals(asList(Everything.class), deployment.getBusinessLocalInterfaces());
    assertEquals(asList(Everything.class), deployment.getBusinessRemoteInterfaces());
    {
        // remote invoke
        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);
        final Everything remote = (Everything) context.lookup("SuperBeanRemote");
        final Reference reference = new Reference("test");
        assertEquals(reference, remote.echo(reference));
        // pass by value
        assertNotSame(reference, remote.echo(reference));
    }
    {
        // local invoke
        final Properties props = new Properties();
        props.put("java.naming.factory.initial", "org.apache.openejb.core.LocalInitialContextFactory");
        final Context context = new InitialContext(props);
        final Everything local = (Everything) context.lookup("SuperBeanLocal");
        final Reference reference = new Reference("test");
        assertEquals(reference, local.echo(reference));
        // pass by reference
        assertSame(reference, local.echo(reference));
    }
    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) ServicePool(org.apache.openejb.server.ServicePool) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) 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) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

ServerFederation (org.apache.openejb.core.ServerFederation)20 Properties (java.util.Properties)18 Assembler (org.apache.openejb.assembler.classic.Assembler)15 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)15 EjbJar (org.apache.openejb.jee.EjbJar)15 StatelessBean (org.apache.openejb.jee.StatelessBean)15 InitialContext (javax.naming.InitialContext)13 ServiceDaemon (org.apache.openejb.server.ServiceDaemon)12 Context (javax.naming.Context)11 ServicePool (org.apache.openejb.server.ServicePool)7 EjbServer (org.apache.openejb.server.ejbd.EjbServer)5 EjbModule (org.apache.openejb.config.EjbModule)4 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)4 EJBException (javax.ejb.EJBException)3 NamingException (javax.naming.NamingException)3 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)3 RemoteInitialContextFactory (org.apache.openejb.client.RemoteInitialContextFactory)3 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)3 ServerService (org.apache.openejb.server.ServerService)3 ServiceException (org.apache.openejb.server.ServiceException)3