Package org.apache.openejb.server

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


        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

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

        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

        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));
            assertNotSame(reference, remote.echo(reference)); // pass by value
        }

        { // 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));
            assertSame(reference, local.echo(reference)); // pass by reference
        }

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

    private ServiceDaemon createServiceDaemon(int poolSize, EjbServer ejbServer, URI uri) throws ServiceException {
        ServiceIdentifier serviceIdentifier = new ServiceIdentifier(ejbServer, uri);
        KeepAliveServer keepAliveServer = new KeepAliveServer(serviceIdentifier);
        ServicePool pool = new ServicePool(keepAliveServer, poolSize);
        ServiceDaemon daemon = new ServiceDaemon(pool, 0, "localhost");
        daemon.start();
        return daemon;
    }
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(keepAliveServer, 10, 5000, true);
        final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
        serviceDaemon.start();

        try {

            final int port = serviceDaemon.getPort();

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

            final EjbJar ejbJar = new EjbJar();
            ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));

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

            // good creds

            final int threads = 1;
            final CountDownLatch latch = new CountDownLatch(threads);

            final Collection<Thread> th = new ArrayList<>(threads);
            for (int i = 0; i < threads; i++) {
                final Client client = new Client(latch, i, port);
                th.add(thread(client, false));
            }

            final boolean await = latch.await(60, TimeUnit.SECONDS);
            assertTrue(await);

            for (final Thread t : th) {
                t.join(1000);
            }
        } finally {
            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());

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

    private ServiceDaemon createServiceDaemon(final int poolSize, final EjbServer ejbServer, URI uri) throws ServiceException {
        ServiceIdentifier serviceIdentifier = new ServiceIdentifier(ejbServer, uri);
        KeepAliveServer keepAliveServer = new KeepAliveServer(serviceIdentifier);
        ServicePool pool = new ServicePool(keepAliveServer, poolSize);
        final ServiceDaemon daemon = new ServiceDaemon(pool, 0, "localhost");
        daemon.start();
        return daemon;
    }
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.