Package org.apache.openejb.server

Examples of org.apache.openejb.server.ServiceDaemon$SocketListener


        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();
    }
View Full Code Here


    private ServiceDaemon server() throws Exception {
        final EjbServer ejbServer = new EjbServer();
        ejbServer.init(new Properties());

        final ServicePool pool = new ServicePool(ejbServer, 10, 5000, true);
        final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
        serviceDaemon.start();

        return serviceDaemon;
    }
View Full Code Here

        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();

        int port = serviceDaemon.getPort();

        final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
        final ConfigurationFactory config = new ConfigurationFactory();

        final EjbModule ejbModule = new EjbModule(new EjbJar("testejbmodule"), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(Orange.class));

        final ClassLoader loader = this.getClass().getClassLoader();

        final ClientModule clientModule = new ClientModule(new ApplicationClient(), loader, "orange-client", OrangeAppClient.class.getName(), "orange-client");

        final AppModule appModule = new AppModule(loader, "testapp");

        appModule.getClientModules().add(clientModule);
        appModule.getEjbModules().add(ejbModule);

        assembler.createApplication(config.configureApplication(appModule));

        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);
        props.put("openejb.client.moduleId", "orange-client");

        Context context = new InitialContext(props);

        final Object home = context.lookup("comp/env/home");
        assertTrue(home instanceof OrangeHome);

        OrangeHome orangeHome = (OrangeHome) home;
        final OrangeRemote orangeRemote = orangeHome.create();
        assertEquals("bat", orangeRemote.echo("tab"));

        final Object business = context.lookup("comp/env/business");
        assertTrue(business instanceof OrangeBusinessRemote);
        OrangeBusinessRemote orangeBusinessRemote = (OrangeBusinessRemote) business;
        assertEquals("nap", orangeBusinessRemote.echo("pan"));

        final Object dataSourceObject = context.lookup("comp/env/datasource");
        assertTrue(dataSourceObject instanceof DataSource);
        //        DataSource dataSource = (DataSource) dataSourceObject;
        //        assertEquals("nap", orangeBusinessRemote.echo("pan"));

        props.put("openejb.client.moduleId", "openejb/global");
        context = new InitialContext(props);

        final Object global = context.lookup("global/testapp/testejbmodule/Orange!" + OrangeBusinessRemote.class.getName());
        assertTrue(global instanceof OrangeBusinessRemote);
        OrangeBusinessRemote globalOrangeBusinessRemote = (OrangeBusinessRemote) global;
        assertEquals("nap", globalOrangeBusinessRemote.echo("pan"));

        serviceDaemon.stop();
        OpenEJB.destroy();
    }
View Full Code Here

        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("openejb.client.connection.strategy", "test");

        assembler.createApplication(config.configureApplication(ejbModule));

        Properties props = new Properties();
        props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
        props.put("java.naming.provider.url", "failover:sticky:ejbd://agwdt:9999,ejbd://127.0.0.1:" + port);
        Context context = new InitialContext(props);

        Widget remote = (Widget) context.lookup("WidgetBeanRemote");

        assertFalse(TestConnectionStrategy.called.get());

        remote.echo("foo");

        assertTrue(TestConnectionStrategy.called.get());

        serviceDaemon.stop();
        OpenEJB.destroy();
    }
View Full Code Here

        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("openejb.client.connection.strategy", "test");

        assembler.createApplication(config.configureApplication(ejbModule));

        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");

        assertFalse(TestConnectionStrategy.called.get());

        remote.echo("foo");

        assertTrue(TestConnectionStrategy.called.get());

        serviceDaemon.stop();
        OpenEJB.destroy();
    }
View Full Code Here

    private ServerService server(final Host host) throws Exception {
        ServerService server = new EjbServer();

        server = new HostFilter(server, host);

        server = new ServiceDaemon(server, 0, "localhost");

        server = new AgentFilter(server, agent, host);

        server.init(new Properties());
View Full Code Here

               
                httpServer.init(props);

                // Binding to port 0 means that the OS will
                // randomly pick an *available* port and bind to it
                serviceDaemon = new ServiceDaemon(httpServer, 0, "localhost");

            } catch (Exception e) {
                throw new RuntimeException("Unable to initialize Test Server.", e);
            }
        }
View Full Code Here

        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);
            props.put("openejb.authentication.realmName", "LM"); // reusing LoginModule from AuthentWithRequestTest since it is more specific
            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();
        }

    }
View Full Code Here

                props.put("openejb.deployments.classpath.filter.systemapps", "false");
                //                props.put("openejb.debuggable-vm-hackery", "true");
                OpenEJB.init(props, new ServerFederation());
                ejbServer.init(props);

                serviceDaemon = new ServiceDaemon(ejbServer, 0, "localhost");

            } catch (Exception e) {
                throw new RuntimeException("Unable to initialize Test Server.", e);
            }
        }
View Full Code Here

        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();
        }

    }
View Full Code Here

TOP

Related Classes of org.apache.openejb.server.ServiceDaemon$SocketListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.